Skip to content

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

test: introduce --trial-run mode to capture test model (#3436)

Pavel Feldman5498ed10a863
diff --git a/test/runner/index.js b/test/runner/index.js
index 527947c155..fcf7dbe946 100644
--- a/test/runner/index.js
+++ b/test/runner/index.js
@@ -31,13 +31,17 @@ program
.option('-g, --grep <grep>', 'Only run tests matching this string or regexp', '.*')
.option('-j, --jobs <jobs>', 'Number of concurrent jobs for --parallel; use 1 to run in serial, default: (number of CPU cores / 2)', Math.ceil(require('os').cpus().length / 2))
.option('--reporter <reporter>', 'Specify reporter to use', '')
+ .option('--trial-run', 'Only collect the matching tests and report them as passing')
.option('--timeout <timeout>', 'Specify test timeout threshold (in milliseconds), default: 10000', 10000)
.action(async (command) => {
// Collect files
const files = collectFiles(path.join(process.cwd(), command.args[0]), command.args.slice(1));
const rootSuite = new Mocha.Suite('', new Mocha.Context(), true);
- console.log(`Parsing ${files.length} test files`);
+ if (!command.reporter) {
+ // TODO: extend reporter interface.
+ console.log(`Parsing ${files.length} test files`);
+ }
let total = 0;
// Build the test model, suite per file.
for (const file of files) {
@@ -54,9 +58,11 @@ program
let runner;
await new Promise(f => {
runner = mocha.run(f);
- runner.on(constants.EVENT_RUN_BEGIN, () => {
- process.stdout.write(colors.yellow('\u00B7'));
- });
+ if (!command.reporter) {
+ runner.on(constants.EVENT_RUN_BEGIN, () => {
+ process.stdout.write(colors.yellow('\u00B7'));
+ });
+ }
});
total += runner.grepTotal(mocha.suite);
@@ -64,18 +70,23 @@ program
mocha.suite.title = path.basename(file);
}
+ // Now run the tests.
if (rootSuite.hasOnly())
rootSuite.filterOnly();
- console.log();
- total = Math.min(total, rootSuite.total()); // First accounts for grep, second for only.
- console.log(`Running ${total} tests using ${Math.min(command.jobs, total)} workers`);
+ if (!command.reporter) {
+ console.log();
+ total = Math.min(total, rootSuite.total()); // First accounts for grep, second for only.
+ console.log(`Running ${total} tests using ${Math.min(command.jobs, total)} workers`);
+ }
- const runner = new Runner(rootSuite, {
+ // Trial run does not need many workers, use one.
+ const jobs = command.trialRun ? 1 : command.jobs;
+ const runner = new Runner(rootSuite, jobs, {
grep: command.grep,
- jobs: command.jobs,
reporter: command.reporter,
retries: command.retries,
timeout: command.timeout,
+ trialRun: command.trialRun,
});
await runner.run(files);
await runner.stop();
diff --git a/test/runner/runner.js b/test/runner/runner.js
index dfde544d5a..7145dc7d18 100644
--- a/test/runner/runner.js
+++ b/test/runner/runner.js
@@ -26,11 +26,11 @@ const constants = Mocha.Runner.constants;
process.setMaxListeners(0);
class Runner extends EventEmitter {
- constructor(suite, options) {
+ constructor(suite, jobs, options) {
super();
this._suite = suite;
+ this._jobs = jobs;
this._options = options;
- this._jobs = options.jobs;
this._workers = new Set();
this._freeWorkers = [];
this._workerClaimers = [];
diff --git a/test/runner/worker.js b/test/runner/worker.js
index aa1efad9e5..eda692f2ca 100644
--- a/test/runner/worker.js
+++ b/test/runner/worker.js
@@ -64,7 +64,7 @@ let failedWithError = false;
async function runSingleTest(file, options) {
let lastOrdinal = -1;
const mocha = new Mocha({
- ui: fixturesUI.bind(null, false),
+ ui: fixturesUI.bind(null, options.trialRun),
timeout: options.timeout,
reporter: NullReporter
});