Skip to content

Commit

Permalink
feat(testrunner): support --file to filter tests by test file name. (
Browse files Browse the repository at this point in the history
  • Loading branch information
aslushnikov committed Apr 21, 2020
1 parent 89b2fe5 commit 2d68830
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
37 changes: 25 additions & 12 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,34 @@ function collect(browserNames) {
delete global[key];
}

return testRunner;
}

module.exports = collect;

if (require.main === module) {
console.log('Testing on Node', process.version);
const browserNames = ['chromium', 'firefox', 'webkit'].filter(name => {
return process.env.BROWSER === name || process.env.BROWSER === 'all';
});
const testRunner = collect(browserNames);

const filterArgIndex = process.argv.indexOf('--filter');
if (filterArgIndex !== -1) {
const filter = process.argv[filterArgIndex + 1];
testRunner.focusMatchingTests(new RegExp(filter, 'i'));
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');
Expand All @@ -203,16 +227,5 @@ function collect(browserNames) {
testRunner.repeatAll(repeat);
}

return testRunner;
}

module.exports = collect;

if (require.main === module) {
console.log('Testing on Node', process.version);
const browserNames = ['chromium', 'firefox', 'webkit'].filter(name => {
return process.env.BROWSER === name || process.env.BROWSER === 'all';
});
const testRunner = collect(browserNames);
testRunner.run().then(() => { delete global.expect; });
}
19 changes: 17 additions & 2 deletions utils/testrunner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,26 @@ class DefaultTestRunner {
return this._api;
}

focusMatchingTests(fullNameRegex) {
focusMatchingNameTests(fullNameRegex) {
const focusedTests = [];
for (const test of this._collector.tests()) {
if (fullNameRegex.test(test.fullName()))
if (fullNameRegex.test(test.fullName())) {
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) {
Expand Down

0 comments on commit 2d68830

Please sign in to comment.