diff --git a/test/electron/electron.spec.js b/test/electron/electron.spec.js index 2b48522838..2daa01a3e1 100644 --- a/test/electron/electron.spec.js +++ b/test/electron/electron.spec.js @@ -16,40 +16,23 @@ const path = require('path'); const config = require('../test.config'); +const utils = require('../utils'); const electronName = process.platform === 'win32' ? 'electron.cmd' : 'electron'; describe('Electron', function() { beforeEach(async (state, testRun) => { const electronPath = path.join(__dirname, '..', '..', 'node_modules', '.bin', electronName); + state.logger = utils.createTestLogger(config.dumpLogOnFailure, testRun); state.application = await playwright.electron.launch(electronPath, { args: [path.join(__dirname, 'testApp.js')], // This is for our own extensive protocol logging, customers don't need it. - logger: { - isEnabled: (name, severity) => { - return name === 'browser' || - (name === 'protocol' && config.dumpProtocolOnFailure); - }, - log: (name, severity, message, args) => { - if (name === 'browser') { - if (severity === 'warning') - testRun.log(`\x1b[31m[browser]\x1b[0m ${message}`) - else - testRun.log(`\x1b[33m[browser]\x1b[0m ${message}`) - } else if (name === 'protocol' && config.dumpProtocolOnFailure) { - testRun.log(`\x1b[32m[protocol]\x1b[0m ${message}`) - } - } - } + logger: state.logger, }); }); afterEach(async (state, testRun) => { await state.application.close(); - // This is for our own extensive protocol logging, customers don't need it. - if (config.dumpProtocolOnFailure) { - if (testRun.ok()) - testRun.output().splice(0); - } + state.logger.setTestRun(null); }); it('should script application', async ({ application }) => { const appPath = await application.evaluate(async ({ app }) => app.getAppPath()); diff --git a/test/test.config.js b/test/test.config.js index bde7c822a2..53da76cdf7 100644 --- a/test/test.config.js +++ b/test/test.config.js @@ -150,7 +150,7 @@ function setupTestRunner(testRunner) { module.exports = { playwrightPath, - dumpProtocolOnFailure: valueFromEnv('DEBUGP', false), + dumpLogOnFailure: valueFromEnv('DEBUGP', false), launchOptions: { executablePath: { chromium: process.env.CRPATH, diff --git a/test/test.js b/test/test.js index 586a87c7f7..d181cf8607 100644 --- a/test/test.js +++ b/test/test.js @@ -120,7 +120,7 @@ function collect(browserNames) { const browserEnvironment = new Environment(browserName); browserEnvironment.beforeAll(async state => { - state._logger = utils.createTestLogger(config.dumpProtocolOnFailure); + state._logger = utils.createTestLogger(config.dumpLogOnFailure); state.browser = await state.browserType.launch({...launchOptions, logger: state._logger}); }); browserEnvironment.afterAll(async state => { diff --git a/test/utils.js b/test/utils.js index d79408e6b4..268d0d87f4 100644 --- a/test/utils.js +++ b/test/utils.js @@ -192,7 +192,7 @@ const utils = module.exports = { platform = p; }, - createTestLogger(dumpProtocolOnFailure = true, testRun = null, prefix = '') { + createTestLogger(dumpLogOnFailure = true, testRun = null, prefix = '') { const colors = [31, 32, 33, 34, 35, 36, 37]; let colorIndex = 0; for (let i = 0; i < prefix.length; i++) @@ -202,7 +202,7 @@ const utils = module.exports = { const logger = { isEnabled: (name, severity) => { - return name.startsWith('browser') || (name === 'protocol' && dumpProtocolOnFailure); + return name.startsWith('browser') || dumpLogOnFailure; }, log: (name, severity, message, args) => { if (!testRun) @@ -212,8 +212,8 @@ const utils = module.exports = { testRun.log(`${prefix}\x1b[31m[browser]\x1b[0m ${message}`) else testRun.log(`${prefix}\x1b[33m[browser]\x1b[0m ${message}`) - } else if (name === 'protocol' && dumpProtocolOnFailure) { - testRun.log(`${prefix}\x1b[32m[protocol]\x1b[0m ${message}`) + } else if (dumpLogOnFailure) { + testRun.log(`${prefix}\x1b[32m[${name}]\x1b[0m ${message}`) } }, setTestRun(tr) {