From e195f5ed333a844b178c87fdccbdf59e0075f876 Mon Sep 17 00:00:00 2001 From: Akshit Sinha Date: Wed, 15 Feb 2023 21:11:09 +0530 Subject: [PATCH 1/4] send test case results for test_todo event --- e2e/__tests__/customReporters.test.ts | 23 +++++++++++++++++++ .../jest-circus/src/testCaseReportHandler.ts | 1 + 2 files changed, 24 insertions(+) diff --git a/e2e/__tests__/customReporters.test.ts b/e2e/__tests__/customReporters.test.ts index fc40f36c2368..f066ad865155 100644 --- a/e2e/__tests__/customReporters.test.ts +++ b/e2e/__tests__/customReporters.test.ts @@ -135,6 +135,29 @@ describe('Custom Reporters Integration', () => { expect(stdout).toMatchSnapshot(); }); + test('shows testCaseResult with todo', () => { + writeFiles(DIR, { + '__tests__/test.test.js': "it.todo('test');", + 'package.json': JSON.stringify({ + jest: { + reporters: ['default', '/reporter.js'], + }, + }), + 'reporter.js': ` + 'use strict'; + module.exports = class Reporter { + onTestCaseResult(test, testCaseResult) { + console.log(testCaseResult.title) + } + }; + `, + }); + + const {stdout, exitCode} = runJest(DIR); + expect(stdout).toBe('test'); + expect(exitCode).toBe(0); + }); + test('prints reporter errors', () => { writeFiles(DIR, { '__tests__/test.test.js': "test('test', () => {});", diff --git a/packages/jest-circus/src/testCaseReportHandler.ts b/packages/jest-circus/src/testCaseReportHandler.ts index 2711654e4dfe..f7633db2622e 100644 --- a/packages/jest-circus/src/testCaseReportHandler.ts +++ b/packages/jest-circus/src/testCaseReportHandler.ts @@ -13,6 +13,7 @@ const testCaseReportHandler = (testPath: string, sendMessageToJest: TestFileEvent) => (event: Circus.Event): void => { switch (event.name) { + case 'test_todo': case 'test_done': { const testResult = makeSingleTestResult(event.test); const testCaseResult = parseSingleTestResult(testResult); From 772f68447e62e205900b149c28e3824528f0f68d Mon Sep 17 00:00:00 2001 From: Akshit Sinha <34775769+akshitsinha@users.noreply.github.com> Date: Wed, 15 Feb 2023 21:38:37 +0530 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce86f3d161fa..9e1efa3ca199 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - `[jest-mock]` Clear mock state when `jest.restoreAllMocks()` is called ([#13867](https://github.com/facebook/jest/pull/13867)) - `[jest-mock]` Prevent `mockImplementationOnce` and `mockReturnValueOnce` bleeding into `withImplementation` ([#13888](https://github.com/facebook/jest/pull/13888)) +- `[jest-circus]` Send test case results for `todo` tests ([#13915](https://github.com/facebook/jest/pull/13915)) ### Chore & Maintenance From 2671e4040f9c438af1df41dd97e92d1d863343f4 Mon Sep 17 00:00:00 2001 From: Akshit Sinha <34775769+akshitsinha@users.noreply.github.com> Date: Wed, 15 Feb 2023 22:40:10 +0530 Subject: [PATCH 3/4] Update changelog --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc2a5a551a85..771b2cbc83f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,6 @@ ### Fixes -- `[jest-mock]` Clear mock state when `jest.restoreAllMocks()` is called ([#13867](https://github.com/facebook/jest/pull/13867)) -- `[jest-mock]` Prevent `mockImplementationOnce` and `mockReturnValueOnce` bleeding into `withImplementation` ([#13888](https://github.com/facebook/jest/pull/13888)) - `[jest-circus]` Send test case results for `todo` tests ([#13915](https://github.com/facebook/jest/pull/13915)) ### Chore & Maintenance From 8075e0714c7c4c59fed96ee8c969f327aa740631 Mon Sep 17 00:00:00 2001 From: Akshit Sinha Date: Thu, 16 Feb 2023 14:17:40 +0530 Subject: [PATCH 4/4] Fix tests --- .../customReportersOnCircus.test.ts.snap | 5 ++++ e2e/__tests__/customReporters.test.ts | 23 ------------------- e2e/__tests__/customReportersOnCircus.test.ts | 15 ++++++++++++ e2e/custom-reporters/__tests__/todo.test.js | 13 +++++++++++ 4 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 e2e/custom-reporters/__tests__/todo.test.js diff --git a/e2e/__tests__/__snapshots__/customReportersOnCircus.test.ts.snap b/e2e/__tests__/__snapshots__/customReportersOnCircus.test.ts.snap index 0867a8829991..0f5823c60467 100644 --- a/e2e/__tests__/__snapshots__/customReportersOnCircus.test.ts.snap +++ b/e2e/__tests__/__snapshots__/customReportersOnCircus.test.ts.snap @@ -9,3 +9,8 @@ exports[`Custom Reporters Integration on jest-circus valid passing assertion cou "onTestCaseResult: 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`] = ` +"onTestCaseResult: sample, status: todo, numExpectations: 0 +onTestFileResult testCaseResult 0: sample, status: todo, numExpectations: 0" +`; diff --git a/e2e/__tests__/customReporters.test.ts b/e2e/__tests__/customReporters.test.ts index f066ad865155..fc40f36c2368 100644 --- a/e2e/__tests__/customReporters.test.ts +++ b/e2e/__tests__/customReporters.test.ts @@ -135,29 +135,6 @@ describe('Custom Reporters Integration', () => { expect(stdout).toMatchSnapshot(); }); - test('shows testCaseResult with todo', () => { - writeFiles(DIR, { - '__tests__/test.test.js': "it.todo('test');", - 'package.json': JSON.stringify({ - jest: { - reporters: ['default', '/reporter.js'], - }, - }), - 'reporter.js': ` - 'use strict'; - module.exports = class Reporter { - onTestCaseResult(test, testCaseResult) { - console.log(testCaseResult.title) - } - }; - `, - }); - - const {stdout, exitCode} = runJest(DIR); - expect(stdout).toBe('test'); - expect(exitCode).toBe(0); - }); - test('prints reporter errors', () => { writeFiles(DIR, { '__tests__/test.test.js': "test('test', () => {});", diff --git a/e2e/__tests__/customReportersOnCircus.test.ts b/e2e/__tests__/customReportersOnCircus.test.ts index 57f35e3b50e6..c6faf69467ae 100644 --- a/e2e/__tests__/customReportersOnCircus.test.ts +++ b/e2e/__tests__/customReportersOnCircus.test.ts @@ -39,4 +39,19 @@ describe('Custom Reporters Integration on jest-circus', () => { expect(stdout).toMatchSnapshot(); }); + + test('push test case results for todo tests', () => { + const {stdout} = runJest('custom-reporters', [ + '--config', + JSON.stringify({ + reporters: [ + 'default', + '/reporters/AssertionCountsReporter.js', + ], + }), + 'todo.test.js', + ]); + + expect(stdout).toMatchSnapshot(); + }); }); diff --git a/e2e/custom-reporters/__tests__/todo.test.js b/e2e/custom-reporters/__tests__/todo.test.js new file mode 100644 index 000000000000..9565e8a040e7 --- /dev/null +++ b/e2e/custom-reporters/__tests__/todo.test.js @@ -0,0 +1,13 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * 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('Custom Reporters', () => { + it.todo('sample'); +});