Skip to content

Commit 37656ec

Browse files
authored
chore: extract AssertionResult from @jest/test-result (#9749)
1 parent c32f498 commit 37656ec

File tree

7 files changed

+54
-49
lines changed

7 files changed

+54
-49
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Chore & Maintenance
88

99
- `[docs]` Update link to watchman troubleshooting docs ([#9727](https://github.com/facebook/jest/pull/9727))
10+
- `[@jest/message-util]` Remove dependency on `@jest/test-result`, which lead to a sprawling dependency tree ([#9749](https://github.com/facebook/jest/pull/9749))
1011
- `[@jest/test-result]` Remove dependency on `@jest/transform`, which lead to a sprawling dependency tree ([#9747](https://github.com/facebook/jest/pull/9747))
1112
- `[@jest/transform]` Expose type `TransformedSource` ([#9736](https://github.com/facebook/jest/pull/9736))
1213

packages/jest-message-util/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
},
2222
"dependencies": {
2323
"@babel/code-frame": "^7.0.0",
24-
"@jest/test-result": "^25.2.4",
2524
"@jest/types": "^25.2.3",
2625
"@types/stack-utils": "^1.0.1",
2726
"chalk": "^3.0.0",

packages/jest-message-util/src/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
import * as fs from 'fs';
99
import * as path from 'path';
10-
import type {Config} from '@jest/types';
11-
import type {AssertionResult, SerializableError} from '@jest/test-result';
10+
import type {Config, TestResult} from '@jest/types';
1211
import chalk = require('chalk');
1312
import micromatch = require('micromatch');
1413
import slash = require('slash');
@@ -120,7 +119,7 @@ function warnAboutWrongTestEnvironment(error: string, env: 'jsdom' | 'node') {
120119
// `before/after each` hooks). If it's thrown, none of the tests in the file
121120
// are executed.
122121
export const formatExecError = (
123-
error: Error | SerializableError | string | undefined,
122+
error: Error | TestResult.SerializableError | string | undefined,
124123
config: StackTraceConfig,
125124
options: StackTraceOptions,
126125
testPath?: Path,
@@ -313,11 +312,11 @@ export const formatStackTrace = (
313312

314313
type FailedResults = Array<{
315314
content: string;
316-
result: AssertionResult;
315+
result: TestResult.AssertionResult;
317316
}>;
318317

319318
export const formatResultsErrors = (
320-
testResults: Array<AssertionResult>,
319+
testResults: Array<TestResult.AssertionResult>,
321320
config: StackTraceConfig,
322321
options: StackTraceOptions,
323322
testPath?: Path,

packages/jest-message-util/tsconfig.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44
"rootDir": "src",
55
"outDir": "build"
66
},
7-
"references": [
8-
{"path": "../jest-test-result"},
9-
{"path": "../jest-types"}
10-
]
7+
"references": [{"path": "../jest-types"}]
118
}

packages/jest-test-result/src/types.ts

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@
77

88
import type {CoverageMap, CoverageMapData} from 'istanbul-lib-coverage';
99
import type {ConsoleBuffer} from '@jest/console';
10-
import type {Config, TransformTypes} from '@jest/types';
10+
import type {Config, TestResult, TransformTypes} from '@jest/types';
1111
import type {V8Coverage} from 'collect-v8-coverage';
1212

1313
export type V8CoverageResult = Array<{
1414
codeTransformResult: TransformTypes.TransformResult | undefined;
1515
result: V8Coverage[number];
1616
}>;
1717

18-
export type SerializableError = {
19-
code?: unknown;
20-
message: string;
21-
stack: string | null | undefined;
22-
type?: string;
23-
};
18+
export type SerializableError = TestResult.SerializableError;
2419

2520
export type FailedAssertion = {
2621
matcherName?: string;
@@ -39,41 +34,19 @@ export type AssertionLocation = {
3934
path: string;
4035
};
4136

42-
export type Status =
43-
| 'passed'
44-
| 'failed'
45-
| 'skipped'
46-
| 'pending'
47-
| 'todo'
48-
| 'disabled';
37+
export type Status = AssertionResult['status'];
4938

5039
export type Bytes = number;
5140

52-
export type Milliseconds = number;
53-
type Callsite = {
54-
column: number;
55-
line: number;
56-
};
41+
export type Milliseconds = TestResult.Milliseconds;
5742

58-
export type AssertionResult = {
59-
ancestorTitles: Array<string>;
60-
duration?: Milliseconds | null | undefined;
61-
failureMessages: Array<string>;
62-
fullName: string;
63-
invocations?: number;
64-
location: Callsite | null | undefined;
65-
numPassingAsserts: number;
66-
status: Status;
67-
title: string;
68-
};
43+
export type AssertionResult = TestResult.AssertionResult;
6944

70-
export type FormattedAssertionResult = {
71-
ancestorTitles: Array<string>;
72-
failureMessages: Array<string> | null;
73-
fullName: string;
74-
location: Callsite | null | undefined;
75-
status: Status;
76-
title: string;
45+
export type FormattedAssertionResult = Pick<
46+
AssertionResult,
47+
'ancestorTitles' | 'fullName' | 'location' | 'status' | 'title'
48+
> & {
49+
failureMessages: AssertionResult['failureMessages'] | null;
7750
};
7851

7952
export type AggregatedResultWithoutCoverage = {
@@ -135,7 +108,7 @@ export type TestResult = {
135108
[sourcePath: string]: string;
136109
};
137110
testExecError?: SerializableError;
138-
testFilePath: string;
111+
testFilePath: Config.Path;
139112
testResults: Array<AssertionResult>;
140113
v8Coverage?: V8CoverageResult;
141114
};
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+
export type Milliseconds = number;
9+
10+
type Status = 'passed' | 'failed' | 'skipped' | 'pending' | 'todo' | 'disabled';
11+
12+
type Callsite = {
13+
column: number;
14+
line: number;
15+
};
16+
17+
// this is here to make it possible to avoid huge dependency trees just for types
18+
export type AssertionResult = {
19+
ancestorTitles: Array<string>;
20+
duration?: Milliseconds | null;
21+
failureMessages: Array<string>;
22+
fullName: string;
23+
invocations?: number;
24+
location?: Callsite | null;
25+
numPassingAsserts: number;
26+
status: Status;
27+
title: string;
28+
};
29+
30+
export type SerializableError = {
31+
code?: unknown;
32+
message: string;
33+
stack: string | null | undefined;
34+
type?: string;
35+
};

packages/jest-types/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import type * as Circus from './Circus';
99
import type * as Config from './Config';
1010
import type * as Global from './Global';
11+
import type * as TestResult from './TestResult';
1112
import type * as TransformTypes from './Transform';
1213

13-
export type {Circus, Config, Global, TransformTypes};
14+
export type {Circus, Config, Global, TestResult, TransformTypes};

0 commit comments

Comments
 (0)