Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Andrey Lushnikov2d68830411ea
diff --git a/test/test.js b/test/test.js
index 2b40ee55f4..b115d9834e 100644
--- a/test/test.js
+++ b/test/test.js
@@ -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');
@@ -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; });
}
diff --git a/utils/testrunner/index.js b/utils/testrunner/index.js
index fec946e103..6f16752a83 100644
--- a/utils/testrunner/index.js
+++ b/utils/testrunner/index.js
@@ -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) {