Add mocha-fgrep flag to run_test_suite.js

This CL adds the ability to filter the tests via Mocha's `fgrep` flag,
giving us the ability to run a subset of the tests if we wish in the
future.

Fixed: 1249000
Change-Id: I3379f6f0f60fc97d8af6b019761cfb31dda8afd2
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3162297
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
This commit is contained in:
Jack Franklin
2021-09-15 11:53:07 +00:00
committed by Devtools-frontend LUCI CQ
parent 1b71653ece
commit 348a89db15
+19 -2
View File
@@ -47,6 +47,11 @@ const yargsObject =
type: 'string',
desc: 'A comma separated glob (or just a file path) to select specific test files to execute.'
})
.option('mocha-fgrep', {
type: 'string',
desc:
'Mocha\'s fgrep option [https://mochajs.org/#-fgrep-string-f-string] which only runs teses whose titles contain the provided string',
})
// test-file-pattern can be provided as a flag or as a positional
// argument. $0 here is Yarg's syntax for the default command:
// https://github.com/yargs/yargs/blob/master/docs/advanced.md#default-commands
@@ -165,7 +170,8 @@ function executeTestSuite({
chromeFeatures,
testFilePattern,
coverage,
cwd
cwd,
mochaOptions = {},
}) {
/**
* Internally within various scripts (Mocha configs, Conductor, etc), we rely on
@@ -196,6 +202,14 @@ function executeTestSuite({
const testSuiteConfig = path.join(absoluteTestSuitePath, '.mocharc.js');
validatePathExistsOrError('.mocharc.js location', testSuiteConfig);
argumentsForNode.push('--config', testSuiteConfig);
if (Object.keys(mochaOptions).length > 0) {
log('Running Mocha with extra flags:');
}
for (const [mochaKey, mochaValue] of Object.entries(mochaOptions)) {
argumentsForNode.push(`--${mochaKey}`, mochaValue);
log(` --${mochaKey}=${mochaValue}`);
}
const result = childProcess.spawnSync(nodePath(), argumentsForNode, {encoding: 'utf-8', stdio: 'inherit', cwd});
return result.status;
}
@@ -270,7 +284,10 @@ function main() {
testFilePattern: configurationFlags['test-file-pattern'],
coverage: configurationFlags['coverage'] && '1',
target,
cwd: configurationFlags['cwd']
cwd: configurationFlags['cwd'],
mochaOptions: {
fgrep: configurationFlags['mocha-fgrep'],
}
});
} catch (error) {
log('Unexpected error when running test suite', error);