From 1bbd094624f24aaac674b2491131828f29166c7b Mon Sep 17 00:00:00 2001 From: Joel Einbinder Date: Tue, 29 May 2018 15:45:03 -0700 Subject: [PATCH] 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. --- test/puppeteer.spec.js | 2 +- test/test.js | 14 +++++++++++++- utils/testrunner/Reporter.js | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/test/puppeteer.spec.js b/test/puppeteer.spec.js index f5b144e406a..583990e7629 100644 --- a/test/puppeteer.spec.js +++ b/test/puppeteer.spec.js @@ -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')); diff --git a/test/test.js b/test/test.js index 3cb6c7a76c3..b1bf8999c3d 100644 --- a/test/test.js +++ b/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; }); diff --git a/utils/testrunner/Reporter.js b/utils/testrunner/Reporter.js index 9558d2a4f57..9f63affc49d 100644 --- a/utils/testrunner/Reporter.js +++ b/utils/testrunner/Reporter.js @@ -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(''); } }