Add timestamps for logs into the functional tests reports (#24509) (#25238)

* feat(NA): first version to add logs to the functional test runner when running on dev.

* fix(NA): change timestamp position.

* test(NA): add unit test for tooling log text writer with timestamp.

* test(NA): update test and snapshots

* fix(NA): only apply timestamp logs for the jenkins test reports.

* test(NA): update jest snapshots correctly.

* fix(NA): only add timestamp for the test results cached chunk logs.

* fix(NA): rollback bad changes.

* refact(NA): change comments on code to be more clear with the purpose.

* refact(NA): rename chunk to line.

* feat(NA): log the relative time info since the start time of the task instead of the absolute time.
This commit is contained in:
Tiago Costa 2018-11-06 18:46:05 +00:00 committed by GitHub
parent 81bfe017d5
commit e3916bd007
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,7 @@ import { format } from 'util';
import Mocha from 'mocha';
import { ToolingLogTextWriter } from '@kbn/dev-utils';
import moment from 'moment';
import { setupJUnitReportGeneration } from '../../../../dev';
import * as colors from './colors';
@ -33,6 +34,7 @@ export function MochaReporterProvider({ getService }) {
const log = getService('log');
const config = getService('config');
let originalLogWriters;
let reporterCaptureStartTime;
return class MochaReporter extends Mocha.reporters.Base {
constructor(runner, options) {
@ -60,7 +62,10 @@ export function MochaReporterProvider({ getService }) {
onStart = () => {
if (config.get('mochaReporter.captureLogOutput')) {
log.warning('debug logs are being captured, only error logs will be written to the console');
reporterCaptureStartTime = moment();
originalLogWriters = log.getWriters();
log.setWriters([
new ToolingLogTextWriter({
level: 'error',
@ -69,7 +74,7 @@ export function MochaReporterProvider({ getService }) {
new ToolingLogTextWriter({
level: 'debug',
writeTo: {
write: (chunk) => {
write: (line) => {
// if the current runnable is a beforeEach hook then
// `runner.suite` is set to the suite that defined the
// hook, rather than the suite executing, so instead we
@ -80,7 +85,14 @@ export function MochaReporterProvider({ getService }) {
? this.runner.test.parent
: this.runner.suite;
recordLog(currentSuite, chunk);
// We are computing the difference between the time when this
// reporter has started and the time when each line are being
// logged in order to be able to label the test results log lines
// with this relative time information
const diffTimeSinceStart = moment().diff(reporterCaptureStartTime);
const readableDiffTimeSinceStart = `[${moment(diffTimeSinceStart).format('HH:mm:ss')}] `;
recordLog(currentSuite, `${readableDiffTimeSinceStart} ${line}`);
}
}
})