MCPcopy
hub / github.com/jestjs/jest / eventHandler

Function eventHandler

packages/jest-circus/src/eventHandler.ts:23–306  ·  view source on GitHub ↗
(event, state)

Source from the content-addressed store, hash-verified

21} from './utils';
22
23const eventHandler: Circus.EventHandler = (event, state) => {
24 switch (event.name) {
25 case 'include_test_location_in_result': {
26 state.includeTestLocationInResult = true;
27 break;
28 }
29 case 'hook_start': {
30 event.hook.seenDone = false;
31 break;
32 }
33 case 'start_describe_definition': {
34 const {blockName, mode} = event;
35 const {currentDescribeBlock, currentlyRunningTest} = state;
36
37 if (currentlyRunningTest) {
38 currentlyRunningTest.errors.push(
39 new Error(
40 `Cannot nest a describe inside a test. Describe block "${blockName}" cannot run because it is nested within "${currentlyRunningTest.name}".`,
41 ),
42 );
43 break;
44 }
45
46 const describeBlock = makeDescribe(blockName, currentDescribeBlock, mode);
47 currentDescribeBlock.children.push(describeBlock);
48 state.currentDescribeBlock = describeBlock;
49 break;
50 }
51 case 'finish_describe_definition': {
52 const {currentDescribeBlock} = state;
53 invariant(currentDescribeBlock, 'currentDescribeBlock must be there');
54
55 if (!describeBlockHasTests(currentDescribeBlock)) {
56 for (const hook of currentDescribeBlock.hooks) {
57 hook.asyncError.message = `Invalid: ${hook.type}() may not be used in a describe block containing no tests.`;
58 state.unhandledErrors.push(hook.asyncError);
59 }
60 }
61
62 // pass mode of currentDescribeBlock to tests
63 // but do not when there is already a single test with "only" mode
64 const shouldPassMode = !(
65 currentDescribeBlock.mode === 'only' &&
66 currentDescribeBlock.children.some(
67 child => child.type === 'test' && child.mode === 'only',
68 )
69 );
70 if (shouldPassMode) {
71 for (const child of currentDescribeBlock.children) {
72 if (child.type === 'test' && !child.mode) {
73 child.mode = currentDescribeBlock.mode;
74 }
75 }
76 }
77 if (
78 !state.hasFocusedTests &&
79 currentDescribeBlock.mode !== 'skip' &&
80 currentDescribeBlock.children.some(

Callers

nothing calls this directly

Calls 11

makeDescribeFunction · 0.90
invariantFunction · 0.90
describeBlockHasTestsFunction · 0.90
makeTestFunction · 0.90
getTestDurationFunction · 0.90
deleteMethod · 0.80
nowMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected