From 37656ec591cf83bdede01b4f22692c17aa4d5967 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 2 Apr 2020 12:20:03 +0200 Subject: [PATCH] chore: extract `AssertionResult` from `@jest/test-result` (#9749) --- CHANGELOG.md | 1 + packages/jest-message-util/package.json | 1 - packages/jest-message-util/src/index.ts | 9 ++--- packages/jest-message-util/tsconfig.json | 5 +-- packages/jest-test-result/src/types.ts | 49 ++++++------------------ packages/jest-types/src/TestResult.ts | 35 +++++++++++++++++ packages/jest-types/src/index.ts | 3 +- 7 files changed, 54 insertions(+), 49 deletions(-) create mode 100644 packages/jest-types/src/TestResult.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f948ef1d1b0a..efe999892353 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/packages/jest-message-util/package.json b/packages/jest-message-util/package.json index b72bc731e40a..81ad448a80c1 100644 --- a/packages/jest-message-util/package.json +++ b/packages/jest-message-util/package.json @@ -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", diff --git a/packages/jest-message-util/src/index.ts b/packages/jest-message-util/src/index.ts index d46f75ffd0ac..e515dcea6ab3 100644 --- a/packages/jest-message-util/src/index.ts +++ b/packages/jest-message-util/src/index.ts @@ -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'); @@ -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, @@ -313,11 +312,11 @@ export const formatStackTrace = ( type FailedResults = Array<{ content: string; - result: AssertionResult; + result: TestResult.AssertionResult; }>; export const formatResultsErrors = ( - testResults: Array, + testResults: Array, config: StackTraceConfig, options: StackTraceOptions, testPath?: Path, diff --git a/packages/jest-message-util/tsconfig.json b/packages/jest-message-util/tsconfig.json index b3bd807e718d..3046cb6b9b6a 100644 --- a/packages/jest-message-util/tsconfig.json +++ b/packages/jest-message-util/tsconfig.json @@ -4,8 +4,5 @@ "rootDir": "src", "outDir": "build" }, - "references": [ - {"path": "../jest-test-result"}, - {"path": "../jest-types"} - ] + "references": [{"path": "../jest-types"}] } diff --git a/packages/jest-test-result/src/types.ts b/packages/jest-test-result/src/types.ts index 9ed0a99a5439..304b358c143b 100644 --- a/packages/jest-test-result/src/types.ts +++ b/packages/jest-test-result/src/types.ts @@ -7,7 +7,7 @@ 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<{ @@ -15,12 +15,7 @@ export type V8CoverageResult = Array<{ 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; @@ -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; - duration?: Milliseconds | null | undefined; - failureMessages: Array; - fullName: string; - invocations?: number; - location: Callsite | null | undefined; - numPassingAsserts: number; - status: Status; - title: string; -}; +export type AssertionResult = TestResult.AssertionResult; -export type FormattedAssertionResult = { - ancestorTitles: Array; - failureMessages: Array | 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 = { @@ -135,7 +108,7 @@ export type TestResult = { [sourcePath: string]: string; }; testExecError?: SerializableError; - testFilePath: string; + testFilePath: Config.Path; testResults: Array; v8Coverage?: V8CoverageResult; }; diff --git a/packages/jest-types/src/TestResult.ts b/packages/jest-types/src/TestResult.ts new file mode 100644 index 000000000000..7b2c16b47b86 --- /dev/null +++ b/packages/jest-types/src/TestResult.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. + */ + +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; + duration?: Milliseconds | null; + failureMessages: Array; + 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; +}; diff --git a/packages/jest-types/src/index.ts b/packages/jest-types/src/index.ts index 7e8989407731..8255474b61ba 100644 --- a/packages/jest-types/src/index.ts +++ b/packages/jest-types/src/index.ts @@ -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};