mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(test): enable dumpio in tests #2610
This patch allows logging the output of the Chromium process to be enabled in tests by passing in the environment variable `DUMPIO=true`. Additionally, the `stderr` of the Chromium process will always be logged in the the "Output" section of failing page tests.
This commit is contained in:
parent
8e12d197a2
commit
1bbd094624
@ -206,7 +206,7 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBro
|
||||
const dumpioTextToLog = 'MAGIC_DUMPIO_TEST';
|
||||
let dumpioData = '';
|
||||
const {spawn} = require('child_process');
|
||||
const options = Object.assign({dumpio: true}, defaultBrowserOptions);
|
||||
const options = Object.assign({}, defaultBrowserOptions, {dumpio: true});
|
||||
const res = spawn('node',
|
||||
[path.join(__dirname, 'fixtures', 'dumpio.js'), PROJECT_ROOT, JSON.stringify(options), server.EMPTY_PAGE, dumpioTextToLog]);
|
||||
res.stderr.on('data', data => dumpioData += data.toString('utf8'));
|
||||
|
14
test/test.js
14
test/test.js
@ -47,6 +47,7 @@ const defaultBrowserOptions = {
|
||||
executablePath,
|
||||
slowMo,
|
||||
headless,
|
||||
dumpio: (process.env.DUMPIO || 'false').trim().toLowerCase() === 'true',
|
||||
args: ['--no-sandbox']
|
||||
};
|
||||
const browserWithExtensionOptions = {
|
||||
@ -120,11 +121,22 @@ describe('Page', function() {
|
||||
state.browser = null;
|
||||
});
|
||||
|
||||
beforeEach(async state => {
|
||||
beforeEach(async(state, test) => {
|
||||
state.page = await state.browser.newPage();
|
||||
const rl = require('readline').createInterface({input: state.browser.process().stderr});
|
||||
test.output = '';
|
||||
rl.on('line', onLine);
|
||||
state.tearDown = () => {
|
||||
rl.removeListener('line', onLine);
|
||||
rl.close();
|
||||
};
|
||||
function onLine(line) {
|
||||
test.output += line + '\n';
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async state => {
|
||||
state.tearDown();
|
||||
await state.page.close();
|
||||
state.page = null;
|
||||
});
|
||||
|
@ -83,6 +83,10 @@ class Reporter {
|
||||
console.log(stack.join('\n'));
|
||||
}
|
||||
}
|
||||
if (test.output) {
|
||||
console.log(' Output:');
|
||||
console.log(test.output.split('\n').map(line => ' ' + line).join('\n'));
|
||||
}
|
||||
console.log('');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user