diff --git a/scripts/test/run_test_suite.js b/scripts/test/run_test_suite.js index 04caaa33d5..d9c5c91dd3 100644 --- a/scripts/test/run_test_suite.js +++ b/scripts/test/run_test_suite.js @@ -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);