Skip to content

Commit b444350

Browse files
committed
Add util to create empty test result
1 parent f37fc35 commit b444350

5 files changed

Lines changed: 46 additions & 46 deletions

File tree

e2e/transform/transform-testrunner/test-runner.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
7-
import {Config} from '@jest/types';
87
import {JestEnvironment} from '@jest/environment';
9-
import Runtime from 'jest-runtime';
108
import {TestResult} from '@jest/test-result';
9+
import {Config} from '@jest/types';
10+
import Runtime from 'jest-runtime';
11+
import {emptyTestResult} from 'jest-util';
1112

1213
export default async function testRunner(
1314
globalConfig: Config.GlobalConfig,
@@ -17,28 +18,7 @@ export default async function testRunner(
1718
testPath: string
1819
): Promise<TestResult> {
1920
return {
20-
numFailingTests: 0,
21-
numPassingTests: 1,
22-
numPendingTests: 0,
23-
numTodoTests: 0,
24-
snapshot: {
25-
added: 0,
26-
fileDeleted: false,
27-
matched: 0,
28-
unchecked: 0,
29-
unmatched: 0,
30-
updated: 0,
31-
},
21+
...emptyTestResult(),
3222
testFilePath: testPath,
33-
testResults: [
34-
{
35-
ancestorTitles: [],
36-
duration: 2,
37-
failureMessages: [],
38-
fullName: 'sample test',
39-
status: 'passed',
40-
title: 'sample test',
41-
},
42-
],
43-
} as TestResult;
23+
};
4424
}

packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
addSerializer,
1717
buildSnapshotResolver,
1818
} from 'jest-snapshot';
19+
import {emptyTestResult} from 'jest-util';
1920
import throat from 'throat';
2021
import {
2122
ROOT_DESCRIBE_BLOCK_NAME,
@@ -215,30 +216,14 @@ export const runAndTransformResultsToJestFormat = async ({
215216

216217
dispatch({name: 'teardown'});
217218
return {
219+
...emptyTestResult(),
218220
console: undefined,
219221
displayName: config.displayName,
220222
failureMessage,
221-
leaks: false, // That's legacy code, just adding it so Flow is happy.
222223
numFailingTests,
223224
numPassingTests,
224225
numPendingTests,
225226
numTodoTests,
226-
openHandles: [],
227-
perfStats: {
228-
// populated outside
229-
end: 0,
230-
start: 0,
231-
},
232-
skipped: false,
233-
snapshot: {
234-
added: 0,
235-
fileDeleted: false,
236-
matched: 0,
237-
unchecked: 0,
238-
uncheckedKeys: [],
239-
unmatched: 0,
240-
updated: 0,
241-
},
242227
sourceMaps: {},
243228
testExecError,
244229
testFilePath: testPath,

packages/jest-jasmine2/src/reporter.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import {Config} from '@jest/types';
99
import {AssertionResult, TestResult} from '@jest/test-result';
1010
import {formatResultsErrors} from 'jest-message-util';
11+
import {emptyTestResult} from 'jest-util';
1112
import {SpecResult} from './jasmine/Spec';
1213
import {SuiteResult} from './jasmine/Suite';
1314
import {Reporter, RunDetails} from './types';
@@ -78,6 +79,7 @@ export default class Jasmine2Reporter implements Reporter {
7879
});
7980

8081
const testResult = {
82+
...emptyTestResult(),
8183
console: null,
8284
failureMessage: formatResultsErrors(
8385
testResults,
@@ -89,10 +91,6 @@ export default class Jasmine2Reporter implements Reporter {
8991
numPassingTests,
9092
numPendingTests,
9193
numTodoTests,
92-
perfStats: {
93-
end: 0,
94-
start: 0,
95-
},
9694
snapshot: {
9795
added: 0,
9896
fileDeleted: false,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import {TestResult} from '@jest/test-result';
9+
10+
export default function emptyTestResult(): TestResult {
11+
return {
12+
leaks: false, // That's legacy code, just adding it so Flow is happy.
13+
numFailingTests: 0,
14+
numPassingTests: 0,
15+
numPendingTests: 0,
16+
numTodoTests: 0,
17+
openHandles: [],
18+
perfStats: {
19+
end: 0,
20+
start: 0,
21+
},
22+
skipped: false,
23+
snapshot: {
24+
added: 0,
25+
fileDeleted: false,
26+
matched: 0,
27+
unchecked: 0,
28+
uncheckedKeys: [],
29+
unmatched: 0,
30+
updated: 0,
31+
},
32+
testFilePath: '',
33+
testResults: [],
34+
};
35+
}

packages/jest-util/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import replacePathSepForGlob from './replacePathSepForGlob';
3131
import testPathPatternToRegExp from './testPathPatternToRegExp';
3232
import * as preRunMessage from './preRunMessage';
3333
import pluralize from './pluralize';
34+
import emptyTestResult from './emptyTestResult';
3435

3536
export = {
3637
BufferedConsole,
@@ -42,6 +43,7 @@ export = {
4243
convertDescriptorToString,
4344
createDirectory,
4445
deepCyclicCopy,
46+
emptyTestResult,
4547
formatTestResults,
4648
getCallsite,
4749
getConsoleOutput,

0 commit comments

Comments
 (0)