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:
Joel Einbinder 2018-05-29 15:45:03 -07:00 committed by Andrey Lushnikov
parent 8e12d197a2
commit 1bbd094624
3 changed files with 18 additions and 2 deletions

View File

@ -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'));

View File

@ -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;
});

View File

@ -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('');
}
}