mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
test: reverse dumpio into quiet, serialize output (#3491)
This commit is contained in:
parent
73d2dc11d7
commit
c44f841f33
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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 };
|
||||
|
@ -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() {
|
||||
|
@ -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 => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user