feat(testrunner): support --file to filter tests by test file name. (#1903)

This commit is contained in:
Andrey Lushnikov 2020-04-21 16:47:38 -07:00 committed by GitHub
parent 89b2fe5f38
commit 2d68830411
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 15 deletions

View File

@ -190,19 +190,6 @@ function collect(browserNames) {
delete global[key]; delete global[key];
} }
const filterArgIndex = process.argv.indexOf('--filter');
if (filterArgIndex !== -1) {
const filter = process.argv[filterArgIndex + 1];
testRunner.focusMatchingTests(new RegExp(filter, 'i'));
}
const repeatArgIndex = process.argv.indexOf('--repeat');
if (repeatArgIndex !== -1) {
const repeat = parseInt(process.argv[repeatArgIndex + 1], 10);
if (!isNaN(repeat))
testRunner.repeatAll(repeat);
}
return testRunner; return testRunner;
} }
@ -214,5 +201,31 @@ if (require.main === module) {
return process.env.BROWSER === name || process.env.BROWSER === 'all'; return process.env.BROWSER === name || process.env.BROWSER === 'all';
}); });
const testRunner = collect(browserNames); const testRunner = collect(browserNames);
const filterArgIndex = process.argv.indexOf('--filter');
if (filterArgIndex !== -1) {
const filter = process.argv[filterArgIndex + 1];
if (!testRunner.focusMatchingNameTests(new RegExp(filter, 'i')).length) {
console.log('ERROR: no tests matched given `--filter` regex.');
process.exit(1);
}
}
const fileArgIndex = process.argv.indexOf('--file');
if (fileArgIndex !== -1) {
const filter = process.argv[fileArgIndex + 1];
if (!testRunner.focusMatchingFilePath(new RegExp(filter, 'i')).length) {
console.log('ERROR: no files matched given `--file` regex.');
process.exit(1);
}
}
const repeatArgIndex = process.argv.indexOf('--repeat');
if (repeatArgIndex !== -1) {
const repeat = parseInt(process.argv[repeatArgIndex + 1], 10);
if (!isNaN(repeat))
testRunner.repeatAll(repeat);
}
testRunner.run().then(() => { delete global.expect; }); testRunner.run().then(() => { delete global.expect; });
} }

View File

@ -82,11 +82,26 @@ class DefaultTestRunner {
return this._api; return this._api;
} }
focusMatchingTests(fullNameRegex) { focusMatchingNameTests(fullNameRegex) {
const focusedTests = [];
for (const test of this._collector.tests()) { for (const test of this._collector.tests()) {
if (fullNameRegex.test(test.fullName())) if (fullNameRegex.test(test.fullName())) {
this._filter.markFocused(test); this._filter.markFocused(test);
focusedTests.push(test);
}
} }
return focusedTests;
}
focusMatchingFilePath(filepathRegex) {
const focusedTests = [];
for (const test of this._collector.tests()) {
if (filepathRegex.test(test.location().filePath())) {
this._filter.markFocused(test);
focusedTests.push(test);
}
}
return focusedTests;
} }
repeatAll(repeatCount) { repeatAll(repeatCount) {