Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass startedAt onTestCaseResult #15145

Merged
merged 8 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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))
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
Loading