diff --git a/packages/jest-circus/src/run.ts b/packages/jest-circus/src/run.ts index 8f198dadf166..d49cfdcb31bf 100644 --- a/packages/jest-circus/src/run.ts +++ b/packages/jest-circus/src/run.ts @@ -34,8 +34,12 @@ const _runTestsForDescribeBlock = async ( await dispatch({describeBlock, name: 'run_describe_start'}); const {beforeAll, afterAll} = getAllHooksForDescribe(describeBlock); - for (const hook of beforeAll) { - await _callCircusHook({describeBlock, hook}); + const isSkipped = describeBlock.mode === 'skip'; + + if (!isSkipped) { + for (const hook of beforeAll) { + await _callCircusHook({describeBlock, hook}); + } } // Tests that fail and are retried we run after other tests @@ -50,7 +54,7 @@ const _runTestsForDescribeBlock = async ( } case 'test': { const hasErrorsBeforeTestRun = child.errors.length > 0; - await _runTest(child); + await _runTest(child, isSkipped); if ( hasErrorsBeforeTestRun === false && @@ -72,24 +76,30 @@ const _runTestsForDescribeBlock = async ( // Clear errors so retries occur await dispatch({name: 'test_retry', test}); - await _runTest(test); + await _runTest(test, isSkipped); numRetriesAvailable--; } } - for (const hook of afterAll) { - await _callCircusHook({describeBlock, hook}); + if (!isSkipped) { + for (const hook of afterAll) { + await _callCircusHook({describeBlock, hook}); + } } await dispatch({describeBlock, name: 'run_describe_finish'}); }; -const _runTest = async (test: Circus.TestEntry): Promise => { +const _runTest = async ( + test: Circus.TestEntry, + parentSkipped: boolean, +): Promise => { await dispatch({name: 'test_start', test}); const testContext = Object.create(null); const {hasFocusedTests, testNamePattern} = getState(); const isSkipped = + parentSkipped || test.mode === 'skip' || (hasFocusedTests && test.mode !== 'only') || (testNamePattern && !testNamePattern.test(getTestID(test))); diff --git a/packages/jest-jasmine2/src/jasmine/Env.ts b/packages/jest-jasmine2/src/jasmine/Env.ts index 1eec2c46c99d..656d2bc44a5a 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.ts +++ b/packages/jest-jasmine2/src/jasmine/Env.ts @@ -611,7 +611,8 @@ export default function (j$: Jasmine) { () => {}, currentDeclarationSuite, ); - spec.todo(); + if (currentDeclarationSuite.markedPending) spec.pend(); + else spec.todo(); currentDeclarationSuite.addChild(spec); return spec; }; @@ -625,6 +626,7 @@ export default function (j$: Jasmine) { ); currentDeclarationSuite.addChild(spec); focusedRunnables.push(spec.id); + if (currentDeclarationSuite.markedPending) spec.pend(); unfocusAncestor(); return spec; }; diff --git a/packages/jest-jasmine2/src/treeProcessor.ts b/packages/jest-jasmine2/src/treeProcessor.ts index 6ad17abeabca..47b8ffb45456 100644 --- a/packages/jest-jasmine2/src/treeProcessor.ts +++ b/packages/jest-jasmine2/src/treeProcessor.ts @@ -65,10 +65,11 @@ export default function treeProcessor(options: Options): void { } function hasNoEnabledTest(node: TreeNode): boolean { - if (node.children) { - return node.children.every(hasNoEnabledTest); - } - return node.disabled || node.markedPending; + return ( + node.disabled || + node.markedPending || + (!!node.children && node.children.every(hasNoEnabledTest)) + ); } function wrapChildren(node: TreeNode, enabled: boolean) {