diff --git a/e2e/transform/transform-testrunner/test-runner.ts b/e2e/transform/transform-testrunner/test-runner.ts index cf51aa5454dc..e16d30de5630 100644 --- a/e2e/transform/transform-testrunner/test-runner.ts +++ b/e2e/transform/transform-testrunner/test-runner.ts @@ -4,10 +4,11 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -import {Config} from '@jest/types'; import {JestEnvironment} from '@jest/environment'; -import Runtime from 'jest-runtime'; import {TestResult} from '@jest/test-result'; +import {Config} from '@jest/types'; +import Runtime from 'jest-runtime'; +import {emptyTestResult} from 'jest-util'; export default async function testRunner( globalConfig: Config.GlobalConfig, @@ -17,28 +18,7 @@ export default async function testRunner( testPath: string ): Promise { return { - numFailingTests: 0, - numPassingTests: 1, - numPendingTests: 0, - numTodoTests: 0, - snapshot: { - added: 0, - fileDeleted: false, - matched: 0, - unchecked: 0, - unmatched: 0, - updated: 0, - }, + ...emptyTestResult(), testFilePath: testPath, - testResults: [ - { - ancestorTitles: [], - duration: 2, - failureMessages: [], - fullName: 'sample test', - status: 'passed', - title: 'sample test', - }, - ], - } as TestResult; + }; } 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..d56408186d3f 100644 --- a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts +++ b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts @@ -16,6 +16,7 @@ import { addSerializer, buildSnapshotResolver, } from 'jest-snapshot'; +import {emptyTestResult} from 'jest-util'; import throat from 'throat'; import { ROOT_DESCRIBE_BLOCK_NAME, @@ -215,30 +216,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..eeee0b71185e 100644 --- a/packages/jest-jasmine2/src/reporter.ts +++ b/packages/jest-jasmine2/src/reporter.ts @@ -8,6 +8,7 @@ import {Config} from '@jest/types'; import {AssertionResult, TestResult} from '@jest/test-result'; import {formatResultsErrors} from 'jest-message-util'; +import {emptyTestResult} from 'jest-util'; import {SpecResult} from './jasmine/Spec'; import {SuiteResult} from './jasmine/Suite'; import {Reporter, RunDetails} from './types'; @@ -78,6 +79,7 @@ export default class Jasmine2Reporter implements Reporter { }); const testResult = { + ...emptyTestResult(), console: null, failureMessage: formatResultsErrors( testResults, @@ -89,10 +91,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-util/src/emptyTestResult.ts b/packages/jest-util/src/emptyTestResult.ts new file mode 100644 index 000000000000..f77a315fc99a --- /dev/null +++ b/packages/jest-util/src/emptyTestResult.ts @@ -0,0 +1,35 @@ +/** + * 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. + */ + +import {TestResult} from '@jest/test-result'; + +export default function emptyTestResult(): TestResult { + return { + 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-util/src/index.ts b/packages/jest-util/src/index.ts index 6f1f6cf92d19..b823341fe984 100644 --- a/packages/jest-util/src/index.ts +++ b/packages/jest-util/src/index.ts @@ -31,6 +31,7 @@ import replacePathSepForGlob from './replacePathSepForGlob'; import testPathPatternToRegExp from './testPathPatternToRegExp'; import * as preRunMessage from './preRunMessage'; import pluralize from './pluralize'; +import emptyTestResult from './emptyTestResult'; export = { BufferedConsole, @@ -42,6 +43,7 @@ export = { convertDescriptorToString, createDirectory, deepCyclicCopy, + emptyTestResult, formatTestResults, getCallsite, getConsoleOutput,