From c9e2117ff63832c8ad92bbc7b8de63f30ba83b24 Mon Sep 17 00:00:00 2001 From: M4rk9696 Date: Thu, 22 Aug 2019 19:14:41 +0530 Subject: [PATCH 1/5] feat: Add util to create empty testResult --- .../jestAdapterInit.ts | 25 ++++++------------- packages/jest-jasmine2/src/reporter.ts | 7 ++---- packages/jest-test-result/src/helpers.ts | 25 +++++++++++++++++++ packages/jest-test-result/src/index.ts | 1 + 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts index 2380e616dd68..c96ec97e84ad 100644 --- a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts +++ b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts @@ -7,7 +7,12 @@ import {Circus, Config, Global} from '@jest/types'; import {JestEnvironment} from '@jest/environment'; -import {AssertionResult, Status, TestResult} from '@jest/test-result'; +import { + AssertionResult, + Status, + TestResult, + emptyTestResult, +} from '@jest/test-result'; import {extractExpectedAssertionsErrors, getState, setState} from 'expect'; import {formatExecError, formatResultsErrors} from 'jest-message-util'; import { @@ -215,30 +220,14 @@ export const runAndTransformResultsToJestFormat = async ({ dispatch({name: 'teardown'}); return { + ...emptyTestResult(), console: undefined, displayName: config.displayName, failureMessage, - leaks: false, // That's legacy code, just adding it so Flow is happy. numFailingTests, numPassingTests, numPendingTests, numTodoTests, - openHandles: [], - perfStats: { - // populated outside - end: 0, - start: 0, - }, - skipped: false, - snapshot: { - added: 0, - fileDeleted: false, - matched: 0, - unchecked: 0, - uncheckedKeys: [], - unmatched: 0, - updated: 0, - }, sourceMaps: {}, testExecError, testFilePath: testPath, diff --git a/packages/jest-jasmine2/src/reporter.ts b/packages/jest-jasmine2/src/reporter.ts index 7354a8b42208..c5164530f604 100644 --- a/packages/jest-jasmine2/src/reporter.ts +++ b/packages/jest-jasmine2/src/reporter.ts @@ -6,7 +6,7 @@ */ import {Config} from '@jest/types'; -import {AssertionResult, TestResult} from '@jest/test-result'; +import {AssertionResult, TestResult, emptyTestResult} from '@jest/test-result'; import {formatResultsErrors} from 'jest-message-util'; import {SpecResult} from './jasmine/Spec'; import {SuiteResult} from './jasmine/Suite'; @@ -78,6 +78,7 @@ export default class Jasmine2Reporter implements Reporter { }); const testResult = { + ...emptyTestResult(), console: null, failureMessage: formatResultsErrors( testResults, @@ -89,10 +90,6 @@ export default class Jasmine2Reporter implements Reporter { numPassingTests, numPendingTests, numTodoTests, - perfStats: { - end: 0, - start: 0, - }, snapshot: { added: 0, fileDeleted: false, diff --git a/packages/jest-test-result/src/helpers.ts b/packages/jest-test-result/src/helpers.ts index 6020142861bc..02b042379fa5 100644 --- a/packages/jest-test-result/src/helpers.ts +++ b/packages/jest-test-result/src/helpers.ts @@ -145,3 +145,28 @@ export const addResult = ( testResult.snapshot.unmatched + testResult.snapshot.updated; }; + +export const emptyTestResult = (): TestResult => ({ + leaks: false, // That's legacy code, just adding it so Flow is happy. + numFailingTests: 0, + numPassingTests: 0, + numPendingTests: 0, + numTodoTests: 0, + openHandles: [], + perfStats: { + end: 0, + start: 0, + }, + skipped: false, + snapshot: { + added: 0, + fileDeleted: false, + matched: 0, + unchecked: 0, + uncheckedKeys: [], + unmatched: 0, + updated: 0, + }, + testFilePath: '', + testResults: [], +}); diff --git a/packages/jest-test-result/src/index.ts b/packages/jest-test-result/src/index.ts index aa51fb4b4024..c2312954287e 100644 --- a/packages/jest-test-result/src/index.ts +++ b/packages/jest-test-result/src/index.ts @@ -9,6 +9,7 @@ export {default as formatTestResults} from './formatTestResults'; export { addResult, buildFailureTestResult, + emptyTestResult, makeEmptyAggregatedTestResult, } from './helpers'; export { From 270f5e4f6e254aecb7c0faafd47e443cc05da374 Mon Sep 17 00:00:00 2001 From: M4rk9696 Date: Thu, 22 Aug 2019 19:54:10 +0530 Subject: [PATCH 2/5] Rename method and add CHANGELOG Co-Authored-By: Simen Bekkhus --- CHANGELOG.md | 1 + .../src/legacy-code-todo-rewrite/jestAdapterInit.ts | 4 ++-- packages/jest-jasmine2/src/reporter.ts | 4 ++-- packages/jest-test-result/src/helpers.ts | 2 +- packages/jest-test-result/src/index.ts | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2322ac2735e..aff3ad9d7cf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - `[babel-plugin-jest-hoist]` Show codeframe on static hoisting issues ([#8865](https://github.com/facebook/jest/pull/8865)) - `[jest-config]` [**BREAKING**] Set default display name color based on runner ([#8689](https://github.com/facebook/jest/pull/8689)) +- `[@jest/test-result]` Create method to create empty `TestResult` ([#8867](https://github.com/facebook/jest/pull/8867)) ### Fixes diff --git a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts index c96ec97e84ad..0b0f92095ba3 100644 --- a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts +++ b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts @@ -11,7 +11,7 @@ import { AssertionResult, Status, TestResult, - emptyTestResult, + createEmptyTestResult, } from '@jest/test-result'; import {extractExpectedAssertionsErrors, getState, setState} from 'expect'; import {formatExecError, formatResultsErrors} from 'jest-message-util'; @@ -220,7 +220,7 @@ export const runAndTransformResultsToJestFormat = async ({ dispatch({name: 'teardown'}); return { - ...emptyTestResult(), + ...createEmptyTestResult(), console: undefined, displayName: config.displayName, failureMessage, diff --git a/packages/jest-jasmine2/src/reporter.ts b/packages/jest-jasmine2/src/reporter.ts index c5164530f604..e152ba1eae37 100644 --- a/packages/jest-jasmine2/src/reporter.ts +++ b/packages/jest-jasmine2/src/reporter.ts @@ -6,7 +6,7 @@ */ import {Config} from '@jest/types'; -import {AssertionResult, TestResult, emptyTestResult} from '@jest/test-result'; +import {AssertionResult, TestResult, createEmptyTestResult} from '@jest/test-result'; import {formatResultsErrors} from 'jest-message-util'; import {SpecResult} from './jasmine/Spec'; import {SuiteResult} from './jasmine/Suite'; @@ -78,7 +78,7 @@ export default class Jasmine2Reporter implements Reporter { }); const testResult = { - ...emptyTestResult(), + ...createEmptyTestResult(), console: null, failureMessage: formatResultsErrors( testResults, diff --git a/packages/jest-test-result/src/helpers.ts b/packages/jest-test-result/src/helpers.ts index 02b042379fa5..1048e845e340 100644 --- a/packages/jest-test-result/src/helpers.ts +++ b/packages/jest-test-result/src/helpers.ts @@ -146,7 +146,7 @@ export const addResult = ( testResult.snapshot.updated; }; -export const emptyTestResult = (): TestResult => ({ +export const createEmptyTestResult = (): TestResult => ({ leaks: false, // That's legacy code, just adding it so Flow is happy. numFailingTests: 0, numPassingTests: 0, diff --git a/packages/jest-test-result/src/index.ts b/packages/jest-test-result/src/index.ts index c2312954287e..d942f144e519 100644 --- a/packages/jest-test-result/src/index.ts +++ b/packages/jest-test-result/src/index.ts @@ -9,7 +9,7 @@ export {default as formatTestResults} from './formatTestResults'; export { addResult, buildFailureTestResult, - emptyTestResult, + createEmptyTestResult, makeEmptyAggregatedTestResult, } from './helpers'; export { From 9a1a065cb8647d94ba446e4e79fe16dba361a04b Mon Sep 17 00:00:00 2001 From: M4rk9696 Date: Thu, 22 Aug 2019 19:58:29 +0530 Subject: [PATCH 3/5] Remove comment --- packages/jest-test-result/src/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-test-result/src/helpers.ts b/packages/jest-test-result/src/helpers.ts index 1048e845e340..a088afc948d0 100644 --- a/packages/jest-test-result/src/helpers.ts +++ b/packages/jest-test-result/src/helpers.ts @@ -147,7 +147,7 @@ export const addResult = ( }; export const createEmptyTestResult = (): TestResult => ({ - leaks: false, // That's legacy code, just adding it so Flow is happy. + leaks: false, numFailingTests: 0, numPassingTests: 0, numPendingTests: 0, From 32441fcfd401603542ab7e2cb63f948b1b9aa29d Mon Sep 17 00:00:00 2001 From: M4rk9696 Date: Thu, 22 Aug 2019 20:01:25 +0530 Subject: [PATCH 4/5] Readd comment on leaks --- packages/jest-test-result/src/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-test-result/src/helpers.ts b/packages/jest-test-result/src/helpers.ts index a088afc948d0..07bc0e6e2226 100644 --- a/packages/jest-test-result/src/helpers.ts +++ b/packages/jest-test-result/src/helpers.ts @@ -147,7 +147,7 @@ export const addResult = ( }; export const createEmptyTestResult = (): TestResult => ({ - leaks: false, + leaks: false, // That's legacy code, just adding it as needed for typing numFailingTests: 0, numPassingTests: 0, numPendingTests: 0, From ed1b9497114333e154b995da670a3c13649369a7 Mon Sep 17 00:00:00 2001 From: M4rk9696 Date: Thu, 22 Aug 2019 20:21:48 +0530 Subject: [PATCH 5/5] fix missing lint --- packages/jest-jasmine2/src/reporter.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/jest-jasmine2/src/reporter.ts b/packages/jest-jasmine2/src/reporter.ts index e152ba1eae37..7970c045a738 100644 --- a/packages/jest-jasmine2/src/reporter.ts +++ b/packages/jest-jasmine2/src/reporter.ts @@ -6,7 +6,11 @@ */ import {Config} from '@jest/types'; -import {AssertionResult, TestResult, createEmptyTestResult} from '@jest/test-result'; +import { + AssertionResult, + TestResult, + createEmptyTestResult, +} from '@jest/test-result'; import {formatResultsErrors} from 'jest-message-util'; import {SpecResult} from './jasmine/Spec'; import {SuiteResult} from './jasmine/Suite';