mirror of
https://github.com/microsoft/playwright.git
synced 2024-10-28 06:07:53 +03:00
feat(testrunner): support --file
to filter tests by test file name. (#1903)
This commit is contained in:
parent
89b2fe5f38
commit
2d68830411
39
test/test.js
39
test/test.js
@ -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; });
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user