Skip to content

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

test: reverse dumpio into quiet, serialize output (#3491)

Pavel Feldmanc44f841f330e
diff --git a/test/runner/fixtures.js b/test/runner/fixtures.js
index 3c787e5657..89deeff705 100644
--- a/test/runner/fixtures.js
+++ b/test/runner/fixtures.js
@@ -109,15 +109,6 @@ class FixturePool {
return fn(params);
}
- patchToEnableFixtures(object, name) {
- const original = object[name];
- object[name] = fn => {
- return original(async () => {
- return await this.resolveParametersAndRun(fn);
- });
- }
- }
-
wrapTestCallback(callback) {
if (!callback)
return callback;
diff --git a/test/runner/fixturesUI.js b/test/runner/fixturesUI.js
index d997f8adef..0f8d55a876 100644
--- a/test/runner/fixturesUI.js
+++ b/test/runner/fixturesUI.js
@@ -58,7 +58,7 @@ function specBuilder(modifiers, specCallback) {
return builder({}, null);
}
-function fixturesUI(trialRun, suite) {
+function fixturesUI(testRunner, suite) {
const suites = [suite];
suite.on(Suite.constants.EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) {
@@ -69,7 +69,7 @@ function fixturesUI(trialRun, suite) {
if (suite.isPending())
fn = null;
let wrapper;
- if (trialRun) {
+ if (testRunner.trialRun) {
if (fn)
wrapper = () => {};
} else {
@@ -113,17 +113,20 @@ function fixturesUI(trialRun, suite) {
return suite;
});
- context.beforeEach = common.beforeEach;
- context.afterEach = common.afterEach;
- if (trialRun) {
- context.beforeEach = () => {};
- context.afterEach = () => {};
- } else {
- context.beforeEach = common.beforeEach;
- context.afterEach = common.afterEach;
- fixturePool.patchToEnableFixtures(context, 'beforeEach');
- fixturePool.patchToEnableFixtures(context, 'afterEach');
- }
+ context.beforeEach = (fn) => {
+ if (testRunner.trialRun)
+ return;
+ return common.beforeEach(async () => {
+ return await fixturePool.resolveParametersAndRun(fn);
+ });
+ };
+ context.afterEach = (fn) => {
+ if (testRunner.trialRun)
+ return;
+ return common.afterEach(async () => {
+ return await fixturePool.resolveParametersAndRun(fn);
+ });
+ };
context.run = mocha.options.delay && common.runWithSuite(suite);
diff --git a/test/runner/index.js b/test/runner/index.js
index 6e080590bc..91f2b38d14 100644
--- a/test/runner/index.js
+++ b/test/runner/index.js
@@ -29,7 +29,7 @@ program
.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('--dumpio', 'Dump stdout and stderr from workers', false)
+ .option('--quiet', 'Suppress stdio', false)
.option('--debug', 'Run tests in-process for debugging', false)
.option('--timeout <timeout>', 'Specify test timeout threshold (in milliseconds), default: 10000', 10000)
.action(async (command) => {
@@ -70,7 +70,7 @@ program
const jobs = (command.trialRun || command.debug) ? 1 : command.jobs;
const runner = new Runner(rootSuite, {
debug: command.debug,
- dumpio: command.dumpio,
+ quiet: command.quiet,
grep: command.grep,
jobs,
reporter: command.reporter,
diff --git a/test/runner/runner.js b/test/runner/runner.js
index 2cfcf6a319..76aec8f8fb 100644
--- a/test/runner/runner.js
+++ b/test/runner/runner.js
@@ -197,17 +197,17 @@ class OopWorker extends EventEmitter {
});
this.stdout = [];
this.stderr = [];
- this.on('stdout', data => {
- if (runner._options.dumpio)
- process.stdout.write(data);
- else
- this.stdout.push(data);
+ this.on('stdout', params => {
+ const chunk = chunkFromParams(params);
+ if (!runner._options.quiet)
+ process.stdout.write(chunk);
+ this.stdout.push(chunk);
});
- this.on('stderr', data => {
- if (runner._options.dumpio)
- process.stderr.write(data);
- else
- this.stderr.push(data);
+ this.on('stderr', params => {
+ const chunk = chunkFromParams(params);
+ if (!runner._options.quiet)
+ process.stderr.write(chunk);
+ this.stderr.push(chunk);
});
this.on('debug', data => {
process.stderr.write(data + '\n');
@@ -273,4 +273,10 @@ class InProcessWorker extends EventEmitter {
}
}
+function chunkFromParams(params) {
+ if (typeof params === 'string')
+ return params;
+ return Buffer.from(params.buffer, 'base64');
+}
+
module.exports = { Runner };
diff --git a/test/runner/testRunner.js b/test/runner/testRunner.js
index 80ebcc6b4d..80725b298f 100644
--- a/test/runner/testRunner.js
+++ b/test/runner/testRunner.js
@@ -39,7 +39,7 @@ class TestRunner extends EventEmitter {
forbidOnly: options.forbidOnly,
reporter: NullReporter,
timeout: options.timeout,
- ui: fixturesUI.bind(null, options.trialRun),
+ ui: fixturesUI.bind(null, this),
});
if (options.grep)
this.mocha.grep(options.grep);
@@ -49,6 +49,7 @@ class TestRunner extends EventEmitter {
this.suite = this.mocha.suite;
this._lastOrdinal = -1;
this._failedWithError = false;
+ this.trialRun = options.trialRun;
}
async run() {
diff --git a/test/runner/worker.js b/test/runner/worker.js
index 6081bcdf14..9c1ae81b43 100644
--- a/test/runner/worker.js
+++ b/test/runner/worker.js
@@ -18,17 +18,26 @@ const debug = require('debug');
const { fixturePool } = require('./fixturesUI');
const { gracefullyCloseAll } = require('../../lib/server/processLauncher');
const { TestRunner } = require('./testRunner');
+const util = require('util');
let closed = false;
sendMessageToParent('ready');
+function chunkToParams(chunk) {
+ if (chunk instanceof Buffer)
+ return { buffer: chunk.toString('base64') };
+ if (typeof chunk !== 'string')
+ return util.inspect(chunk);
+ return chunk;
+}
+
process.stdout.write = chunk => {
- sendMessageToParent('stdout', chunk);
+ sendMessageToParent('stdout', chunkToParams(chunk));
};
process.stderr.write = chunk => {
- sendMessageToParent('stderr', chunk);
+ sendMessageToParent('stderr', chunkToParams(chunk));
};
debug.log = data => {