feat(testrunner): add DEBUG to testrunner (#1014)

The plan is to collect logs for the whole test run and upload it later on
using https://github.com/actions/upload-artifact

Produced log size:
- 163MB (8.5MB zipped) for Chromium: `DEBUG=* npm run unit 2>log`
- 135MB (4.8MB zipped) for WebKit: `DEBUG=*,-pw:wrapped* npm run wunit 2>log`
- 29MB (4.0MB zipped) for Firefox: `DEBUG=* npm run funit 2>log`
This commit is contained in:
Andrey Lushnikov 2020-02-14 15:21:08 -08:00 committed by GitHub
parent 2e9e0b77bf
commit 8487ef2821
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,7 @@ const EventEmitter = require('events');
const Multimap = require('./Multimap'); const Multimap = require('./Multimap');
const fs = require('fs'); const fs = require('fs');
const {SourceMapSupport} = require('./SourceMapSupport'); const {SourceMapSupport} = require('./SourceMapSupport');
const debug = require('debug');
const INFINITE_TIMEOUT = 2147483647; const INFINITE_TIMEOUT = 2147483647;
@ -240,6 +241,7 @@ class TestPass {
} else { } else {
// Otherwise, run the test itself if there is no scheduled termination. // Otherwise, run the test itself if there is no scheduled termination.
this._runningUserCallbacks.set(workerId, test._userCallback); this._runningUserCallbacks.set(workerId, test._userCallback);
this._runner._willStartTestBody(test, workerId);
test.error = await test._userCallback.run(state, test); test.error = await test._userCallback.run(state, test);
if (test.error) if (test.error)
await this._runner._sourceMapSupport.rewriteStackTraceWithSourceMaps(test.error); await this._runner._sourceMapSupport.rewriteStackTraceWithSourceMaps(test.error);
@ -252,6 +254,7 @@ class TestPass {
test.result = TestResult.Terminated; test.result = TestResult.Terminated;
else else
test.result = TestResult.Failed; test.result = TestResult.Failed;
this._runner._didFinishTestBody(test, workerId);
} }
for (let i = suitesStack.length - 1; i >= 0; i--) for (let i = suitesStack.length - 1; i >= 0; i--)
crashed = (await this._runHook(workerId, suitesStack[i], 'afterEach', state, test)) || crashed; crashed = (await this._runHook(workerId, suitesStack[i], 'afterEach', state, test)) || crashed;
@ -267,19 +270,23 @@ class TestPass {
const hook = suite[hookName]; const hook = suite[hookName];
if (!hook) if (!hook)
return false; return false;
this._runner._willStartHook(suite, hook, hookName, workerId);
this._runningUserCallbacks.set(workerId, hook); this._runningUserCallbacks.set(workerId, hook);
const error = await hook.run(...args); const error = await hook.run(...args);
this._runningUserCallbacks.delete(workerId, hook); this._runningUserCallbacks.delete(workerId, hook);
if (error === TimeoutError) { if (error === TimeoutError) {
const location = `${hook.location.fileName}:${hook.location.lineNumber}:${hook.location.columnNumber}`; const location = `${hook.location.fileName}:${hook.location.lineNumber}:${hook.location.columnNumber}`;
const message = `${location} - Timeout Exceeded ${hook.timeout}ms while running "${hookName}" in suite "${suite.fullName}"`; const message = `${location} - Timeout Exceeded ${hook.timeout}ms while running "${hookName}" in suite "${suite.fullName}"`;
this._runner._didFailHook(suite, hook, hookName);
return await this._terminate(TestResult.Crashed, message, null); return await this._terminate(TestResult.Crashed, message, null);
} }
if (error) { if (error) {
const location = `${hook.location.fileName}:${hook.location.lineNumber}:${hook.location.columnNumber}`; const location = `${hook.location.fileName}:${hook.location.lineNumber}:${hook.location.columnNumber}`;
const message = `${location} - FAILED while running "${hookName}" in suite "${suite.fullName}"`; const message = `${location} - FAILED while running "${hookName}" in suite "${suite.fullName}"`;
this._runner._didFailHook(suite, hook, hookName);
return await this._terminate(TestResult.Crashed, message, error); return await this._terminate(TestResult.Crashed, message, error);
} }
this._runner._didCompleteHook(suite, hook, hookName);
return false; return false;
} }
@ -289,6 +296,7 @@ class TestPass {
if (error && error.stack) if (error && error.stack)
await this._runner._sourceMapSupport.rewriteStackTraceWithSourceMaps(error); await this._runner._sourceMapSupport.rewriteStackTraceWithSourceMaps(error);
this._termination = {result, message, error}; this._termination = {result, message, error};
this._runner._willTerminate(this._termination);
for (const userCallback of this._runningUserCallbacks.valuesArray()) for (const userCallback of this._runningUserCallbacks.valuesArray())
userCallback.terminate(); userCallback.terminate();
return true; return true;
@ -509,6 +517,30 @@ class TestRunner extends EventEmitter {
test.endTimestamp = Date.now(); test.endTimestamp = Date.now();
this.emit(TestRunner.Events.TestFinished, test, workerId); this.emit(TestRunner.Events.TestFinished, test, workerId);
} }
_willStartTestBody(test, workerId) {
debug('testrunner:test')(`starting "${test.fullName}" (${test.location.fileName + ':' + test.location.lineNumber})`);
}
_didFinishTestBody(test, workerId) {
debug('testrunner:test')(`${test.result.toUpperCase()} "${test.fullName}" (${test.location.fileName + ':' + test.location.lineNumber})`);
}
_willStartHook(suite, hook, hookName, workerId) {
debug('testrunner:hook')(`"${hookName}" started for "${suite.fullName}" (${hook.location.fileName + ':' + hook.location.lineNumber})`);
}
_didFailHook(suite, hook, hookName, workerId) {
debug('testrunner:hook')(`"${hookName}" FAILED for "${suite.fullName}" (${hook.location.fileName + ':' + hook.location.lineNumber})`);
}
_didCompleteHook(suite, hook, hookName, workerId) {
debug('testrunner:hook')(`"${hookName}" OK for "${suite.fullName}" (${hook.location.fileName + ':' + hook.location.lineNumber})`);
}
_willTerminate(termination) {
debug('testrunner')(`TERMINTED result = ${termination.result}, message = ${termination.message}`);
}
} }
async function setLogBreakpoints(debuggerLogBreakpoints) { async function setLogBreakpoints(debuggerLogBreakpoints) {