mirror of https://github.com/facebook/jest.git
feat: pass `startedAt` to `onTestCaseResult` (#15145)
This commit is contained in:
parent
fb207dd5f9
commit
41f842a46b
|
@ -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 `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]` 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-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**] 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]` [**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))
|
- `[jest-config]` Loads config file from provided path in `package.json` ([#14044](https://github.com/facebook/jest/pull/14044))
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`Custom Reporters Integration on jest-circus valid failing assertion counts for adding reporters 1`] = `
|
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"
|
onTestFileResult testCaseResult 0: adds fail, status: failed, numExpectations: 0"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Custom Reporters Integration on jest-circus valid passing assertion counts for adding reporters 1`] = `
|
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"
|
onTestFileResult testCaseResult 0: adds ok, status: passed, numExpectations: 3"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`Custom Reporters Integration on jest-circus push test case results for todo tests 1`] = `
|
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"
|
onTestFileResult testCaseResult 0: sample, status: todo, numExpectations: 0"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,12 @@ class AssertionCountsReporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onTestCaseResult(test, testCaseResult) {
|
onTestCaseResult(test, testCaseResult) {
|
||||||
|
const difference = new Date(
|
||||||
|
Date.now() - testCaseResult.startedAt,
|
||||||
|
).getDate();
|
||||||
console.log(
|
console.log(
|
||||||
`onTestCaseResult: ${testCaseResult.title}, ` +
|
`onTestCaseResult: ${testCaseResult.title}, ` +
|
||||||
|
`started: ${difference === 1 ? 'today' : 'invalid'}, ` +
|
||||||
`status: ${testCaseResult.status}, ` +
|
`status: ${testCaseResult.status}, ` +
|
||||||
`numExpectations: ${testCaseResult.numPassingAsserts}`,
|
`numExpectations: ${testCaseResult.numPassingAsserts}`,
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,7 +11,7 @@ import dedent from 'dedent';
|
||||||
import isGeneratorFn from 'is-generator-fn';
|
import isGeneratorFn from 'is-generator-fn';
|
||||||
import slash = require('slash');
|
import slash = require('slash');
|
||||||
import StackUtils = require('stack-utils');
|
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 type {Circus, Global} from '@jest/types';
|
||||||
import {
|
import {
|
||||||
ErrorWithStack,
|
ErrorWithStack,
|
||||||
|
@ -490,7 +490,7 @@ const resolveTestCaseStartInfo = (
|
||||||
|
|
||||||
export const parseSingleTestResult = (
|
export const parseSingleTestResult = (
|
||||||
testResult: Circus.TestResult,
|
testResult: Circus.TestResult,
|
||||||
): AssertionResult => {
|
): TestCaseResult => {
|
||||||
let status: Status;
|
let status: Status;
|
||||||
if (testResult.status === 'skip') {
|
if (testResult.status === 'skip') {
|
||||||
status = 'pending';
|
status = 'pending';
|
||||||
|
@ -517,6 +517,7 @@ export const parseSingleTestResult = (
|
||||||
location: testResult.location,
|
location: testResult.location,
|
||||||
numPassingAsserts: testResult.numPassingAsserts,
|
numPassingAsserts: testResult.numPassingAsserts,
|
||||||
retryReasons: [...testResult.retryReasons],
|
retryReasons: [...testResult.retryReasons],
|
||||||
|
startedAt: testResult.startedAt,
|
||||||
status,
|
status,
|
||||||
title,
|
title,
|
||||||
};
|
};
|
||||||
|
|
|
@ -85,7 +85,7 @@ export type Suite = {
|
||||||
tests: Array<AssertionResult>;
|
tests: Array<AssertionResult>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TestCaseResult = AssertionResult;
|
export type TestCaseResult = AssertionResult & {startedAt?: number | null};
|
||||||
|
|
||||||
export type TestResult = {
|
export type TestResult = {
|
||||||
console?: ConsoleBuffer;
|
console?: ConsoleBuffer;
|
||||||
|
@ -209,7 +209,7 @@ export type TestEvents = {
|
||||||
'test-file-success': [Test, TestResult];
|
'test-file-success': [Test, TestResult];
|
||||||
'test-file-failure': [Test, SerializableError];
|
'test-file-failure': [Test, SerializableError];
|
||||||
'test-case-start': [string, Circus.TestCaseStartInfo];
|
'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> = (
|
export type TestFileEvent<T extends keyof TestEvents = keyof TestEvents> = (
|
||||||
|
|
Loading…
Reference in New Issue