diff --git a/CHANGELOG.md b/CHANGELOG.md index b64c2d6b4f7b..42f143013922 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ - `[jest-runner]` Exposing `CallbackTestRunner`, `EmittingTestRunner` abstract classes to help typing third party runners ([#12646](https://github.com/facebook/jest/pull/12646)) - `[jest-runtime]` [**BREAKING**] `Runtime.createHasteMap` now returns a promise ([#12008](https://github.com/facebook/jest/pull/12008)) - `[jest-runtime]` Calling `jest.resetModules` function will clear FS and transform cache ([#12531](https://github.com/facebook/jest/pull/12531)) +- `[jest-runtime]` [**BREAKING**] Remove `Context` type export, it must be imported from `@jest/test-result` ([#12685](https://github.com/facebook/jest/pull/12685)) - `[@jest/schemas]` New module for JSON schemas for Jest's config ([#12384](https://github.com/facebook/jest/pull/12384)) - `[jest-transform]` [**BREAKING**] Make it required for `process()` and `processAsync()` methods to always return structured data ([#12638](https://github.com/facebook/jest/pull/12638)) - `[jest-test-result]` Add duration property to JSON test output ([#12518](https://github.com/facebook/jest/pull/12518)) diff --git a/packages/jest-core/src/SearchSource.ts b/packages/jest-core/src/SearchSource.ts index fd8d254204b6..b1c8d31125fd 100644 --- a/packages/jest-core/src/SearchSource.ts +++ b/packages/jest-core/src/SearchSource.ts @@ -8,13 +8,12 @@ import * as os from 'os'; import * as path from 'path'; import micromatch = require('micromatch'); -import type {Test} from '@jest/test-result'; +import type {Test, TestContext} from '@jest/test-result'; import type {Config} from '@jest/types'; import type {ChangedFiles} from 'jest-changed-files'; import {replaceRootDirInPath} from 'jest-config'; import {escapePathForRegex} from 'jest-regex-util'; import {DependencyResolver} from 'jest-resolve-dependencies'; -import type {Context} from 'jest-runtime'; import {buildSnapshotResolver} from 'jest-snapshot'; import {globsToMatcher, testPathPatternToRegExp} from 'jest-util'; import type {Filter, Stats, TestPathCases} from './types'; @@ -41,7 +40,7 @@ const regexToMatcher = (testRegex: Config.ProjectConfig['testRegex']) => { }); }; -const toTests = (context: Context, tests: Array) => +const toTests = (context: TestContext, tests: Array) => tests.map(path => ({ context, duration: undefined, @@ -56,11 +55,11 @@ const hasSCM = (changedFilesInfo: ChangedFiles) => { }; export default class SearchSource { - private _context: Context; + private _context: TestContext; private _dependencyResolver: DependencyResolver | null; private _testPathCases: TestPathCases = []; - constructor(context: Context) { + constructor(context: TestContext) { const {config} = context; this._context = context; this._dependencyResolver = null; diff --git a/packages/jest-core/src/cli/index.ts b/packages/jest-core/src/cli/index.ts index c80f06b0040c..478b7f0d9cc4 100644 --- a/packages/jest-core/src/cli/index.ts +++ b/packages/jest-core/src/cli/index.ts @@ -9,12 +9,12 @@ import chalk = require('chalk'); import exit = require('exit'); import rimraf = require('rimraf'); import {CustomConsole} from '@jest/console'; -import type {AggregatedResult} from '@jest/test-result'; +import type {AggregatedResult, TestContext} from '@jest/test-result'; import type {Config} from '@jest/types'; import type {ChangedFilesPromise} from 'jest-changed-files'; import {readConfigs} from 'jest-config'; import type HasteMap from 'jest-haste-map'; -import Runtime, {Context} from 'jest-runtime'; +import Runtime from 'jest-runtime'; import {createDirectory, preRunMessage} from 'jest-util'; import {TestWatcher} from 'jest-watcher'; import {formatHandleErrors} from '../collectHandles'; @@ -227,7 +227,7 @@ const _run10000 = async ( }; const runWatch = async ( - contexts: Array, + contexts: Array, _configs: Array, hasDeprecationWarnings: boolean, globalConfig: Config.GlobalConfig, @@ -265,7 +265,7 @@ const runWatch = async ( const runWithoutWatch = async ( globalConfig: Config.GlobalConfig, - contexts: Array, + contexts: Array, outputStream: NodeJS.WriteStream, onComplete: OnCompleteCallback, changedFilesPromise?: ChangedFilesPromise, diff --git a/packages/jest-core/src/lib/createContext.ts b/packages/jest-core/src/lib/createContext.ts index 0b5e3a7c8444..be1a75061dd9 100644 --- a/packages/jest-core/src/lib/createContext.ts +++ b/packages/jest-core/src/lib/createContext.ts @@ -5,14 +5,15 @@ * LICENSE file in the root directory of this source tree. */ +import type {TestContext} from '@jest/test-result'; import type {Config} from '@jest/types'; import type {HasteMapObject} from 'jest-haste-map'; -import Runtime, {Context} from 'jest-runtime'; +import Runtime from 'jest-runtime'; export default function createContext( config: Config.ProjectConfig, {hasteFS, moduleMap}: HasteMapObject, -): Context { +): TestContext { return { config, hasteFS, diff --git a/packages/jest-core/src/runJest.ts b/packages/jest-core/src/runJest.ts index 0ebc5e1a996b..7061d3d282e7 100644 --- a/packages/jest-core/src/runJest.ts +++ b/packages/jest-core/src/runJest.ts @@ -13,6 +13,7 @@ import {CustomConsole} from '@jest/console'; import { AggregatedResult, Test, + TestContext, TestResultsProcessor, formatTestResults, makeEmptyAggregatedTestResult, @@ -21,7 +22,6 @@ import type TestSequencer from '@jest/test-sequencer'; import type {Config} from '@jest/types'; import type {ChangedFiles, ChangedFilesPromise} from 'jest-changed-files'; import Resolver from 'jest-resolve'; -import type {Context} from 'jest-runtime'; import {requireOrImportModule, tryRealpath} from 'jest-util'; import {JestHook, JestHookEmitter, TestWatcher} from 'jest-watcher'; import type FailedTestsCache from './FailedTestsCache'; @@ -136,7 +136,7 @@ export default async function runJest({ filter, }: { globalConfig: Config.GlobalConfig; - contexts: Array; + contexts: Array; outputStream: NodeJS.WriteStream; testWatcher: TestWatcher; jestHooks?: JestHookEmitter; diff --git a/packages/jest-core/src/types.ts b/packages/jest-core/src/types.ts index f29b8b3e2535..98119f1c6375 100644 --- a/packages/jest-core/src/types.ts +++ b/packages/jest-core/src/types.ts @@ -5,8 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import type {Test} from '@jest/test-result'; -import type {Context} from 'jest-runtime'; +import type {Test, TestContext} from '@jest/test-result'; export type Stats = { roots: number; @@ -17,7 +16,7 @@ export type Stats = { }; export type TestRunData = Array<{ - context: Context; + context: TestContext; matches: { allTests: number; tests: Array; diff --git a/packages/jest-core/src/watch.ts b/packages/jest-core/src/watch.ts index 17eb04f1ad87..ca0a6a421f26 100644 --- a/packages/jest-core/src/watch.ts +++ b/packages/jest-core/src/watch.ts @@ -10,13 +10,13 @@ import ansiEscapes = require('ansi-escapes'); import chalk = require('chalk'); import exit = require('exit'); import slash = require('slash'); +import type {TestContext} from '@jest/test-result'; import type {Config} from '@jest/types'; import type { ChangeEvent as HasteChangeEvent, default as HasteMap, } from 'jest-haste-map'; import {formatExecError} from 'jest-message-util'; -import type {Context} from 'jest-runtime'; import { isInteractive, preRunMessage, @@ -91,7 +91,7 @@ const RESERVED_KEY_PLUGINS = new Map< export default async function watch( initialGlobalConfig: Config.GlobalConfig, - contexts: Array, + contexts: Array, outputStream: NodeJS.WriteStream, hasteMapInstances: Array, stdin: NodeJS.ReadStream = process.stdin, diff --git a/packages/jest-reporters/src/SummaryReporter.ts b/packages/jest-reporters/src/SummaryReporter.ts index 4c7ba39d965e..cef51dda1b36 100644 --- a/packages/jest-reporters/src/SummaryReporter.ts +++ b/packages/jest-reporters/src/SummaryReporter.ts @@ -192,7 +192,7 @@ export default class SummaryReporter extends BaseReporter { } private _getTestSummary( - contexts: Set, + testContexts: Set, globalConfig: Config.GlobalConfig, ) { const getMatchingTestsInfo = () => { @@ -227,8 +227,8 @@ export default class SummaryReporter extends BaseReporter { } const contextInfo = - contexts.size > 1 - ? chalk.dim(' in ') + contexts.size + chalk.dim(' projects') + testContexts.size > 1 + ? chalk.dim(' in ') + testContexts.size + chalk.dim(' projects') : ''; return ( diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index c405a1191543..49eb7b38fe5b 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -33,7 +33,11 @@ import type { import type {LegacyFakeTimers, ModernFakeTimers} from '@jest/fake-timers'; import type * as JestGlobals from '@jest/globals'; import type {SourceMapRegistry} from '@jest/source-map'; -import type {RuntimeTransformResult, V8CoverageResult} from '@jest/test-result'; +import type { + RuntimeTransformResult, + TestContext, + V8CoverageResult, +} from '@jest/test-result'; import { CallerTransformOptions, ScriptTransformer, @@ -57,9 +61,6 @@ import { decodePossibleOutsideJestVmPath, findSiblingsWithFileExtension, } from './helpers'; -import type {Context} from './types'; - -export type {Context} from './types'; const esmIsAvailable = typeof SourceTextModule === 'function'; @@ -332,7 +333,7 @@ export default class Runtime { watch?: boolean; watchman: boolean; }, - ): Promise { + ): Promise { createDirectory(config.cacheDirectory); const instance = await Runtime.createHasteMap(config, { console: options.console, diff --git a/packages/jest-runtime/src/types.ts b/packages/jest-runtime/src/types.ts deleted file mode 100644 index b78f08090446..000000000000 --- a/packages/jest-runtime/src/types.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * 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. - */ - -import type {Config} from '@jest/types'; -import type {FS as HasteFS, ModuleMap} from 'jest-haste-map'; -import type Resolver from 'jest-resolve'; - -export type Context = { - config: Config.ProjectConfig; - hasteFS: HasteFS; - moduleMap: ModuleMap; - resolver: Resolver; -}; diff --git a/packages/jest-test-sequencer/package.json b/packages/jest-test-sequencer/package.json index 7b843967dce2..468c5360f8a0 100644 --- a/packages/jest-test-sequencer/package.json +++ b/packages/jest-test-sequencer/package.json @@ -20,7 +20,6 @@ "@jest/test-result": "^28.0.0-alpha.8", "graceful-fs": "^4.2.9", "jest-haste-map": "^28.0.0-alpha.8", - "jest-runtime": "^28.0.0-alpha.8", "slash": "^3.0.0" }, "devDependencies": { diff --git a/packages/jest-test-sequencer/src/__tests__/test_sequencer.test.ts b/packages/jest-test-sequencer/src/__tests__/test_sequencer.test.ts index 4830a53d1040..52a48762e22c 100644 --- a/packages/jest-test-sequencer/src/__tests__/test_sequencer.test.ts +++ b/packages/jest-test-sequencer/src/__tests__/test_sequencer.test.ts @@ -7,9 +7,8 @@ import * as path from 'path'; import * as mockedFs from 'graceful-fs'; -import type {Test} from '@jest/test-result'; +import type {Test, TestContext} from '@jest/test-result'; import {makeProjectConfig} from '@jest/test-utils'; -import type {Context} from 'jest-runtime'; import TestSequencer from '../index'; jest.mock('graceful-fs', () => ({ @@ -24,7 +23,7 @@ let sequencer: TestSequencer; const fs = jest.mocked(mockedFs); -const context: Context = { +const context: TestContext = { config: makeProjectConfig({ cache: true, cacheDirectory: '/cache', @@ -36,7 +35,7 @@ const context: Context = { }, }; -const secondContext: Context = { +const secondContext: TestContext = { config: makeProjectConfig({ cache: true, cacheDirectory: '/cache2', diff --git a/packages/jest-test-sequencer/src/index.ts b/packages/jest-test-sequencer/src/index.ts index 711765dd2cd8..2a643c4f777d 100644 --- a/packages/jest-test-sequencer/src/index.ts +++ b/packages/jest-test-sequencer/src/index.ts @@ -9,9 +9,8 @@ import * as crypto from 'crypto'; import * as path from 'path'; import * as fs from 'graceful-fs'; import slash = require('slash'); -import type {AggregatedResult, Test} from '@jest/test-result'; +import type {AggregatedResult, Test, TestContext} from '@jest/test-result'; import HasteMap from 'jest-haste-map'; -import type {Context} from 'jest-runtime'; const FAIL = 0; const SUCCESS = 1; @@ -39,10 +38,10 @@ export type ShardOptions = { * is called to store/update this information on the cache map. */ export default class TestSequencer { - private _cache: Map = new Map(); + private _cache: Map = new Map(); - _getCachePath(context: Context): string { - const {config} = context; + _getCachePath(testContext: TestContext): string { + const {config} = testContext; const HasteMapClass = HasteMap.getStatic(config); return HasteMapClass.getCacheFilePath( config.cacheDirectory, diff --git a/packages/jest-test-sequencer/tsconfig.json b/packages/jest-test-sequencer/tsconfig.json index 70822da7c647..7d3736031d3b 100644 --- a/packages/jest-test-sequencer/tsconfig.json +++ b/packages/jest-test-sequencer/tsconfig.json @@ -8,7 +8,6 @@ "exclude": ["./**/__tests__/**/*"], "references": [ {"path": "../jest-haste-map"}, - {"path": "../jest-runtime"}, {"path": "../jest-test-result"}, {"path": "../test-utils"} ] diff --git a/yarn.lock b/yarn.lock index 2455bf6708ea..e1456f4c1e05 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2847,7 +2847,6 @@ __metadata: "@types/graceful-fs": ^4.1.3 graceful-fs: ^4.2.9 jest-haste-map: ^28.0.0-alpha.8 - jest-runtime: ^28.0.0-alpha.8 slash: ^3.0.0 languageName: unknown linkType: soft