mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-13 17:57:06 +00:00
Vector PerformanceBudgetTest::testTotalModulesSize CI break
- Account for 10 Kbs in the case wikibase is enabled for scripts budget - Message generation centralised function - Added bundlesize.config.json file path to message. - Update the message to show in Kbs Bug: T350338 Change-Id: I8490cd7aa4468b54bab05960c8c594093167cb72
This commit is contained in:
parent
72ec5037cf
commit
9f35fd8d56
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"total": {
|
"total": {
|
||||||
"vector-2022": {
|
"vector-2022": {
|
||||||
"scripts": "70.1KB",
|
"scripts": "80KB",
|
||||||
"styles": "17.0KB"
|
"styles": "17KB"
|
||||||
},
|
},
|
||||||
"vector": {
|
"vector": {
|
||||||
"scripts": "70.1KB",
|
"scripts": "80KB",
|
||||||
"styles": "17.0KB"
|
"styles": "17KB"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"modules": [
|
"modules": [
|
||||||
|
|
|
@ -148,38 +148,58 @@ class PerformanceBudgetTest extends MediaWikiIntegrationTestCase {
|
||||||
* @throws MediaWiki\Config\ConfigException
|
* @throws MediaWiki\Config\ConfigException
|
||||||
*/
|
*/
|
||||||
public function testTotalModulesSize( $skinName, $maxSizes ) {
|
public function testTotalModulesSize( $skinName, $maxSizes ) {
|
||||||
$this->markTestSkipped( 'test unstable: T350338' );
|
|
||||||
|
|
||||||
$skin = $this->prepareSkin( $skinName );
|
$skin = $this->prepareSkin( $skinName );
|
||||||
$moduleStyles = $skin->getOutput()->getModuleStyles();
|
$moduleStyles = $skin->getOutput()->getModuleStyles();
|
||||||
$size = 0;
|
$size = 0;
|
||||||
foreach ( $moduleStyles as $moduleName ) {
|
foreach ( $moduleStyles as $moduleName ) {
|
||||||
$size += $this->getContentTransferSize( $moduleName, $skinName );
|
$size += $this->getContentTransferSize( $moduleName, $skinName );
|
||||||
}
|
}
|
||||||
$debugInformation = "The following modules are enabled on page load:\n" .
|
|
||||||
implode( "\n", $moduleStyles );
|
|
||||||
$stylesMaxSize = $this->getSizeInBytes( $maxSizes[ 'styles' ] );
|
$stylesMaxSize = $this->getSizeInBytes( $maxSizes[ 'styles' ] );
|
||||||
$message = "T346813: Performance budget for style in skin" .
|
$message = $this->createMessage( $skinName, $size, $stylesMaxSize, $moduleStyles );
|
||||||
" $skinName on main article namespace has been exceeded." .
|
|
||||||
" Total size of style modules is $size bytes is greater" .
|
|
||||||
" than the current budget size of $stylesMaxSize bytes" .
|
|
||||||
" Please reduce styles that you are loading on page load" .
|
|
||||||
" or talk to the skin maintainer about modifying the budget. $debugInformation";
|
|
||||||
$this->assertLessThanOrEqual( $stylesMaxSize, $size, $message );
|
$this->assertLessThanOrEqual( $stylesMaxSize, $size, $message );
|
||||||
$modulesScripts = $skin->getOutput()->getModules();
|
$modulesScripts = $skin->getOutput()->getModules();
|
||||||
$size = 0;
|
$size = 0;
|
||||||
foreach ( $modulesScripts as $moduleName ) {
|
foreach ( $modulesScripts as $moduleName ) {
|
||||||
$size += $this->getContentTransferSize( $moduleName, $skinName );
|
$size += $this->getContentTransferSize( $moduleName, $skinName );
|
||||||
}
|
}
|
||||||
$debugInformation = "The following modules are enabled on page load:\n" .
|
|
||||||
implode( "\n", $modulesScripts );
|
|
||||||
$scriptsMaxSize = $this->getSizeInBytes( $maxSizes[ 'scripts' ] );
|
$scriptsMaxSize = $this->getSizeInBytes( $maxSizes[ 'scripts' ] );
|
||||||
$message = "T346813: Performance budget for scripts in skin" .
|
$message = $this->createMessage( $skinName, $size, $scriptsMaxSize, $modulesScripts, true );
|
||||||
" $skinName on main article namespace has been exceeded." .
|
|
||||||
" Total size of script modules is $size bytes is greater" .
|
|
||||||
" than the current budget size of $scriptsMaxSize bytes" .
|
|
||||||
" Please reduce scripts that you are loading on page load" .
|
|
||||||
" or talk to the skin maintainer about modifying the budget. $debugInformation";
|
|
||||||
$this->assertLessThanOrEqual( $scriptsMaxSize, $size, $message );
|
$this->assertLessThanOrEqual( $scriptsMaxSize, $size, $message );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a message for the assertion
|
||||||
|
*
|
||||||
|
* @param string $skinName
|
||||||
|
* @param int|float $size
|
||||||
|
* @param int|float $maxSize
|
||||||
|
* @param array $modules
|
||||||
|
* @param bool $scripts
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function createMessage( $skinName, $size, $maxSize, $modules, $scripts = false ) {
|
||||||
|
$debugInformation = "The following modules are enabled on page load:\n" .
|
||||||
|
implode( "\n", $modules );
|
||||||
|
$moduleType = $scripts ? 'scripts' : 'styles';
|
||||||
|
return "T346813: Performance budget for $moduleType in skin" .
|
||||||
|
" $skinName on main article namespace has been exceeded." .
|
||||||
|
" Total size of $moduleType modules is " . $this->bytesToKbsRoundup( $size ) . " Kbs is greater" .
|
||||||
|
" than the current budget size of " . $this->bytesToKbsRoundup( $maxSize ) . " Kbs" .
|
||||||
|
" (see Vector/bundlesize.config.json).\n" .
|
||||||
|
"Please reduce $moduleType that you are loading on page load" .
|
||||||
|
" or talk to the skin maintainer about modifying the budget.\n" .
|
||||||
|
"$debugInformation";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts bytes to Kbs and rounds up to the nearest 0.1
|
||||||
|
*
|
||||||
|
* @param int|float $sizeInBytes
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
private function bytesToKbsRoundup( $sizeInBytes ) {
|
||||||
|
return ceil( ( $sizeInBytes * 10 ) / 1024 ) / 10;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue