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