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:
Moh'd Khier Abualruz 2023-11-07 17:47:28 +01:00 committed by Jdlrobson
parent 72ec5037cf
commit 9f35fd8d56
2 changed files with 42 additions and 22 deletions

View file

@ -1,12 +1,12 @@
{
"total": {
"vector-2022": {
"scripts": "70.1KB",
"styles": "17.0KB"
"scripts": "80KB",
"styles": "17KB"
},
"vector": {
"scripts": "70.1KB",
"styles": "17.0KB"
"scripts": "80KB",
"styles": "17KB"
}
},
"modules": [

View file

@ -148,38 +148,58 @@ class PerformanceBudgetTest extends MediaWikiIntegrationTestCase {
* @throws MediaWiki\Config\ConfigException
*/
public function testTotalModulesSize( $skinName, $maxSizes ) {
$this->markTestSkipped( 'test unstable: T350338' );
$skin = $this->prepareSkin( $skinName );
$moduleStyles = $skin->getOutput()->getModuleStyles();
$size = 0;
foreach ( $moduleStyles as $moduleName ) {
$size += $this->getContentTransferSize( $moduleName, $skinName );
}
$debugInformation = "The following modules are enabled on page load:\n" .
implode( "\n", $moduleStyles );
$stylesMaxSize = $this->getSizeInBytes( $maxSizes[ 'styles' ] );
$message = "T346813: Performance budget for style in skin" .
" $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";
$message = $this->createMessage( $skinName, $size, $stylesMaxSize, $moduleStyles );
$this->assertLessThanOrEqual( $stylesMaxSize, $size, $message );
$modulesScripts = $skin->getOutput()->getModules();
$size = 0;
foreach ( $modulesScripts as $moduleName ) {
$size += $this->getContentTransferSize( $moduleName, $skinName );
}
$debugInformation = "The following modules are enabled on page load:\n" .
implode( "\n", $modulesScripts );
$scriptsMaxSize = $this->getSizeInBytes( $maxSizes[ 'scripts' ] );
$message = "T346813: Performance budget for scripts in skin" .
" $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";
$message = $this->createMessage( $skinName, $size, $scriptsMaxSize, $modulesScripts, true );
$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;
}
}