diff --git a/test/jest-light-runner/src/worker-runner.js b/test/jest-light-runner/src/worker-runner.js index af5fee56d0aa..a40bbb4340b6 100644 --- a/test/jest-light-runner/src/worker-runner.js +++ b/test/jest-light-runner/src/worker-runner.js @@ -1,12 +1,13 @@ import path from "path"; import { fileURLToPath, pathToFileURL } from "url"; +import { performance } from "perf_hooks"; import snapshot from "jest-snapshot"; import expect from "expect"; import * as circus from "jest-circus"; import "./global-setup.js"; -/** @typedef {{ failures: number, passses: number, pending: number }} Stats */ +/** @typedef {{ failures: number, passses: number, pending: number, start: number, end: number }} Stats */ /** @typedef {{ ancestors: string[], title: string, errors: Error[], skipped: boolean }} InternalTestResult */ // Node.js workers (worker_therads) don't support @@ -26,7 +27,7 @@ export default async function ({ test, updateSnapshot, port }) { port.postMessage("start"); /** @type {Stats} */ - const stats = { passes: 0, failures: 0, pending: 0 }; + const stats = { passes: 0, failures: 0, pending: 0, start: 0, end: 0 }; /** @type {Array} */ const results = []; @@ -38,7 +39,9 @@ export default async function ({ test, updateSnapshot, port }) { ); expect.setState({ snapshotState }); + stats.start = performance.now(); await runTestBlock(tests, hasFocusedTests, results, stats); + stats.end = performance.now(); snapshotState._inlineSnapshots.forEach(({ frame }) => { // When using native ESM, errors have an URL location. @@ -47,7 +50,7 @@ export default async function ({ test, updateSnapshot, port }) { }); snapshotState.save(); - return toTestResult(stats, results, test.path); + return toTestResult(stats, results, test); } async function loadTests(testFile) { @@ -160,10 +163,13 @@ function callAsync(fn) { * * @param {Stats} stats * @param {Array} tests - * @param {string} path + * @param {import("@jest/test-result").Test} testInput * @returns {import("@jest/test-result").TestResult} */ -function toTestResult(stats, tests, path) { +function toTestResult(stats, tests, { path, context }) { + const { start, end } = stats; + const runtime = end - start; + return { coverage: globalThis.__coverage__, console: null, @@ -175,8 +181,10 @@ function toTestResult(stats, tests, path) { numPassingTests: stats.passes, numPendingTests: stats.pending, perfStats: { - end: +new Date(stats.end), - start: +new Date(stats.start), + start, + end, + runtime: Math.round(runtime), // ms precision + slow: runtime / 1000 > context.config.slowTestThreshold, }, skipped: false, snapshot: {