From 1388ea7460def03d8b49a49069758fe7749b47d9 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Mon, 24 Oct 2022 10:02:40 +0100 Subject: [PATCH 1/4] Fix #13482: `.todo` tests are shown as `todo` when inside a focussed describe --- e2e/__tests__/__snapshots__/testTodo.test.ts.snap | 14 ++++++++++++++ e2e/__tests__/testTodo.test.ts | 7 +++++++ e2e/test-todo/__tests__/only-todo.test.js | 13 +++++++++++++ packages/jest-circus/src/run.ts | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 e2e/test-todo/__tests__/only-todo.test.js diff --git a/e2e/__tests__/__snapshots__/testTodo.test.ts.snap b/e2e/__tests__/__snapshots__/testTodo.test.ts.snap index 223f73fe35e8..a9e1ff123e2b 100644 --- a/e2e/__tests__/__snapshots__/testTodo.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testTodo.test.ts.snap @@ -1,5 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`counts todo tests when inside of a \`describe.only\` 1`] = ` +"PASS __tests__/only-todo.test.js + with .only, should show 'passed', 'todo', 'todo' + ✓ passing test + ✎ todo todo test 1 + ✎ todo todo test 2 + +Test Suites: 1 passed, 1 total +Tests: 2 todo, 1 passed, 3 total +Snapshots: 0 total +Time: <> +Ran all test suites matching /only-todo.test.js/i." +`; + exports[`shows error messages when called with invalid argument 1`] = ` "FAIL __tests__/todoNonString.test.js ● Test suite failed to run diff --git a/e2e/__tests__/testTodo.test.ts b/e2e/__tests__/testTodo.test.ts index d1b608227088..bf60beb7c3ff 100644 --- a/e2e/__tests__/testTodo.test.ts +++ b/e2e/__tests__/testTodo.test.ts @@ -44,3 +44,10 @@ test('shows todo messages when in verbose mode', () => { const {rest} = extractSummary(result.stderr); expect(rest).toMatchSnapshot(); }); + +test('counts todo tests when inside of a `describe.only`', () => { + const result = runJest(dir, ['only-todo.test.js']); + expect(result.exitCode).toBe(0); + const {rest, summary} = extractSummary(result.stderr); + expect(`${rest}\n\n${summary}`).toMatchSnapshot(); +}); diff --git a/e2e/test-todo/__tests__/only-todo.test.js b/e2e/test-todo/__tests__/only-todo.test.js new file mode 100644 index 000000000000..4be0d53006c0 --- /dev/null +++ b/e2e/test-todo/__tests__/only-todo.test.js @@ -0,0 +1,13 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +'use strict'; + +describe.only("with .only, should show 'passed', 'todo', 'todo'", () => { + test('passing test', () => {}); + test.todo('todo test 1'); + test.todo('todo test 2'); +}); diff --git a/packages/jest-circus/src/run.ts b/packages/jest-circus/src/run.ts index 562a49aa38e3..4d1f69a4e609 100644 --- a/packages/jest-circus/src/run.ts +++ b/packages/jest-circus/src/run.ts @@ -147,7 +147,7 @@ const _runTest = async ( const isSkipped = parentSkipped || test.mode === 'skip' || - (hasFocusedTests && test.mode !== 'only') || + (hasFocusedTests && test.mode === undefined) || (testNamePattern && !testNamePattern.test(getTestID(test))); if (isSkipped) { From 11bea088090f437f89622b4cf8a52e510e531df8 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Mon, 24 Oct 2022 10:06:29 +0100 Subject: [PATCH 2/4] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0db12a656313..48bb9f6b3899 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- `[jest-circus]` Test marked as `todo` are shown as todo when inside a focussed describe ([#13504](https://github.com/facebook/jest/pull/13504)) - `[@jest/test-sequencer]` Make sure sharding does not produce empty groups ([#13476](https://github.com/facebook/jest/pull/13476)) ### Chore & Maintenance From 095e6d636df49b30af68698fff76b73d3c75cd58 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Mon, 24 Oct 2022 10:58:45 +0100 Subject: [PATCH 3/4] Fix lint error --- e2e/test-todo/__tests__/only-todo.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/e2e/test-todo/__tests__/only-todo.test.js b/e2e/test-todo/__tests__/only-todo.test.js index 4be0d53006c0..6bc35448d084 100644 --- a/e2e/test-todo/__tests__/only-todo.test.js +++ b/e2e/test-todo/__tests__/only-todo.test.js @@ -4,6 +4,9 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ + +/* eslint-disable jest/no-focused-tests */ + 'use strict'; describe.only("with .only, should show 'passed', 'todo', 'todo'", () => { From f460e58636455361405cb5ddc71833bd259b77da Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 24 Oct 2022 12:04:57 +0200 Subject: [PATCH 4/4] move chnagelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02a8e0b713f0..fbba7206284a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,8 @@ ### Fixes -- `[jest-circus]` Test marked as `todo` are shown as todo when inside a focussed describe ([#13504](https://github.com/facebook/jest/pull/13504)) - `[@jest/test-sequencer]` Make sure sharding does not produce empty groups ([#13476](https://github.com/facebook/jest/pull/13476)) +- `[jest-circus]` Test marked as `todo` are shown as todo when inside a focussed describe ([#13504](https://github.com/facebook/jest/pull/13504)) - `[jest-mock]` Ensure mock resolved and rejected values are promises from correct realm ([#13503](https://github.com/facebook/jest/pull/13503)) ### Chore & Maintenance