diff --git a/CHANGELOG.md b/CHANGELOG.md index 8736f4bb5946..cb1680c858d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ - `[@jest/core]`: Migrate to TypeScript ([#7998](https://github.com/facebook/jest/pull/7998)) - `[@jest/source-map]`: Extract `getCallsite` function from `jest-util` into a new separate package ([#8029](https://github.com/facebook/jest/pull/8029)) - `[@jest/console]`: Extract custom `console` implementations from `jest-util` into a new separate package ([#8030](https://github.com/facebook/jest/pull/8030)) +- `[@jest/test-result]`: Extract TestResult types and helpers into a new separate package ([#8034](https://github.com/facebook/jest/pull/8034)) ### Performance diff --git a/packages/jest-circus/package.json b/packages/jest-circus/package.json index 900ef052e55a..cefebb02d651 100644 --- a/packages/jest-circus/package.json +++ b/packages/jest-circus/package.json @@ -12,6 +12,7 @@ "dependencies": { "@babel/traverse": "^7.1.0", "@jest/environment": "^24.1.0", + "@jest/test-result": "^24.1.0", "@jest/types": "^24.1.0", "@types/node": "*", "chalk": "^2.0.1", diff --git a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts index 7ad289942726..ca365a5af51e 100644 --- a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts +++ b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts @@ -6,8 +6,9 @@ */ import path from 'path'; -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; import {JestEnvironment} from '@jest/environment'; +import {TestResult} from '@jest/test-result'; // eslint-disable-next-line import/no-extraneous-dependencies import Runtime from 'jest-runtime'; import {SnapshotState} from 'jest-snapshot'; @@ -20,7 +21,7 @@ const jestAdapter = async ( environment: JestEnvironment, runtime: Runtime, testPath: string, -): Promise => { +): Promise => { const { initialize, runAndTransformResultsToJestFormat, @@ -86,7 +87,7 @@ const jestAdapter = async ( }; const _addSnapshotData = ( - results: TestResult.TestResult, + results: TestResult, // TODO: make just snapshotState: SnapshotState when `jest-snapshot` is ESM snapshotState: typeof SnapshotState.prototype, ) => { diff --git a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts index 577a5e94431c..f3ba05efcddd 100644 --- a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts +++ b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {Config, TestResult} from '@jest/types'; - +import {Config} from '@jest/types'; +import {AssertionResult, Status, TestResult} from '@jest/test-result'; import {extractExpectedAssertionsErrors, getState, setState} from 'expect'; import {formatExecError, formatResultsErrors} from 'jest-message-util'; import { @@ -127,7 +127,7 @@ export const runAndTransformResultsToJestFormat = async ({ config: Config.ProjectConfig; globalConfig: Config.GlobalConfig; testPath: string; -}): Promise => { +}): Promise => { const runResult: RunResult = await run(); let numFailingTests = 0; @@ -135,43 +135,43 @@ export const runAndTransformResultsToJestFormat = async ({ let numPendingTests = 0; let numTodoTests = 0; - const assertionResults: Array< - TestResult.AssertionResult - > = runResult.testResults.map(testResult => { - let status: TestResult.Status; - if (testResult.status === 'skip') { - status = 'pending'; - numPendingTests += 1; - } else if (testResult.status === 'todo') { - status = 'todo'; - numTodoTests += 1; - } else if (testResult.errors.length) { - status = 'failed'; - numFailingTests += 1; - } else { - status = 'passed'; - numPassingTests += 1; - } + const assertionResults: Array = runResult.testResults.map( + testResult => { + let status: Status; + if (testResult.status === 'skip') { + status = 'pending'; + numPendingTests += 1; + } else if (testResult.status === 'todo') { + status = 'todo'; + numTodoTests += 1; + } else if (testResult.errors.length) { + status = 'failed'; + numFailingTests += 1; + } else { + status = 'passed'; + numPassingTests += 1; + } - const ancestorTitles = testResult.testPath.filter( - name => name !== ROOT_DESCRIBE_BLOCK_NAME, - ); - const title = ancestorTitles.pop(); + const ancestorTitles = testResult.testPath.filter( + name => name !== ROOT_DESCRIBE_BLOCK_NAME, + ); + const title = ancestorTitles.pop(); - return { - ancestorTitles, - duration: testResult.duration, - failureMessages: testResult.errors, - fullName: title - ? ancestorTitles.concat(title).join(' ') - : ancestorTitles.join(' '), - invocations: testResult.invocations, - location: testResult.location, - numPassingAsserts: 0, - status, - title: testResult.testPath[testResult.testPath.length - 1], - }; - }); + return { + ancestorTitles, + duration: testResult.duration, + failureMessages: testResult.errors, + fullName: title + ? ancestorTitles.concat(title).join(' ') + : ancestorTitles.join(' '), + invocations: testResult.invocations, + location: testResult.location, + numPassingAsserts: 0, + status, + title: testResult.testPath[testResult.testPath.length - 1], + }; + }, + ); let failureMessage = formatResultsErrors( assertionResults, diff --git a/packages/jest-circus/tsconfig.json b/packages/jest-circus/tsconfig.json index 979ba4e24667..31de3b50f0a3 100644 --- a/packages/jest-circus/tsconfig.json +++ b/packages/jest-circus/tsconfig.json @@ -11,6 +11,7 @@ {"path": "../jest-message-util"}, {"path": "../jest-runtime"}, {"path": "../jest-snapshot"}, + {"path": "../jest-test-result"}, {"path": "../jest-types"}, {"path": "../jest-util"}, {"path": "../pretty-format"} diff --git a/packages/jest-core/package.json b/packages/jest-core/package.json index 2d3c7f2ac4fd..86e681a3638c 100644 --- a/packages/jest-core/package.json +++ b/packages/jest-core/package.json @@ -8,6 +8,7 @@ "@jest/console": "^24.1.0", "@jest/types": "^24.1.0", "@jest/reporters": "^24.1.0", + "@jest/test-result": "^24.1.0", "@jest/transform": "^24.1.0", "ansi-escapes": "^3.0.0", "chalk": "^2.0.1", diff --git a/packages/jest-core/src/FailedTestsCache.ts b/packages/jest-core/src/FailedTestsCache.ts index f0bb0fde064d..46848927913d 100644 --- a/packages/jest-core/src/FailedTestsCache.ts +++ b/packages/jest-core/src/FailedTestsCache.ts @@ -6,7 +6,8 @@ */ import {Test} from 'jest-runner'; -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {TestResult} from '@jest/test-result'; type TestMap = {[key: string]: {[key: string]: boolean}}; @@ -22,7 +23,7 @@ export default class FailedTestsCache { return tests.filter(testResult => enabledTestsMap[testResult.path]); } - setTestResults(testResults: Array) { + setTestResults(testResults: Array) { this._enabledTestsMap = (testResults || []) .filter(testResult => testResult.numFailingTests) .reduce((suiteMap, testResult) => { diff --git a/packages/jest-core/src/ReporterDispatcher.ts b/packages/jest-core/src/ReporterDispatcher.ts index b36299aa1cb9..b121cece104c 100644 --- a/packages/jest-core/src/ReporterDispatcher.ts +++ b/packages/jest-core/src/ReporterDispatcher.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import {TestResult} from '@jest/types'; +import {AggregatedResult, TestResult} from '@jest/test-result'; import {Test} from 'jest-runner'; import {Context} from 'jest-runtime'; import {Reporter, ReporterOnStartOptions} from './types'; @@ -29,8 +29,8 @@ export default class ReporterDispatcher { async onTestResult( test: Test, - testResult: TestResult.TestResult, - results: TestResult.AggregatedResult, + testResult: TestResult, + results: AggregatedResult, ) { for (const reporter of this._reporters) { reporter.onTestResult && @@ -44,19 +44,13 @@ export default class ReporterDispatcher { } } - async onRunStart( - results: TestResult.AggregatedResult, - options: ReporterOnStartOptions, - ) { + async onRunStart(results: AggregatedResult, options: ReporterOnStartOptions) { for (const reporter of this._reporters) { reporter.onRunStart && (await reporter.onRunStart(results, options)); } } - async onRunComplete( - contexts: Set, - results: TestResult.AggregatedResult, - ) { + async onRunComplete(contexts: Set, results: AggregatedResult) { for (const reporter of this._reporters) { reporter.onRunComplete && (await reporter.onRunComplete(contexts, results)); diff --git a/packages/jest-core/src/SnapshotInteractiveMode.ts b/packages/jest-core/src/SnapshotInteractiveMode.ts index ab09e39c6979..f1a662f99525 100644 --- a/packages/jest-core/src/SnapshotInteractiveMode.ts +++ b/packages/jest-core/src/SnapshotInteractiveMode.ts @@ -8,9 +8,8 @@ import chalk from 'chalk'; import ansiEscapes from 'ansi-escapes'; -import {TestResult} from '@jest/types'; +import {AggregatedResult, AssertionLocation} from '@jest/test-result'; import {KEYS} from 'jest-watcher'; - import {pluralize, specialChars} from 'jest-util'; const {ARROW, CLEAR} = specialChars; @@ -19,10 +18,10 @@ export default class SnapshotInteractiveMode { private _pipe: NodeJS.WritableStream; private _isActive: boolean; private _updateTestRunnerConfig!: ( - assertion: TestResult.AssertionLocation | null, + assertion: AssertionLocation | null, shouldUpdateSnapshot: boolean, ) => unknown; - private _testAssertions!: Array; + private _testAssertions!: Array; private _countPaths!: number; private _skippedNum: number; @@ -205,7 +204,7 @@ export default class SnapshotInteractiveMode { this._run(false); } - updateWithResults(results: TestResult.AggregatedResult) { + updateWithResults(results: AggregatedResult) { const hasSnapshotFailure = !!results.snapshot.failure; if (hasSnapshotFailure) { this._drawUIOverlay(); @@ -228,9 +227,9 @@ export default class SnapshotInteractiveMode { } run( - failedSnapshotTestAssertions: Array, + failedSnapshotTestAssertions: Array, onConfigChange: ( - assertion: TestResult.AssertionLocation | null, + assertion: AssertionLocation | null, shouldUpdateSnapshot: boolean, ) => unknown, ) { diff --git a/packages/jest-core/src/TestNamePatternPrompt.ts b/packages/jest-core/src/TestNamePatternPrompt.ts index fe55aa6caf01..d996e91cf2bf 100644 --- a/packages/jest-core/src/TestNamePatternPrompt.ts +++ b/packages/jest-core/src/TestNamePatternPrompt.ts @@ -12,11 +12,11 @@ import { printPatternCaret, printRestoredPatternCaret, } from 'jest-watcher'; -import {TestResult} from '@jest/types'; +import {TestResult} from '@jest/test-result'; // TODO: Make underscored props `private` export default class TestNamePatternPrompt extends PatternPrompt { - _cachedTestResults: Array; + _cachedTestResults: Array; constructor(pipe: NodeJS.WritableStream, prompt: Prompt) { super(pipe, prompt); @@ -57,7 +57,7 @@ export default class TestNamePatternPrompt extends PatternPrompt { return matchedTests; } - updateCachedTestResults(testResults: Array = []) { + updateCachedTestResults(testResults: Array = []) { this._cachedTestResults = testResults; } } diff --git a/packages/jest-core/src/TestScheduler.ts b/packages/jest-core/src/TestScheduler.ts index 737241fd4d4b..42b183706152 100644 --- a/packages/jest-core/src/TestScheduler.ts +++ b/packages/jest-core/src/TestScheduler.ts @@ -7,7 +7,7 @@ import chalk from 'chalk'; import {formatExecError} from 'jest-message-util'; -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; import snapshot from 'jest-snapshot'; import TestRunner, {Test} from 'jest-runner'; import {Context} from 'jest-runtime'; @@ -22,9 +22,12 @@ import { import exit from 'exit'; import { addResult, + AggregatedResult, buildFailureTestResult, makeEmptyAggregatedTestResult, -} from './testResultHelpers'; + SerializableError, + TestResult, +} from '@jest/test-result'; import ReporterDispatcher from './ReporterDispatcher'; import TestWatcher from './TestWatcher'; import {shouldRunInBand} from './testSchedulerHelper'; @@ -91,7 +94,7 @@ export default class TestScheduler { timings, ); - const onResult = async (test: Test, testResult: TestResult.TestResult) => { + const onResult = async (test: Test, testResult: TestResult) => { if (watcher.isInterrupted()) { return Promise.resolve(); } @@ -127,10 +130,7 @@ export default class TestScheduler { return this._bailIfNeeded(contexts, aggregatedResults, watcher); }; - const onFailure = async ( - test: Test, - error: TestResult.SerializableError, - ) => { + const onFailure = async (test: Test, error: SerializableError) => { if (watcher.isInterrupted()) { return; } @@ -346,7 +346,7 @@ export default class TestScheduler { private _bailIfNeeded( contexts: Set, - aggregatedResults: TestResult.AggregatedResult, + aggregatedResults: AggregatedResult, watcher: TestWatcher, ): Promise { if ( diff --git a/packages/jest-core/src/TestSequencer.ts b/packages/jest-core/src/TestSequencer.ts index 3928d695fb9d..2ab26eed493e 100644 --- a/packages/jest-core/src/TestSequencer.ts +++ b/packages/jest-core/src/TestSequencer.ts @@ -6,7 +6,7 @@ */ import fs from 'fs'; -import {TestResult} from '@jest/types'; +import {AggregatedResult} from '@jest/test-result'; import {getCacheFilePath} from 'jest-haste-map'; import {Context} from 'jest-runtime'; import {Test} from 'jest-runner'; @@ -90,7 +90,7 @@ export default class TestSequencer { }); } - cacheResults(tests: Array, results: TestResult.AggregatedResult) { + cacheResults(tests: Array, results: AggregatedResult) { const map = Object.create(null); tests.forEach(test => (map[test.path] = test)); results.testResults.forEach(testResult => { diff --git a/packages/jest-core/src/cli/index.ts b/packages/jest-core/src/cli/index.ts index 6f7f987791b4..a1dce1db10b9 100644 --- a/packages/jest-core/src/cli/index.ts +++ b/packages/jest-core/src/cli/index.ts @@ -5,7 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {AggregatedResult} from '@jest/test-result'; import {CustomConsole} from '@jest/console'; import {createDirectory, preRunMessage} from 'jest-util'; import {readConfigs} from 'jest-config'; @@ -27,20 +28,20 @@ import logDebugMessages from '../lib/log_debug_messages'; const {print: preRunMessagePrint} = preRunMessage; -type OnCompleteCallback = (results: TestResult.AggregatedResult) => void; +type OnCompleteCallback = (results: AggregatedResult) => void; export const runCLI = async ( argv: Config.Argv, projects: Array, ): Promise<{ - results: TestResult.AggregatedResult; + results: AggregatedResult; globalConfig: Config.GlobalConfig; }> => { const realFs = require('fs'); const fs = require('graceful-fs'); fs.gracefulify(realFs); - let results: TestResult.AggregatedResult | undefined; + let results: AggregatedResult | undefined; // If we output a JSON object, we can't write anything to stdout, since // it'll break the JSON structure and it won't be valid. diff --git a/packages/jest-core/src/plugins/update_snapshots_interactive.ts b/packages/jest-core/src/plugins/update_snapshots_interactive.ts index 29f2cac10bce..2984a6524113 100644 --- a/packages/jest-core/src/plugins/update_snapshots_interactive.ts +++ b/packages/jest-core/src/plugins/update_snapshots_interactive.ts @@ -5,13 +5,14 @@ * LICENSE file in the root directory of this source tree. */ -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {AggregatedResult, AssertionLocation} from '@jest/test-result'; import {BaseWatchPlugin, JestHookSubscriber} from 'jest-watcher'; import SnapshotInteractiveMode from '../SnapshotInteractiveMode'; class UpdateSnapshotInteractivePlugin extends BaseWatchPlugin { private _snapshotInteractiveMode: SnapshotInteractiveMode; - private _failedSnapshotTestAssertions: Array; + private _failedSnapshotTestAssertions: Array; isInternal: true; constructor(options: {stdin: NodeJS.ReadStream; stdout: NodeJS.WriteStream}) { @@ -22,9 +23,9 @@ class UpdateSnapshotInteractivePlugin extends BaseWatchPlugin { } getFailedSnapshotTestAssertions( - testResults: TestResult.AggregatedResult, - ): Array { - const failedTestPaths: Array = []; + testResults: AggregatedResult, + ): Array { + const failedTestPaths: Array = []; if (testResults.numFailedTests === 0 || !testResults.testResults) { return failedTestPaths; } diff --git a/packages/jest-core/src/runJest.ts b/packages/jest-core/src/runJest.ts index 976c27a42f14..1e91cb16ec83 100644 --- a/packages/jest-core/src/runJest.ts +++ b/packages/jest-core/src/runJest.ts @@ -15,14 +15,17 @@ import fs from 'graceful-fs'; import {JestHook, JestHookEmitter} from 'jest-watcher'; import {Context} from 'jest-runtime'; import {Test} from 'jest-runner'; -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import { + AggregatedResult, + makeEmptyAggregatedTestResult, +} from '@jest/test-result'; import {ChangedFiles, ChangedFilesPromise} from 'jest-changed-files'; import getNoTestsFoundMessage from './getNoTestsFoundMessage'; import runGlobalHook from './runGlobalHook'; import SearchSource from './SearchSource'; import TestScheduler, {TestSchedulerContext} from './TestScheduler'; import TestSequencer from './TestSequencer'; -import {makeEmptyAggregatedTestResult} from './testResultHelpers'; import FailedTestsCache from './FailedTestsCache'; import collectNodeHandles from './collectHandles'; import TestWatcher from './TestWatcher'; @@ -68,12 +71,12 @@ type ProcessResultOptions = Pick< 'json' | 'outputFile' | 'testResultsProcessor' > & { collectHandles?: () => Array; - onComplete?: (result: TestResult.AggregatedResult) => void; + onComplete?: (result: AggregatedResult) => void; outputStream: NodeJS.WritableStream; }; const processResults = ( - runResults: TestResult.AggregatedResult, + runResults: AggregatedResult, options: ProcessResultOptions, ) => { const { @@ -134,7 +137,7 @@ export default (async function runJest({ jestHooks?: JestHookEmitter; startRun: (globalConfig: Config.GlobalConfig) => void; changedFilesPromise?: ChangedFilesPromise; - onComplete: (testResults: TestResult.AggregatedResult) => void; + onComplete: (testResults: AggregatedResult) => void; failedTestsCache?: FailedTestsCache; }) { const sequencer = new TestSequencer(); diff --git a/packages/jest-core/src/types.ts b/packages/jest-core/src/types.ts index debd9af8d73a..4b8f6041be27 100644 --- a/packages/jest-core/src/types.ts +++ b/packages/jest-core/src/types.ts @@ -7,7 +7,8 @@ import {Context} from 'jest-runtime'; import {Test} from 'jest-runner'; -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {AggregatedResult, TestResult} from '@jest/test-result'; export type TestRunData = Array<{ context: Context; @@ -48,17 +49,17 @@ export type ReporterOnStartOptions = { export type Reporter = { onTestResult: ( test: Test, - testResult: TestResult.TestResult, - aggregatedResult: TestResult.AggregatedResult, + testResult: TestResult, + aggregatedResult: AggregatedResult, ) => Promise; onRunStart: ( - results: TestResult.AggregatedResult, + results: AggregatedResult, options: ReporterOnStartOptions, ) => Promise; onTestStart: (test: Test) => Promise; onRunComplete: ( contexts: Set, - results: TestResult.AggregatedResult, + results: AggregatedResult, ) => Promise; getLastError: () => Error; }; diff --git a/packages/jest-core/tsconfig.json b/packages/jest-core/tsconfig.json index b235da20ff81..e1662255d97f 100644 --- a/packages/jest-core/tsconfig.json +++ b/packages/jest-core/tsconfig.json @@ -16,6 +16,7 @@ {"path": "../jest-runner"}, {"path": "../jest-runtime"}, {"path": "../jest-snapshot"}, + {"path": "../jest-test-result"}, {"path": "../jest-types"}, {"path": "../jest-transform"}, {"path": "../jest-util"}, diff --git a/packages/jest-message-util/package.json b/packages/jest-message-util/package.json index b733e62d8c82..259c4f243ccd 100644 --- a/packages/jest-message-util/package.json +++ b/packages/jest-message-util/package.json @@ -14,6 +14,7 @@ "types": "build/index.d.ts", "dependencies": { "@babel/code-frame": "^7.0.0", + "@jest/test-result": "^24.1.0", "@jest/types": "^24.1.0", "@types/stack-utils": "^1.0.1", "chalk": "^2.0.1", diff --git a/packages/jest-message-util/src/index.ts b/packages/jest-message-util/src/index.ts index 6535e8e7fee9..01eb438f44dc 100644 --- a/packages/jest-message-util/src/index.ts +++ b/packages/jest-message-util/src/index.ts @@ -7,7 +7,8 @@ import fs from 'fs'; import path from 'path'; -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {AssertionResult, SerializableError} from '@jest/test-result'; import chalk from 'chalk'; import micromatch from 'micromatch'; import slash from 'slash'; @@ -18,13 +19,9 @@ import {Frame} from './types'; export {Frame} from './types'; type Path = Config.Path; -type AssertionResult = TestResult.AssertionResult; -type SerializableError = TestResult.SerializableError; // stack utils tries to create pretty stack by making paths relative. -const stackUtils = new StackUtils({ - cwd: 'something which does not exist', -}); +const stackUtils = new StackUtils({cwd: 'something which does not exist'}); let nodeInternals: Array = []; diff --git a/packages/jest-message-util/tsconfig.json b/packages/jest-message-util/tsconfig.json index b802dbf5ce24..b3bd807e718d 100644 --- a/packages/jest-message-util/tsconfig.json +++ b/packages/jest-message-util/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "build" }, "references": [ + {"path": "../jest-test-result"}, {"path": "../jest-types"} ] } diff --git a/packages/jest-phabricator/package.json b/packages/jest-phabricator/package.json index f1000201d15c..4ca1fdd4e622 100644 --- a/packages/jest-phabricator/package.json +++ b/packages/jest-phabricator/package.json @@ -8,7 +8,7 @@ }, "types": "build/index.d.ts", "dependencies": { - "@jest/types": "^24.1.0" + "@jest/test-result": "^24.1.0" }, "engines": { "node": ">= 6" diff --git a/packages/jest-phabricator/src/index.ts b/packages/jest-phabricator/src/index.ts index f4e6ffbbbe9a..de36344afc5d 100644 --- a/packages/jest-phabricator/src/index.ts +++ b/packages/jest-phabricator/src/index.ts @@ -5,9 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {TestResult} from '@jest/types'; +import {AggregatedResult} from '@jest/test-result'; -type AggregatedResult = TestResult.AggregatedResult; type CoverageMap = AggregatedResult['coverageMap']; function summarize(coverageMap: CoverageMap): CoverageMap { diff --git a/packages/jest-phabricator/tsconfig.json b/packages/jest-phabricator/tsconfig.json index 7a7b7a460af1..ed501699fc79 100644 --- a/packages/jest-phabricator/tsconfig.json +++ b/packages/jest-phabricator/tsconfig.json @@ -6,7 +6,7 @@ }, "references": [ { - "path": "../jest-types" + "path": "../jest-test-result" } ] } diff --git a/packages/jest-reporters/package.json b/packages/jest-reporters/package.json index 39ff7a54f21d..a563c6ca58ad 100644 --- a/packages/jest-reporters/package.json +++ b/packages/jest-reporters/package.json @@ -6,6 +6,7 @@ "types": "build/index.d.ts", "dependencies": { "@jest/environment": "^24.1.0", + "@jest/test-result": "^24.1.0", "@jest/transform": "^24.1.0", "@jest/types": "^24.1.0", "chalk": "^2.0.1", diff --git a/packages/jest-reporters/src/Status.ts b/packages/jest-reporters/src/Status.ts index 099dbe200739..c6a279c48f25 100644 --- a/packages/jest-reporters/src/Status.ts +++ b/packages/jest-reporters/src/Status.ts @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {TestResult, Config} from '@jest/types'; - +import {Config} from '@jest/types'; +import {AggregatedResult, TestResult} from '@jest/test-result'; import chalk from 'chalk'; import stringLength from 'string-length'; import {ReporterOnStartOptions} from './types'; @@ -70,7 +70,7 @@ export default class Status { private _emitScheduled: boolean; private _estimatedTime: number; private _interval?: NodeJS.Timeout; - private _aggregatedResults?: TestResult.AggregatedResult; + private _aggregatedResults?: AggregatedResult; private _showStatus: boolean; constructor() { @@ -87,7 +87,7 @@ export default class Status { } runStarted( - aggregatedResults: TestResult.AggregatedResult, + aggregatedResults: AggregatedResult, options: ReporterOnStartOptions, ) { this._estimatedTime = (options && options.estimatedTime) || 0; @@ -114,8 +114,8 @@ export default class Status { testFinished( _config: Config.ProjectConfig, - testResult: TestResult.TestResult, - aggregatedResults: TestResult.AggregatedResult, + testResult: TestResult, + aggregatedResults: AggregatedResult, ) { const {testFilePath} = testResult; this._aggregatedResults = aggregatedResults; diff --git a/packages/jest-reporters/src/base_reporter.ts b/packages/jest-reporters/src/base_reporter.ts index 36c7c57670b9..5bce49df154e 100644 --- a/packages/jest-reporters/src/base_reporter.ts +++ b/packages/jest-reporters/src/base_reporter.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import {TestResult} from '@jest/types'; +import {AggregatedResult, TestResult} from '@jest/test-result'; import {preRunMessage} from 'jest-util'; import {ReporterOnStartOptions, Context, Test, Reporter} from './types'; @@ -18,24 +18,21 @@ export default class BaseReporter implements Reporter { process.stderr.write(message + '\n'); } - onRunStart( - _results: TestResult.AggregatedResult, - _options: ReporterOnStartOptions, - ) { + onRunStart(_results: AggregatedResult, _options: ReporterOnStartOptions) { preRunMessageRemove(process.stderr); } onTestResult( _test: Test, - _testResult: TestResult.TestResult, - _results: TestResult.AggregatedResult, + _testResult: TestResult, + _results: AggregatedResult, ) {} onTestStart(_test: Test) {} onRunComplete( _contexts: Set, - _aggregatedResults: TestResult.AggregatedResult, + _aggregatedResults: AggregatedResult, ): Promise | void {} protected _setError(error: Error) { diff --git a/packages/jest-reporters/src/coverage_reporter.ts b/packages/jest-reporters/src/coverage_reporter.ts index c3f2004858a0..698abc17e4ff 100644 --- a/packages/jest-reporters/src/coverage_reporter.ts +++ b/packages/jest-reporters/src/coverage_reporter.ts @@ -10,8 +10,8 @@ /// import path from 'path'; -import {TestResult, Config} from '@jest/types'; - +import {Config} from '@jest/types'; +import {AggregatedResult, TestResult} from '@jest/test-result'; import {clearLine, isInteractive} from 'jest-util'; import {createReporter} from 'istanbul-api'; import chalk from 'chalk'; @@ -50,8 +50,8 @@ export default class CoverageReporter extends BaseReporter { onTestResult( _test: Test, - testResult: TestResult.TestResult, - _aggregatedResults: TestResult.AggregatedResult, + testResult: TestResult, + _aggregatedResults: AggregatedResult, ) { if (testResult.coverage) { this._coverageMap.merge(testResult.coverage); @@ -81,7 +81,7 @@ export default class CoverageReporter extends BaseReporter { async onRunComplete( contexts: Set, - aggregatedResults: TestResult.AggregatedResult, + aggregatedResults: AggregatedResult, ) { await this._addUntestedFiles(this._globalConfig, contexts); const {map, sourceFinder} = this._sourceMapStore.transformCoverage( diff --git a/packages/jest-reporters/src/default_reporter.ts b/packages/jest-reporters/src/default_reporter.ts index 686207e1d3ae..664e30d665d7 100644 --- a/packages/jest-reporters/src/default_reporter.ts +++ b/packages/jest-reporters/src/default_reporter.ts @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {TestResult, Config} from '@jest/types'; - +import {Config} from '@jest/types'; +import {AggregatedResult, TestResult} from '@jest/test-result'; import {clearLine, getConsoleOutput, isInteractive} from 'jest-util'; import chalk from 'chalk'; import {Test, ReporterOnStartOptions} from './types'; @@ -119,7 +119,7 @@ export default class DefaultReporter extends BaseReporter { } onRunStart( - aggregatedResults: TestResult.AggregatedResult, + aggregatedResults: AggregatedResult, options: ReporterOnStartOptions, ) { this._status.runStarted(aggregatedResults, options); @@ -139,8 +139,8 @@ export default class DefaultReporter extends BaseReporter { onTestResult( test: Test, - testResult: TestResult.TestResult, - aggregatedResults: TestResult.AggregatedResult, + testResult: TestResult, + aggregatedResults: AggregatedResult, ) { this.testFinished(test.context.config, testResult, aggregatedResults); if (!testResult.skipped) { @@ -160,8 +160,8 @@ export default class DefaultReporter extends BaseReporter { testFinished( config: Config.ProjectConfig, - testResult: TestResult.TestResult, - aggregatedResults: TestResult.AggregatedResult, + testResult: TestResult, + aggregatedResults: AggregatedResult, ) { this._status.testFinished(config, testResult, aggregatedResults); } @@ -169,7 +169,7 @@ export default class DefaultReporter extends BaseReporter { printTestFileHeader( _testPath: Config.Path, config: Config.ProjectConfig, - result: TestResult.TestResult, + result: TestResult, ) { this.log(getResultHeader(result, this._globalConfig, config)); const consoleBuffer = result.console; @@ -190,7 +190,7 @@ export default class DefaultReporter extends BaseReporter { printTestFileFailureMessage( _testPath: Config.Path, _config: Config.ProjectConfig, - result: TestResult.TestResult, + result: TestResult, ) { if (result.failureMessage) { this.log(result.failureMessage); diff --git a/packages/jest-reporters/src/get_result_header.ts b/packages/jest-reporters/src/get_result_header.ts index 43c8b2301d94..4c80809cdce6 100644 --- a/packages/jest-reporters/src/get_result_header.ts +++ b/packages/jest-reporters/src/get_result_header.ts @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {Config, TestResult} from '@jest/types'; - +import {Config} from '@jest/types'; +import {TestResult} from '@jest/test-result'; import chalk from 'chalk'; import {formatTestPath, printDisplayName} from './utils'; @@ -25,7 +25,7 @@ const PASS = chalk.supportsColor : PASS_TEXT; export default ( - result: TestResult.TestResult, + result: TestResult, globalConfig: Config.GlobalConfig, projectConfig?: Config.ProjectConfig, ) => { diff --git a/packages/jest-reporters/src/get_snapshot_status.ts b/packages/jest-reporters/src/get_snapshot_status.ts index 91c4e692eb90..42ea340fe022 100644 --- a/packages/jest-reporters/src/get_snapshot_status.ts +++ b/packages/jest-reporters/src/get_snapshot_status.ts @@ -5,10 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {TestResult} from '@jest/types'; - import chalk from 'chalk'; - +import {TestResult} from '@jest/test-result'; import {pluralize} from 'jest-util'; const ARROW = ' \u203A '; @@ -19,7 +17,7 @@ const SNAPSHOT_UPDATED = chalk.bold.green; const SNAPSHOT_OUTDATED = chalk.bold.yellow; export default ( - snapshot: TestResult.TestResult['snapshot'], + snapshot: TestResult['snapshot'], afterUpdate: boolean, ): Array => { const statuses = []; diff --git a/packages/jest-reporters/src/get_snapshot_summary.ts b/packages/jest-reporters/src/get_snapshot_summary.ts index 19027f821aca..902cb79b7034 100644 --- a/packages/jest-reporters/src/get_snapshot_summary.ts +++ b/packages/jest-reporters/src/get_snapshot_summary.ts @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {Config, TestResult} from '@jest/types'; - +import {Config} from '@jest/types'; +import {SnapshotSummary} from '@jest/test-result'; import chalk from 'chalk'; import {pluralize} from 'jest-util'; import {formatTestPath} from './utils'; @@ -23,7 +23,7 @@ const SNAPSHOT_SUMMARY = chalk.bold; const SNAPSHOT_UPDATED = chalk.bold.green; export default ( - snapshots: TestResult.SnapshotSummary, + snapshots: SnapshotSummary, globalConfig: Config.GlobalConfig, updateCommand: string, ): Array => { diff --git a/packages/jest-reporters/src/notify_reporter.ts b/packages/jest-reporters/src/notify_reporter.ts index b6755b85b25c..460530a6447d 100644 --- a/packages/jest-reporters/src/notify_reporter.ts +++ b/packages/jest-reporters/src/notify_reporter.ts @@ -11,7 +11,8 @@ import path from 'path'; import util from 'util'; import exit from 'exit'; -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {AggregatedResult} from '@jest/test-result'; import notifier from 'node-notifier'; import {TestSchedulerContext, Context} from './types'; import BaseReporter from './base_reporter'; @@ -36,10 +37,7 @@ export default class NotifyReporter extends BaseReporter { this._context = context; } - onRunComplete( - contexts: Set, - result: TestResult.AggregatedResult, - ): void { + onRunComplete(contexts: Set, result: AggregatedResult): void { const success = result.numFailedTests === 0 && result.numRuntimeErrorTestSuites === 0; diff --git a/packages/jest-reporters/src/summary_reporter.ts b/packages/jest-reporters/src/summary_reporter.ts index cf392376c53f..6e60fde4d3ea 100644 --- a/packages/jest-reporters/src/summary_reporter.ts +++ b/packages/jest-reporters/src/summary_reporter.ts @@ -5,7 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {TestResult, Config} from '@jest/types'; +import {Config} from '@jest/types'; +import {AggregatedResult, SnapshotSummary} from '@jest/test-result'; import chalk from 'chalk'; import {testPathPatternToRegExp} from 'jest-util'; import {Context, ReporterOnStartOptions} from './types'; @@ -65,17 +66,14 @@ export default class SummaryReporter extends BaseReporter { } onRunStart( - aggregatedResults: TestResult.AggregatedResult, + aggregatedResults: AggregatedResult, options: ReporterOnStartOptions, ) { super.onRunStart(aggregatedResults, options); this._estimatedTime = options.estimatedTime; } - onRunComplete( - contexts: Set, - aggregatedResults: TestResult.AggregatedResult, - ) { + onRunComplete(contexts: Set, aggregatedResults: AggregatedResult) { const {numTotalTestSuites, testResults, wasInterrupted} = aggregatedResults; if (numTotalTestSuites) { const lastResult = testResults[testResults.length - 1]; @@ -114,7 +112,7 @@ export default class SummaryReporter extends BaseReporter { } private _printSnapshotSummary( - snapshots: TestResult.SnapshotSummary, + snapshots: SnapshotSummary, globalConfig: Config.GlobalConfig, ) { if ( @@ -159,7 +157,7 @@ export default class SummaryReporter extends BaseReporter { } private _printSummary( - aggregatedResults: TestResult.AggregatedResult, + aggregatedResults: AggregatedResult, globalConfig: Config.GlobalConfig, ) { // If there were any failing tests and there was a large number of tests diff --git a/packages/jest-reporters/src/types.ts b/packages/jest-reporters/src/types.ts index cfdde6598abc..9c0270b1c745 100644 --- a/packages/jest-reporters/src/types.ts +++ b/packages/jest-reporters/src/types.ts @@ -5,7 +5,12 @@ * LICENSE file in the root directory of this source tree. */ -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import { + AggregatedResult, + SerializableError, + TestResult, +} from '@jest/test-result'; import {JestEnvironment as Environment} from '@jest/environment'; import {ModuleMap, FS as HasteFS} from 'jest-haste-map'; import HasteResolver from 'jest-resolve'; @@ -39,27 +44,24 @@ export type CoverageReporterOptions = { export type OnTestStart = (test: Test) => Promise; export type OnTestFailure = ( test: Test, - error: TestResult.SerializableError, -) => Promise; -export type OnTestSuccess = ( - test: Test, - result: TestResult.TestResult, + error: SerializableError, ) => Promise; +export type OnTestSuccess = (test: Test, result: TestResult) => Promise; export interface Reporter { readonly onTestResult: ( test: Test, - testResult: TestResult.TestResult, - aggregatedResult: TestResult.AggregatedResult, + testResult: TestResult, + aggregatedResult: AggregatedResult, ) => Promise | void; readonly onRunStart: ( - results: TestResult.AggregatedResult, + results: AggregatedResult, options: ReporterOnStartOptions, ) => Promise | void; readonly onTestStart: (test: Test) => Promise | void; readonly onRunComplete: ( contexts: Set, - results: TestResult.AggregatedResult, + results: AggregatedResult, ) => Promise | void; readonly getLastError: () => Error | void; } @@ -76,7 +78,7 @@ export type TestFramework = ( environment: Environment, runtime: Runtime, testPath: string, -) => Promise; +) => Promise; export type TestRunnerOptions = { serial: boolean; diff --git a/packages/jest-reporters/src/utils.ts b/packages/jest-reporters/src/utils.ts index d078b584fbf0..e4b3c93c876c 100644 --- a/packages/jest-reporters/src/utils.ts +++ b/packages/jest-reporters/src/utils.ts @@ -6,7 +6,8 @@ */ import path from 'path'; -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {AggregatedResult} from '@jest/test-result'; import chalk from 'chalk'; import slash from 'slash'; import {pluralize} from 'jest-util'; @@ -88,7 +89,7 @@ export const relativePath = ( }; export const getSummary = ( - aggregatedResults: TestResult.AggregatedResult, + aggregatedResults: AggregatedResult, options?: SummaryOptions, ) => { let runTime = (Date.now() - aggregatedResults.startTime) / 1000; diff --git a/packages/jest-reporters/src/verbose_reporter.ts b/packages/jest-reporters/src/verbose_reporter.ts index 74ac6794f27c..bc1a22dfa876 100644 --- a/packages/jest-reporters/src/verbose_reporter.ts +++ b/packages/jest-reporters/src/verbose_reporter.ts @@ -5,8 +5,13 @@ * LICENSE file in the root directory of this source tree. */ -import {Config, TestResult} from '@jest/types'; - +import {Config} from '@jest/types'; +import { + AggregatedResult, + AssertionResult, + Suite, + TestResult, +} from '@jest/test-result'; import chalk from 'chalk'; import {specialChars} from 'jest-util'; import {Test} from './types'; @@ -23,13 +28,13 @@ export default class VerboseReporter extends DefaultReporter { } static filterTestResults( - testResults: Array, - ): Array { + testResults: Array, + ): Array { return testResults.filter(({status}) => status !== 'pending'); } - static groupTestsBySuites(testResults: Array) { - const root: TestResult.Suite = {suites: [], tests: [], title: ''}; + static groupTestsBySuites(testResults: Array) { + const root: Suite = {suites: [], tests: [], title: ''}; testResults.forEach(testResult => { let targetSuite = root; @@ -51,8 +56,8 @@ export default class VerboseReporter extends DefaultReporter { onTestResult( test: Test, - result: TestResult.TestResult, - aggregatedResults: TestResult.AggregatedResult, + result: TestResult, + aggregatedResults: AggregatedResult, ) { super.testFinished(test.context.config, result, aggregatedResults); if (!result.skipped) { @@ -73,12 +78,12 @@ export default class VerboseReporter extends DefaultReporter { super.forceFlushBufferedOutput(); } - private _logTestResults(testResults: Array) { + private _logTestResults(testResults: Array) { this._logSuite(VerboseReporter.groupTestsBySuites(testResults), 0); this._logLine(); } - private _logSuite(suite: TestResult.Suite, indentLevel: number) { + private _logSuite(suite: Suite, indentLevel: number) { if (suite.title) { this._logLine(suite.title, indentLevel); } @@ -100,16 +105,13 @@ export default class VerboseReporter extends DefaultReporter { } } - private _logTest(test: TestResult.AssertionResult, indentLevel: number) { + private _logTest(test: AssertionResult, indentLevel: number) { const status = this._getIcon(test.status); const time = test.duration ? ` (${test.duration.toFixed(0)}ms)` : ''; this._logLine(status + ' ' + chalk.dim(test.title + time), indentLevel); } - private _logTests( - tests: Array, - indentLevel: number, - ) { + private _logTests(tests: Array, indentLevel: number) { if (this._globalConfig.expand) { tests.forEach(test => this._logTest(test, indentLevel)); } else { diff --git a/packages/jest-reporters/tsconfig.json b/packages/jest-reporters/tsconfig.json index 5f38de20815b..00dffcebc22f 100644 --- a/packages/jest-reporters/tsconfig.json +++ b/packages/jest-reporters/tsconfig.json @@ -9,6 +9,7 @@ {"path": "../jest-haste-map"}, {"path": "../jest-resolve"}, {"path": "../jest-runtime"}, + {"path": "../jest-test-result"}, {"path": "../jest-types"}, {"path": "../jest-util"}, {"path": "../jest-worker"} diff --git a/packages/jest-runner/package.json b/packages/jest-runner/package.json index eca46c1cfd29..bb95041522cc 100644 --- a/packages/jest-runner/package.json +++ b/packages/jest-runner/package.json @@ -12,6 +12,7 @@ "dependencies": { "@jest/console": "^24.1.0", "@jest/environment": "^24.1.0", + "@jest/test-result": "^24.1.0", "@jest/types": "^24.1.0", "chalk": "^2.4.2", "exit": "^0.1.2", diff --git a/packages/jest-runner/src/index.ts b/packages/jest-runner/src/index.ts index 1fe4c0eee6a8..c18063a3a590 100644 --- a/packages/jest-runner/src/index.ts +++ b/packages/jest-runner/src/index.ts @@ -5,7 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {SerializableError} from '@jest/test-result'; import exit from 'exit'; import throat from 'throat'; import Worker from 'jest-worker'; @@ -135,10 +136,7 @@ class TestRunner { }); }); - const onError = async ( - err: TestResult.SerializableError, - test: JestTest, - ) => { + const onError = async (err: SerializableError, test: JestTest) => { await onFailure(test, err); if (err.type === 'ProcessTerminatedError') { console.error( diff --git a/packages/jest-runner/src/runTest.ts b/packages/jest-runner/src/runTest.ts index ebbae640c6d3..7d15b235af71 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -6,7 +6,8 @@ * */ -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {TestResult} from '@jest/test-result'; import { BufferedConsole, CustomConsole, @@ -32,7 +33,7 @@ import {TestFramework, TestRunnerContext} from './types'; type RunTestInternalResult = { leakDetector: LeakDetector | null; - result: TestResult.TestResult; + result: TestResult; }; function freezeConsole( @@ -223,7 +224,7 @@ async function runTestInternal( try { await environment.setup(); - let result: TestResult.TestResult; + let result: TestResult; try { result = await testFramework( @@ -283,7 +284,7 @@ export default async function runTest( config: Config.ProjectConfig, resolver: Resolver, context?: TestRunnerContext, -): Promise { +): Promise { const {leakDetector, result} = await runTestInternal( path, globalConfig, diff --git a/packages/jest-runner/src/testWorker.ts b/packages/jest-runner/src/testWorker.ts index fed1e1e4a669..3cd4309fb6e7 100644 --- a/packages/jest-runner/src/testWorker.ts +++ b/packages/jest-runner/src/testWorker.ts @@ -6,7 +6,8 @@ * */ -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {SerializableError, TestResult} from '@jest/test-result'; import HasteMap, {SerializableModuleMap, ModuleMap} from 'jest-haste-map'; import exit from 'exit'; import {separateMessageFromStack} from 'jest-message-util'; @@ -28,9 +29,7 @@ process.on('uncaughtException', err => { exit(1); }); -const formatError = ( - error: string | ErrorWithCode, -): TestResult.SerializableError => { +const formatError = (error: string | ErrorWithCode): SerializableError => { if (typeof error === 'string') { const {message, stack} = separateMessageFromStack(error); return { @@ -77,7 +76,7 @@ export async function worker({ path, serializableModuleMap, context, -}: WorkerData): Promise { +}: WorkerData): Promise { try { const moduleMap = serializableModuleMap ? HasteMap.ModuleMap.fromJSON(serializableModuleMap) diff --git a/packages/jest-runner/src/types.ts b/packages/jest-runner/src/types.ts index 78fb71d00d95..7f3aa4a626c8 100644 --- a/packages/jest-runner/src/types.ts +++ b/packages/jest-runner/src/types.ts @@ -6,7 +6,8 @@ */ import {EventEmitter} from 'events'; -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {SerializableError, TestResult} from '@jest/test-result'; import {JestEnvironment} from '@jest/environment'; import {ModuleMap, FS as HasteFS} from 'jest-haste-map'; import HasteResolver from 'jest-resolve'; @@ -29,11 +30,11 @@ export type Context = { export type OnTestStart = (test: Test) => Promise; export type OnTestFailure = ( test: Test, - serializableError: TestResult.SerializableError, + serializableError: SerializableError, ) => Promise; export type OnTestSuccess = ( test: Test, - testResult: TestResult.TestResult, + testResult: TestResult, ) => Promise; export type TestFramework = ( @@ -42,7 +43,7 @@ export type TestFramework = ( environment: JestEnvironment, runtime: Runtime, testPath: string, -) => Promise; +) => Promise; export type TestRunnerOptions = { serial: boolean; diff --git a/packages/jest-runner/tsconfig.json b/packages/jest-runner/tsconfig.json index e541cc3f572c..69c0f3da86e8 100644 --- a/packages/jest-runner/tsconfig.json +++ b/packages/jest-runner/tsconfig.json @@ -14,6 +14,7 @@ {"path": "../jest-message-util"}, {"path": "../jest-resolve"}, {"path": "../jest-runtime"}, + {"path": "../jest-test-result"}, {"path": "../jest-types"}, {"path": "../jest-worker"}, {"path": "../jest-util"} diff --git a/packages/jest-test-result/.npmignore b/packages/jest-test-result/.npmignore new file mode 100644 index 000000000000..85e48fe7b0a4 --- /dev/null +++ b/packages/jest-test-result/.npmignore @@ -0,0 +1,3 @@ +**/__mocks__/** +**/__tests__/** +src diff --git a/packages/jest-test-result/package.json b/packages/jest-test-result/package.json new file mode 100644 index 000000000000..2eafd33afe86 --- /dev/null +++ b/packages/jest-test-result/package.json @@ -0,0 +1,21 @@ +{ + "name": "@jest/test-result", + "version": "24.1.0", + "repository": { + "type": "git", + "url": "https://github.com/facebook/jest.git", + "directory": "packages/jest-test-result" + }, + "license": "MIT", + "main": "build/index.js", + "types": "build/index.d.ts", + "dependencies": { + "@jest/console": "^24.1.0", + "@jest/types": "^24.1.0", + "@types/istanbul-lib-coverage": "^1.1.0" + }, + "engines": { + "node": ">= 6" + }, + "gitHead": "634e5a54f46b2a62d1dc81a170562e6f4e55ad60" +} diff --git a/packages/jest-util/src/__tests__/formatTestResults.test.ts b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts similarity index 90% rename from packages/jest-util/src/__tests__/formatTestResults.test.ts rename to packages/jest-test-result/src/__tests__/formatTestResults.test.ts index 09bd58b9a786..523d79b34d7c 100644 --- a/packages/jest-util/src/__tests__/formatTestResults.test.ts +++ b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {TestResult} from '@jest/types'; import formatTestResults from '../formatTestResults'; +import {AggregatedResult} from '../types'; describe('formatTestResults', () => { const assertion = { @@ -15,7 +15,7 @@ describe('formatTestResults', () => { title: 'returns true', }; - const results: TestResult.AggregatedResult = { + const results: AggregatedResult = { testResults: [ { numFailingTests: 0, diff --git a/packages/jest-util/src/formatTestResults.ts b/packages/jest-test-result/src/formatTestResults.ts similarity index 72% rename from packages/jest-util/src/formatTestResults.ts rename to packages/jest-test-result/src/formatTestResults.ts index 465573a524af..161937b7c1dc 100644 --- a/packages/jest-util/src/formatTestResults.ts +++ b/packages/jest-test-result/src/formatTestResults.ts @@ -5,15 +5,24 @@ * LICENSE file in the root directory of this source tree. */ -import {TestResult} from '@jest/types'; +import { + AggregatedResult, + AssertionResult, + CodeCoverageFormatter, + CodeCoverageReporter, + FormattedAssertionResult, + FormattedTestResult, + FormattedTestResults, + TestResult, +} from './types'; const formatResult = ( - testResult: TestResult.TestResult, - codeCoverageFormatter: TestResult.CodeCoverageFormatter, - reporter: TestResult.CodeCoverageReporter, -): TestResult.FormattedTestResult => { + testResult: TestResult, + codeCoverageFormatter: CodeCoverageFormatter, + reporter: CodeCoverageReporter, +): FormattedTestResult => { const now = Date.now(); - const output: TestResult.FormattedTestResult = { + const output: FormattedTestResult = { assertionResults: [], coverage: {}, endTime: now, @@ -45,9 +54,9 @@ const formatResult = ( }; function formatTestAssertion( - assertion: TestResult.AssertionResult, -): TestResult.FormattedAssertionResult { - const result: TestResult.FormattedAssertionResult = { + assertion: AssertionResult, +): FormattedAssertionResult { + const result: FormattedAssertionResult = { ancestorTitles: assertion.ancestorTitles, failureMessages: null, fullName: assertion.fullName, @@ -62,10 +71,10 @@ function formatTestAssertion( } export default function formatTestResults( - results: TestResult.AggregatedResult, - codeCoverageFormatter?: TestResult.CodeCoverageFormatter | null, - reporter?: TestResult.CodeCoverageReporter, -): TestResult.FormattedTestResults { + results: AggregatedResult, + codeCoverageFormatter?: CodeCoverageFormatter | null, + reporter?: CodeCoverageReporter, +): FormattedTestResults { const formatter = codeCoverageFormatter || (coverage => coverage); const testResults = results.testResults.map(testResult => diff --git a/packages/jest-core/src/testResultHelpers.ts b/packages/jest-test-result/src/helpers.ts similarity index 92% rename from packages/jest-core/src/testResultHelpers.ts rename to packages/jest-test-result/src/helpers.ts index ffbebe101de9..a46f86959945 100644 --- a/packages/jest-core/src/testResultHelpers.ts +++ b/packages/jest-test-result/src/helpers.ts @@ -5,9 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {AggregatedResult, SerializableError, TestResult} from './types'; -export const makeEmptyAggregatedTestResult = (): TestResult.AggregatedResult => ({ +export const makeEmptyAggregatedTestResult = (): AggregatedResult => ({ numFailedTestSuites: 0, numFailedTests: 0, numPassedTestSuites: 0, @@ -43,8 +44,8 @@ export const makeEmptyAggregatedTestResult = (): TestResult.AggregatedResult => export const buildFailureTestResult = ( testPath: Config.Path, - err: TestResult.SerializableError, -): TestResult.TestResult => ({ + err: SerializableError, +): TestResult => ({ console: null, displayName: '', failureMessage: null, @@ -76,8 +77,8 @@ export const buildFailureTestResult = ( // Add individual test result to an aggregated test result export const addResult = ( - aggregatedResults: TestResult.AggregatedResult, - testResult: TestResult.TestResult, + aggregatedResults: AggregatedResult, + testResult: TestResult, ): void => { // `todos` are new as of Jest 24, and not all runners return it. // Set it to `0` to avoid `NaN` diff --git a/packages/jest-test-result/src/index.ts b/packages/jest-test-result/src/index.ts new file mode 100644 index 000000000000..883937b89ccc --- /dev/null +++ b/packages/jest-test-result/src/index.ts @@ -0,0 +1,23 @@ +/** + * 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 {default as formatTestResults} from './formatTestResults'; +export { + addResult, + buildFailureTestResult, + makeEmptyAggregatedTestResult, +} from './helpers'; +export { + AggregatedResult, + AssertionLocation, + AssertionResult, + SerializableError, + SnapshotSummary, + Status, + Suite, + TestResult, +} from './types'; diff --git a/packages/jest-types/src/TestResult.ts b/packages/jest-test-result/src/types.ts similarity index 98% rename from packages/jest-types/src/TestResult.ts rename to packages/jest-test-result/src/types.ts index caa976e84a28..3d3eeed73c61 100644 --- a/packages/jest-types/src/TestResult.ts +++ b/packages/jest-test-result/src/types.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +// eslint-disable-next-line import/no-extraneous-dependencies import {CoverageMap, CoverageMapData} from 'istanbul-lib-coverage'; import {ConsoleBuffer} from '@jest/console'; diff --git a/packages/jest-test-result/tsconfig.json b/packages/jest-test-result/tsconfig.json new file mode 100644 index 000000000000..4a3022904a19 --- /dev/null +++ b/packages/jest-test-result/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "references": [ + {"path": "../jest-console"}, + {"path": "../jest-types"} + ] +} diff --git a/packages/jest-types/package.json b/packages/jest-types/package.json index 2e3ce749573b..98f1d42a99bd 100644 --- a/packages/jest-types/package.json +++ b/packages/jest-types/package.json @@ -13,7 +13,7 @@ "main": "build/index.js", "types": "build/index.d.ts", "dependencies": { - "@jest/console": "^24.1.0", - "@types/istanbul-lib-coverage": "^1.1.0" + "@types/istanbul-lib-coverage": "^1.1.0", + "@types/yargs": "^12.0.9" } } diff --git a/packages/jest-types/src/index.ts b/packages/jest-types/src/index.ts index dd30d701fb87..119377a9b79d 100644 --- a/packages/jest-types/src/index.ts +++ b/packages/jest-types/src/index.ts @@ -6,7 +6,6 @@ */ import * as Config from './Config'; -import * as TestResult from './TestResult'; import * as Global from './Global'; -export {Config, TestResult, Global}; +export {Config, Global}; diff --git a/packages/jest-types/tsconfig.json b/packages/jest-types/tsconfig.json index 7808cc33f9e5..7bb06bce6d20 100644 --- a/packages/jest-types/tsconfig.json +++ b/packages/jest-types/tsconfig.json @@ -3,8 +3,5 @@ "compilerOptions": { "rootDir": "src", "outDir": "build" - }, - "references": [ - {"path": "../jest-console"} - ] + } } diff --git a/packages/jest-util/package.json b/packages/jest-util/package.json index b1d9a023e075..e8b911b9bd03 100644 --- a/packages/jest-util/package.json +++ b/packages/jest-util/package.json @@ -13,6 +13,7 @@ "@jest/console": "^24.1.0", "@jest/fake-timers": "^24.1.0", "@jest/source-map": "^24.1.0", + "@jest/test-result": "^24.1.0", "@jest/types": "^24.1.0", "@types/node": "*", "callsites": "^3.0.0", diff --git a/packages/jest-util/src/getFailedSnapshotTests.ts b/packages/jest-util/src/getFailedSnapshotTests.ts index 192fa524a4b7..913c954440b4 100644 --- a/packages/jest-util/src/getFailedSnapshotTests.ts +++ b/packages/jest-util/src/getFailedSnapshotTests.ts @@ -5,9 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {AggregatedResult} from '@jest/test-result'; -function getFailedSnapshotTests(testResults: TestResult.AggregatedResult) { +function getFailedSnapshotTests(testResults: AggregatedResult) { const failedTestPaths: Array = []; if (testResults.numFailedTests === 0 || !testResults.testResults) { return failedTestPaths; diff --git a/packages/jest-util/src/index.ts b/packages/jest-util/src/index.ts index 6495e87e1f26..4adeb9e3c470 100644 --- a/packages/jest-util/src/index.ts +++ b/packages/jest-util/src/index.ts @@ -14,10 +14,10 @@ import { NullConsole, getConsoleOutput, } from '@jest/console'; +import {formatTestResults} from '@jest/test-result'; import clearLine from './clearLine'; import createDirectory from './createDirectory'; import ErrorWithStack from './ErrorWithStack'; -import formatTestResults from './formatTestResults'; import getFailedSnapshotTests from './getFailedSnapshotTests'; import installCommonGlobals from './installCommonGlobals'; import isInteractive from './isInteractive'; diff --git a/packages/jest-util/tsconfig.json b/packages/jest-util/tsconfig.json index 84ae1d60d0e8..f40d52b2fb32 100644 --- a/packages/jest-util/tsconfig.json +++ b/packages/jest-util/tsconfig.json @@ -8,6 +8,7 @@ {"path": "../jest-console"}, {"path": "../jest-fake-timers"}, {"path": "../jest-source-map"}, + {"path": "../jest-test-result"}, {"path": "../jest-types"} ] } diff --git a/packages/jest-watcher/package.json b/packages/jest-watcher/package.json index df3bd61731ce..9ab1947c4b78 100644 --- a/packages/jest-watcher/package.json +++ b/packages/jest-watcher/package.json @@ -4,6 +4,7 @@ "version": "24.0.0", "main": "build/index.js", "dependencies": { + "@jest/test-result": "^24.1.0", "@jest/types": "^24.1.0", "@types/node": "*", "ansi-escapes": "^3.0.0", diff --git a/packages/jest-watcher/src/types.ts b/packages/jest-watcher/src/types.ts index e8c5bb128d20..932eb9f4b69f 100644 --- a/packages/jest-watcher/src/types.ts +++ b/packages/jest-watcher/src/types.ts @@ -5,7 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {Config, TestResult} from '@jest/types'; +import {Config} from '@jest/types'; +import {AggregatedResult} from '@jest/test-result'; type TestSuiteInfo = { config: Config.ProjectConfig; @@ -24,7 +25,7 @@ export type FileChange = (fs: JestHookExposedFS) => void; export type ShouldRunTestSuite = ( testSuiteInfo: TestSuiteInfo, ) => Promise; -export type TestRunComplete = (results: TestResult.AggregatedResult) => void; +export type TestRunComplete = (results: AggregatedResult) => void; export type JestHookSubscriber = { onFileChange: (fn: FileChange) => void; @@ -34,7 +35,7 @@ export type JestHookSubscriber = { export type JestHookEmitter = { onFileChange: (fs: JestHookExposedFS) => void; - onTestRunComplete: (results: TestResult.AggregatedResult) => void; + onTestRunComplete: (results: AggregatedResult) => void; shouldRunTestSuite: (testSuiteInfo: TestSuiteInfo) => Promise; }; diff --git a/packages/jest-watcher/tsconfig.json b/packages/jest-watcher/tsconfig.json index 2bea30d53a40..eb392c86ab90 100644 --- a/packages/jest-watcher/tsconfig.json +++ b/packages/jest-watcher/tsconfig.json @@ -4,5 +4,9 @@ "rootDir": "src", "outDir": "build" }, - "references": [{"path": "../jest-types"}, {"path": "../jest-util"}] + "references": [ + {"path": "../jest-test-result"}, + {"path": "../jest-types"}, + {"path": "../jest-util"} + ] } diff --git a/yarn.lock b/yarn.lock index 35dfdc279ddb..85ea7f1405f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1860,7 +1860,7 @@ dependencies: "@types/node" "*" -"@types/yargs@^12.0.2": +"@types/yargs@^12.0.2", "@types/yargs@^12.0.9": version "12.0.9" resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-12.0.9.tgz#693e76a52f61a2f1e7fb48c0eef167b95ea4ffd0" integrity sha512-sCZy4SxP9rN2w30Hlmg5dtdRwgYQfYRiLo9usw8X9cxlf+H4FqM1xX7+sNH7NNKVdbXMJWqva7iyy+fxh/V7fA==