Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: extract AssertionResult from @jest/test-result #9749

Merged
merged 3 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Chore & Maintenance

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

Expand Down
1 change: 0 additions & 1 deletion packages/jest-message-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
},
"dependencies": {
"@babel/code-frame": "^7.0.0",
"@jest/test-result": "^25.2.4",
"@jest/types": "^25.2.3",
"@types/stack-utils": "^1.0.1",
"chalk": "^3.0.0",
Expand Down
9 changes: 4 additions & 5 deletions packages/jest-message-util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

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

type FailedResults = Array<{
content: string;
result: AssertionResult;
result: TestResult.AssertionResult;
}>;

export const formatResultsErrors = (
testResults: Array<AssertionResult>,
testResults: Array<TestResult.AssertionResult>,
config: StackTraceConfig,
options: StackTraceOptions,
testPath?: Path,
Expand Down
5 changes: 1 addition & 4 deletions packages/jest-message-util/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
"rootDir": "src",
"outDir": "build"
},
"references": [
{"path": "../jest-test-result"},
{"path": "../jest-types"}
]
"references": [{"path": "../jest-types"}]
}
49 changes: 11 additions & 38 deletions packages/jest-test-result/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@

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

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

export type SerializableError = {
code?: unknown;
message: string;
stack: string | null | undefined;
type?: string;
};
export type SerializableError = TestResult.SerializableError;

export type FailedAssertion = {
matcherName?: string;
Expand All @@ -39,41 +34,19 @@ export type AssertionLocation = {
path: string;
};

export type Status =
| 'passed'
| 'failed'
| 'skipped'
| 'pending'
| 'todo'
| 'disabled';
export type Status = AssertionResult['status'];

export type Bytes = number;

export type Milliseconds = number;
type Callsite = {
column: number;
line: number;
};
export type Milliseconds = TestResult.Milliseconds;

export type AssertionResult = {
ancestorTitles: Array<string>;
duration?: Milliseconds | null | undefined;
failureMessages: Array<string>;
fullName: string;
invocations?: number;
location: Callsite | null | undefined;
numPassingAsserts: number;
status: Status;
title: string;
};
export type AssertionResult = TestResult.AssertionResult;

export type FormattedAssertionResult = {
ancestorTitles: Array<string>;
failureMessages: Array<string> | null;
fullName: string;
location: Callsite | null | undefined;
status: Status;
title: string;
export type FormattedAssertionResult = Pick<
AssertionResult,
'ancestorTitles' | 'fullName' | 'location' | 'status' | 'title'
> & {
failureMessages: AssertionResult['failureMessages'] | null;
};

export type AggregatedResultWithoutCoverage = {
Expand Down Expand Up @@ -135,7 +108,7 @@ export type TestResult = {
[sourcePath: string]: string;
};
testExecError?: SerializableError;
testFilePath: string;
testFilePath: Config.Path;
testResults: Array<AssertionResult>;
v8Coverage?: V8CoverageResult;
};
Expand Down
35 changes: 35 additions & 0 deletions packages/jest-types/src/TestResult.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.
*/

export type Milliseconds = number;

type Status = 'passed' | 'failed' | 'skipped' | 'pending' | 'todo' | 'disabled';

type Callsite = {
column: number;
line: number;
};

// this is here to make it possible to avoid huge dependency trees just for types
export type AssertionResult = {
ancestorTitles: Array<string>;
duration?: Milliseconds | null;
failureMessages: Array<string>;
fullName: string;
invocations?: number;
location?: Callsite | null;
numPassingAsserts: number;
status: Status;
title: string;
};

export type SerializableError = {
code?: unknown;
message: string;
stack: string | null | undefined;
type?: string;
};
3 changes: 2 additions & 1 deletion packages/jest-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import type * as Circus from './Circus';
import type * as Config from './Config';
import type * as Global from './Global';
import type * as TestResult from './TestResult';
import type * as TransformTypes from './Transform';

export type {Circus, Config, Global, TransformTypes};
export type {Circus, Config, Global, TestResult, TransformTypes};