[testing] Pass tests files to mocha as dashed args

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 <szuend@chromium.org>
Auto-Submit: Philip Pfaffe <pfaffe@chromium.org>
Reviewed-by: Simon Zünd <szuend@chromium.org>
This commit is contained in:
Philip Pfaffe
2024-06-04 06:59:48 +00:00
committed by Devtools-frontend LUCI CQ
parent 031e7c8dc7
commit cf71126b1c
2 changed files with 25 additions and 8 deletions
+13 -1
View File
@@ -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,
+12 -7
View File
@@ -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.
);
}
}