Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Features

- `[jest-circus, jest-test-result]` Pass startedAt timestamp in `TestCaseResultObject` seen in `onTestCaseResult` ([#15145](https://github.com/jestjs/jest/pull/15145))
- `[babel-jest]` Add option `excludeJestPreset` to allow opting out of `babel-preset-jest` ([#15164](https://github.com/jestjs/jest/pull/15164))
- `[jest-circus, jest-cli, jest-config]` Add `waitNextEventLoopTurnForUnhandledRejectionEvents` flag to minimise performance impact of correct detection of unhandled promise rejections introduced in [#14315](https://github.com/jestjs/jest/pull/14315) ([#14681](https://github.com/jestjs/jest/pull/14681))
- `[jest-circus]` Add a `waitBeforeRetry` option to `jest.retryTimes` ([#14738](https://github.com/jestjs/jest/pull/14738))
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
`;

Expand Down
4 changes: 4 additions & 0 deletions e2e/custom-reporters/reporters/AssertionCountsReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
);
Expand Down
5 changes: 3 additions & 2 deletions packages/jest-circus/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -490,7 +490,7 @@ const resolveTestCaseStartInfo = (

export const parseSingleTestResult = (
testResult: Circus.TestResult,
): AssertionResult => {
): TestCaseResult => {
let status: Status;
if (testResult.status === 'skip') {
status = 'pending';
Expand All @@ -517,6 +517,7 @@ export const parseSingleTestResult = (
location: testResult.location,
numPassingAsserts: testResult.numPassingAsserts,
retryReasons: [...testResult.retryReasons],
startedAt: testResult.startedAt,
status,
title,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-test-result/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export type Suite = {
tests: Array<AssertionResult>;
};

export type TestCaseResult = AssertionResult;
export type TestCaseResult = AssertionResult & {startedAt?: number | null};

export type TestResult = {
console?: ConsoleBuffer;
Expand Down Expand Up @@ -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<T extends keyof TestEvents = keyof TestEvents> = (
Expand Down