test: dump all logs in DEBUGP mode (#2517)
This commit is contained in:
parent
6d8f39b318
commit
4faa1306b9
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ function setupTestRunner(testRunner) {
|
|||
|
||||
module.exports = {
|
||||
playwrightPath,
|
||||
dumpProtocolOnFailure: valueFromEnv('DEBUGP', false),
|
||||
dumpLogOnFailure: valueFromEnv('DEBUGP', false),
|
||||
launchOptions: {
|
||||
executablePath: {
|
||||
chromium: process.env.CRPATH,
|
||||
|
|
|
|||
|
|
@ -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 => {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue