From cf71126b1c6e47bfa52df318eb9047ffd2cbb9e2 Mon Sep 17 00:00:00 2001 From: Philip Pfaffe Date: Mon, 3 Jun 2024 10:19:17 +0000 Subject: [PATCH] [testing] Pass tests files to mocha as dashed args MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids mocha accidentally picking up the test files itself. Bug: 333423685 Change-Id: I5c15c619f07c913a5ababb8b7b9dd24ed195eb09 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5591052 Commit-Queue: Simon Zünd Auto-Submit: Philip Pfaffe Reviewed-by: Simon Zünd --- test/conductor/test_config.ts | 14 +++++++++++++- test/run.ts | 19 ++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/test/conductor/test_config.ts b/test/conductor/test_config.ts index cdbe30e6f7..58c92ce1ff 100644 --- a/test/conductor/test_config.ts +++ b/test/conductor/test_config.ts @@ -62,8 +62,20 @@ function mochaGrep(): Config['mochaGrep'] { return grep; } +function getTestsFromOptions() { + const tests = options['tests']; + if (Array.isArray(tests)) { + return tests; + } + + if (typeof tests === 'string') { + return [tests]; + } + return []; +} + export const TestConfig: Config = { - tests: options['tests'], + tests: getTestsFromOptions(), artifactsDir: options['artifacts-dir'] || SOURCE_ROOT, chromeBinary: options['chrome-binary'] ?? defaultChromePath(), serverType: ServerType.HostedMode, diff --git a/test/run.ts b/test/run.ts index 441ba3396d..23117d5b74 100644 --- a/test/run.ts +++ b/test/run.ts @@ -92,11 +92,11 @@ class Tests { pathToCheck => isContainedInDirectory(path.buildPath, pathToCheck.buildPath)); } - protected run(tests: PathPair[], args: string[]) { + protected run(tests: PathPair[], args: string[], positionalTestArgs = true) { const argumentsForNode = [ ...args, '--', - ...tests.map(t => t.buildPath), + ...tests.map(t => positionalTestArgs ? t.buildPath : `--tests=${t.buildPath}`), ...forwardOptions(), ]; if (options['debug-driver']) { @@ -112,11 +112,16 @@ class Tests { class MochaTests extends Tests { override run(tests: PathPair[]) { - return super.run(tests, [ - path.join(SOURCE_ROOT, 'node_modules', 'mocha', 'bin', 'mocha'), - '--config', - path.join(this.suite.buildPath, 'mocharc.js'), - ]); + return super.run( + tests, + [ + path.join(SOURCE_ROOT, 'node_modules', 'mocha', 'bin', 'mocha'), + '--config', + path.join(this.suite.buildPath, 'mocharc.js'), + ], + /* positionalTestArgs= */ false, // Mocha interprets positional arguments as test files itself. Work around + // that by passing the tests as dashed args instead. + ); } }