diff --git a/CHANGELOG.md b/CHANGELOG.md index dfb02abcd021..01e5bb097cc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - `[jest-circus]` Add a `waitBeforeRetry` option to `jest.retryTimes` ([#14738](https://github.com/jestjs/jest/pull/14738)) - `[jest-circus]` Add a `retryImmediately` option to `jest.retryTimes` ([#14696](https://github.com/jestjs/jest/pull/14696)) - `[jest-circus, jest-jasmine2]` Allow `setupFilesAfterEnv` to export an async function ([#10962](https://github.com/jestjs/jest/issues/10962)) +- `[jest-circus, jest-test-result]` Add `startedAt` timestamp in `TestCaseResultObject` within `onTestCaseResult` ([#15145](https://github.com/jestjs/jest/pull/15145)) - `[jest-config]` [**BREAKING**] Add `mts` and `cts` to default `moduleFileExtensions` config ([#14369](https://github.com/facebook/jest/pull/14369)) - `[jest-config]` [**BREAKING**] Update `testMatch` and `testRegex` default option for supporting `mjs`, `cjs`, `mts`, and `cts` ([#14584](https://github.com/jestjs/jest/pull/14584)) - `[jest-config]` Loads config file from provided path in `package.json` ([#14044](https://github.com/facebook/jest/pull/14044)) diff --git a/e2e/__tests__/__snapshots__/customReportersOnCircus.test.ts.snap b/e2e/__tests__/__snapshots__/customReportersOnCircus.test.ts.snap index e52b96c3dbb6..6403c2c464f4 100644 --- a/e2e/__tests__/__snapshots__/customReportersOnCircus.test.ts.snap +++ b/e2e/__tests__/__snapshots__/customReportersOnCircus.test.ts.snap @@ -1,17 +1,17 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Custom Reporters Integration on jest-circus valid failing assertion counts for adding reporters 1`] = ` -"onTestCaseResult: adds fail, status: failed, numExpectations: 0 +"onTestCaseResult: adds fail, started: today, status: failed, numExpectations: 0 onTestFileResult testCaseResult 0: adds fail, status: failed, numExpectations: 0" `; exports[`Custom Reporters Integration on jest-circus valid passing assertion counts for adding reporters 1`] = ` -"onTestCaseResult: adds ok, status: passed, numExpectations: 3 +"onTestCaseResult: adds ok, started: today, status: passed, numExpectations: 3 onTestFileResult testCaseResult 0: adds ok, status: passed, numExpectations: 3" `; exports[`Custom Reporters Integration on jest-circus push test case results for todo tests 1`] = ` -"onTestCaseResult: sample, status: todo, numExpectations: 0 +"onTestCaseResult: sample, started: today, status: todo, numExpectations: 0 onTestFileResult testCaseResult 0: sample, status: todo, numExpectations: 0" `; diff --git a/e2e/custom-reporters/reporters/AssertionCountsReporter.js b/e2e/custom-reporters/reporters/AssertionCountsReporter.js index 7777efd828b0..8b177283c2d6 100644 --- a/e2e/custom-reporters/reporters/AssertionCountsReporter.js +++ b/e2e/custom-reporters/reporters/AssertionCountsReporter.js @@ -18,8 +18,12 @@ class AssertionCountsReporter { } } onTestCaseResult(test, testCaseResult) { + const difference = new Date( + Date.now() - testCaseResult.startedAt, + ).getDate(); console.log( `onTestCaseResult: ${testCaseResult.title}, ` + + `started: ${difference === 1 ? 'today' : 'invalid'}, ` + `status: ${testCaseResult.status}, ` + `numExpectations: ${testCaseResult.numPassingAsserts}`, ); diff --git a/packages/jest-circus/src/utils.ts b/packages/jest-circus/src/utils.ts index 84aab232bde1..9776072964b0 100644 --- a/packages/jest-circus/src/utils.ts +++ b/packages/jest-circus/src/utils.ts @@ -11,7 +11,7 @@ import dedent from 'dedent'; import isGeneratorFn from 'is-generator-fn'; import slash = require('slash'); import StackUtils = require('stack-utils'); -import type {AssertionResult, Status} from '@jest/test-result'; +import type {Status, TestCaseResult} from '@jest/test-result'; import type {Circus, Global} from '@jest/types'; import { ErrorWithStack, @@ -490,7 +490,7 @@ const resolveTestCaseStartInfo = ( export const parseSingleTestResult = ( testResult: Circus.TestResult, -): AssertionResult => { +): TestCaseResult => { let status: Status; if (testResult.status === 'skip') { status = 'pending'; @@ -517,6 +517,7 @@ export const parseSingleTestResult = ( location: testResult.location, numPassingAsserts: testResult.numPassingAsserts, retryReasons: [...testResult.retryReasons], + startedAt: testResult.startedAt, status, title, }; diff --git a/packages/jest-test-result/src/types.ts b/packages/jest-test-result/src/types.ts index 7200d5a73da8..6fb6c645e2c9 100644 --- a/packages/jest-test-result/src/types.ts +++ b/packages/jest-test-result/src/types.ts @@ -85,7 +85,7 @@ export type Suite = { tests: Array; }; -export type TestCaseResult = AssertionResult; +export type TestCaseResult = AssertionResult & {startedAt?: number | null}; export type TestResult = { console?: ConsoleBuffer; @@ -209,7 +209,7 @@ export type TestEvents = { 'test-file-success': [Test, TestResult]; 'test-file-failure': [Test, SerializableError]; 'test-case-start': [string, Circus.TestCaseStartInfo]; - 'test-case-result': [string, AssertionResult]; + 'test-case-result': [string, TestCaseResult]; }; export type TestFileEvent = (