Skip to content

Commit 5a7a6c4

Browse files
authored
[jest-circus] Clear the current test after skipped and todo tests (#16342)
1 parent b654d7e commit 5a7a6c4

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
- `[expect, jest-message-util, jest-pattern, jest-regex-util, jest-util]` Revert `node:` protocol imports to restore webpack/browser-bundle compatibility ([#16167](https://github.com/jestjs/jest/pull/16167))
1818
- `[expect]` Widen `toMatchObject` and `objectContaining` parameter type from `Record<string, unknown>` to `object` so class instances are accepted ([#16196](https://github.com/jestjs/jest/pull/16196))
19+
- `[jest-circus]` Clear `currentlyRunningTest` after skipped and todo tests ([#16342](https://github.com/jestjs/jest/pull/16342))
1920
- `[jest-circus, jest-jasmine2, jest-message-util]` Serialize the inner errors of an `AggregateError` into `failureMessages`, `retryReasons` and `unhandledErrors`, so `--json` output and reporter annotations include them ([#16316](https://github.com/jestjs/jest/pull/16316))
2021
- `[@jest/create-cache-key-function]` Include the caller support flags in the generated key, so a transformer that emits ESM or CJS based on them no longer shares one cache entry between the two ([#16331](https://github.com/jestjs/jest/pull/16331))
2122
- `[@jest/create-cache-key-function]` Include the stringified project config in the generated key, so editing a transformer's own settings invalidates what it cached ([#16331](https://github.com/jestjs/jest/pull/16331))

‎packages/jest-circus/src/__tests__/eventHandler.test.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// addEventHandler and removeEventHandler are provided in the ./index
99
import {addEventHandler, removeEventHandler} from '../index';
1010
// dispatch comes from the ./state
11-
import {dispatch} from '../state';
11+
import eventHandler from '../eventHandler';
12+
import {dispatch, getState, resetState} from '../state';
13+
import {makeTest} from '../utils';
1214

1315
test('addEventHandler and removeEventHandler control handlers', async () => {
1416
const spy: any = jest.fn();
@@ -23,3 +25,28 @@ test('addEventHandler and removeEventHandler control handlers', async () => {
2325
await dispatch({name: 'unknown2' as any});
2426
expect(spy).not.toHaveBeenCalledWith({name: 'unknown2'}, expect.anything());
2527
});
28+
29+
test('clears the currently running test when a test is skipped or todo', async () => {
30+
resetState();
31+
const state = getState();
32+
const circusTest = makeTest(
33+
() => {},
34+
undefined,
35+
false,
36+
'test',
37+
state.rootDescribeBlock,
38+
undefined,
39+
new Error(),
40+
false,
41+
);
42+
43+
state.currentlyRunningTest = circusTest;
44+
await eventHandler({name: 'test_skip', test: circusTest}, state);
45+
expect(circusTest.status).toBe('skip');
46+
expect(state.currentlyRunningTest).toBeNull();
47+
48+
state.currentlyRunningTest = circusTest;
49+
await eventHandler({name: 'test_todo', test: circusTest}, state);
50+
expect(circusTest.status).toBe('todo');
51+
expect(state.currentlyRunningTest).toBeNull();
52+
});

‎packages/jest-circus/src/eventHandler.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,12 @@ const eventHandler: Circus.EventHandler = (event, state) => {
184184
}
185185
case 'test_skip': {
186186
event.test.status = 'skip';
187+
state.currentlyRunningTest = null;
187188
break;
188189
}
189190
case 'test_todo': {
190191
event.test.status = 'todo';
192+
state.currentlyRunningTest = null;
191193
break;
192194
}
193195
case 'test_done': {

0 commit comments

Comments
 (0)