diff --git a/src/functional_test_runner/lib/mocha/reporter/reporter.js b/src/functional_test_runner/lib/mocha/reporter/reporter.js index 39c69f914e43f..1df3fc8b6bf18 100644 --- a/src/functional_test_runner/lib/mocha/reporter/reporter.js +++ b/src/functional_test_runner/lib/mocha/reporter/reporter.js @@ -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}`); } } })