chore: add memory debugging to mocha runner (#11722)

This commit is contained in:
Alex Rudenko 2024-01-23 14:26:57 +01:00 committed by GitHub
parent d17a9df027
commit afa3fd4c34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View File

@ -169,6 +169,21 @@ export const setupTestBrowserHooks = (): void => {
// if browser is not found // if browser is not found
} }
}); });
after(() => {
if (typeof gc !== 'undefined') {
gc();
const memory = process.memoryUsage();
console.log('Memory stats:');
for (const key of Object.keys(memory)) {
console.log(
key,
// @ts-expect-error TS cannot the key type.
`${Math.round(((memory[key] / 1024 / 1024) * 100) / 100)} MB`
);
}
}
});
}; };
export const getTestState = async ( export const getTestState = async (

View File

@ -46,6 +46,7 @@ const {
minTests, minTests,
shard, shard,
reporter, reporter,
printMemory,
} = yargs(hideBin(process.argv)) } = yargs(hideBin(process.argv))
.parserConfiguration({'unknown-options-as-args': true}) .parserConfiguration({'unknown-options-as-args': true})
.scriptName('@puppeteer/mocha-runner') .scriptName('@puppeteer/mocha-runner')
@ -82,6 +83,10 @@ const {
string: true, string: true,
requiresArg: true, requiresArg: true,
}) })
.option('print-memory', {
boolean: true,
default: false,
})
.parseSync(); .parseSync();
function getApplicableTestSuites( function getApplicableTestSuites(
@ -197,6 +202,10 @@ async function main() {
'trace-warnings', 'trace-warnings',
]; ];
if (printMemory) {
args.push('-n', 'expose-gc');
}
const specPattern = 'test/build/**/*.spec.js'; const specPattern = 'test/build/**/*.spec.js';
const specs = globSync(specPattern, { const specs = globSync(specPattern, {
ignore: !includeCdpTests ? 'test/build/cdp/**/*.spec.js' : undefined, ignore: !includeCdpTests ? 'test/build/cdp/**/*.spec.js' : undefined,