Skip to content

Commit

Permalink
Add util to create empty test result
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark1626 committed Aug 19, 2019
1 parent f37fc35 commit b444350
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 46 deletions.
30 changes: 5 additions & 25 deletions e2e/transform/transform-testrunner/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,28 +18,7 @@ export default async function testRunner(
testPath: string
): Promise<TestResult> {
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;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
addSerializer,
buildSnapshotResolver,
} from 'jest-snapshot';
import {emptyTestResult} from 'jest-util';
import throat from 'throat';
import {
ROOT_DESCRIBE_BLOCK_NAME,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions packages/jest-jasmine2/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -78,6 +79,7 @@ export default class Jasmine2Reporter implements Reporter {
});

const testResult = {
...emptyTestResult(),
console: null,
failureMessage: formatResultsErrors(
testResults,
Expand All @@ -89,10 +91,6 @@ export default class Jasmine2Reporter implements Reporter {
numPassingTests,
numPendingTests,
numTodoTests,
perfStats: {
end: 0,
start: 0,
},
snapshot: {
added: 0,
fileDeleted: false,
Expand Down
35 changes: 35 additions & 0 deletions packages/jest-util/src/emptyTestResult.ts
Original file line number Diff line number Diff line change
@@ -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: [],
};
}
2 changes: 2 additions & 0 deletions packages/jest-util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,6 +43,7 @@ export = {
convertDescriptorToString,
createDirectory,
deepCyclicCopy,
emptyTestResult,
formatTestResults,
getCallsite,
getConsoleOutput,
Expand Down

0 comments on commit b444350

Please sign in to comment.