Skip to content

Commit d2f3dc6

Browse files
authored
refactor(jest-runtime)!: remove Context type, it must be imported from @jest/test-result (#12685)
1 parent 3b69f23 commit d2f3dc6

File tree

15 files changed

+34
-55
lines changed

15 files changed

+34
-55
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
- `[jest-runner]` Exposing `CallbackTestRunner`, `EmittingTestRunner` abstract classes to help typing third party runners ([#12646](https://github.com/facebook/jest/pull/12646))
5050
- `[jest-runtime]` [**BREAKING**] `Runtime.createHasteMap` now returns a promise ([#12008](https://github.com/facebook/jest/pull/12008))
5151
- `[jest-runtime]` Calling `jest.resetModules` function will clear FS and transform cache ([#12531](https://github.com/facebook/jest/pull/12531))
52+
- `[jest-runtime]` [**BREAKING**] Remove `Context` type export, it must be imported from `@jest/test-result` ([#12685](https://github.com/facebook/jest/pull/12685))
5253
- `[@jest/schemas]` New module for JSON schemas for Jest's config ([#12384](https://github.com/facebook/jest/pull/12384))
5354
- `[jest-transform]` [**BREAKING**] Make it required for `process()` and `processAsync()` methods to always return structured data ([#12638](https://github.com/facebook/jest/pull/12638))
5455
- `[jest-test-result]` Add duration property to JSON test output ([#12518](https://github.com/facebook/jest/pull/12518))

packages/jest-core/src/SearchSource.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
import * as os from 'os';
99
import * as path from 'path';
1010
import micromatch = require('micromatch');
11-
import type {Test} from '@jest/test-result';
11+
import type {Test, TestContext} from '@jest/test-result';
1212
import type {Config} from '@jest/types';
1313
import type {ChangedFiles} from 'jest-changed-files';
1414
import {replaceRootDirInPath} from 'jest-config';
1515
import {escapePathForRegex} from 'jest-regex-util';
1616
import {DependencyResolver} from 'jest-resolve-dependencies';
17-
import type {Context} from 'jest-runtime';
1817
import {buildSnapshotResolver} from 'jest-snapshot';
1918
import {globsToMatcher, testPathPatternToRegExp} from 'jest-util';
2019
import type {Filter, Stats, TestPathCases} from './types';
@@ -41,7 +40,7 @@ const regexToMatcher = (testRegex: Config.ProjectConfig['testRegex']) => {
4140
});
4241
};
4342

44-
const toTests = (context: Context, tests: Array<string>) =>
43+
const toTests = (context: TestContext, tests: Array<string>) =>
4544
tests.map(path => ({
4645
context,
4746
duration: undefined,
@@ -56,11 +55,11 @@ const hasSCM = (changedFilesInfo: ChangedFiles) => {
5655
};
5756

5857
export default class SearchSource {
59-
private _context: Context;
58+
private _context: TestContext;
6059
private _dependencyResolver: DependencyResolver | null;
6160
private _testPathCases: TestPathCases = [];
6261

63-
constructor(context: Context) {
62+
constructor(context: TestContext) {
6463
const {config} = context;
6564
this._context = context;
6665
this._dependencyResolver = null;

packages/jest-core/src/cli/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import chalk = require('chalk');
99
import exit = require('exit');
1010
import rimraf = require('rimraf');
1111
import {CustomConsole} from '@jest/console';
12-
import type {AggregatedResult} from '@jest/test-result';
12+
import type {AggregatedResult, TestContext} from '@jest/test-result';
1313
import type {Config} from '@jest/types';
1414
import type {ChangedFilesPromise} from 'jest-changed-files';
1515
import {readConfigs} from 'jest-config';
1616
import type HasteMap from 'jest-haste-map';
17-
import Runtime, {Context} from 'jest-runtime';
17+
import Runtime from 'jest-runtime';
1818
import {createDirectory, preRunMessage} from 'jest-util';
1919
import {TestWatcher} from 'jest-watcher';
2020
import {formatHandleErrors} from '../collectHandles';
@@ -227,7 +227,7 @@ const _run10000 = async (
227227
};
228228

229229
const runWatch = async (
230-
contexts: Array<Context>,
230+
contexts: Array<TestContext>,
231231
_configs: Array<Config.ProjectConfig>,
232232
hasDeprecationWarnings: boolean,
233233
globalConfig: Config.GlobalConfig,
@@ -265,7 +265,7 @@ const runWatch = async (
265265

266266
const runWithoutWatch = async (
267267
globalConfig: Config.GlobalConfig,
268-
contexts: Array<Context>,
268+
contexts: Array<TestContext>,
269269
outputStream: NodeJS.WriteStream,
270270
onComplete: OnCompleteCallback,
271271
changedFilesPromise?: ChangedFilesPromise,

packages/jest-core/src/lib/createContext.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
import type {TestContext} from '@jest/test-result';
89
import type {Config} from '@jest/types';
910
import type {HasteMapObject} from 'jest-haste-map';
10-
import Runtime, {Context} from 'jest-runtime';
11+
import Runtime from 'jest-runtime';
1112

1213
export default function createContext(
1314
config: Config.ProjectConfig,
1415
{hasteFS, moduleMap}: HasteMapObject,
15-
): Context {
16+
): TestContext {
1617
return {
1718
config,
1819
hasteFS,

packages/jest-core/src/runJest.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {CustomConsole} from '@jest/console';
1313
import {
1414
AggregatedResult,
1515
Test,
16+
TestContext,
1617
TestResultsProcessor,
1718
formatTestResults,
1819
makeEmptyAggregatedTestResult,
@@ -21,7 +22,6 @@ import type TestSequencer from '@jest/test-sequencer';
2122
import type {Config} from '@jest/types';
2223
import type {ChangedFiles, ChangedFilesPromise} from 'jest-changed-files';
2324
import Resolver from 'jest-resolve';
24-
import type {Context} from 'jest-runtime';
2525
import {requireOrImportModule, tryRealpath} from 'jest-util';
2626
import {JestHook, JestHookEmitter, TestWatcher} from 'jest-watcher';
2727
import type FailedTestsCache from './FailedTestsCache';
@@ -136,7 +136,7 @@ export default async function runJest({
136136
filter,
137137
}: {
138138
globalConfig: Config.GlobalConfig;
139-
contexts: Array<Context>;
139+
contexts: Array<TestContext>;
140140
outputStream: NodeJS.WriteStream;
141141
testWatcher: TestWatcher;
142142
jestHooks?: JestHookEmitter;

packages/jest-core/src/types.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import type {Test} from '@jest/test-result';
9-
import type {Context} from 'jest-runtime';
8+
import type {Test, TestContext} from '@jest/test-result';
109

1110
export type Stats = {
1211
roots: number;
@@ -17,7 +16,7 @@ export type Stats = {
1716
};
1817

1918
export type TestRunData = Array<{
20-
context: Context;
19+
context: TestContext;
2120
matches: {
2221
allTests: number;
2322
tests: Array<Test>;

packages/jest-core/src/watch.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import ansiEscapes = require('ansi-escapes');
1010
import chalk = require('chalk');
1111
import exit = require('exit');
1212
import slash = require('slash');
13+
import type {TestContext} from '@jest/test-result';
1314
import type {Config} from '@jest/types';
1415
import type {
1516
ChangeEvent as HasteChangeEvent,
1617
default as HasteMap,
1718
} from 'jest-haste-map';
1819
import {formatExecError} from 'jest-message-util';
19-
import type {Context} from 'jest-runtime';
2020
import {
2121
isInteractive,
2222
preRunMessage,
@@ -91,7 +91,7 @@ const RESERVED_KEY_PLUGINS = new Map<
9191

9292
export default async function watch(
9393
initialGlobalConfig: Config.GlobalConfig,
94-
contexts: Array<Context>,
94+
contexts: Array<TestContext>,
9595
outputStream: NodeJS.WriteStream,
9696
hasteMapInstances: Array<HasteMap>,
9797
stdin: NodeJS.ReadStream = process.stdin,

packages/jest-reporters/src/SummaryReporter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export default class SummaryReporter extends BaseReporter {
192192
}
193193

194194
private _getTestSummary(
195-
contexts: Set<TestContext>,
195+
testContexts: Set<TestContext>,
196196
globalConfig: Config.GlobalConfig,
197197
) {
198198
const getMatchingTestsInfo = () => {
@@ -227,8 +227,8 @@ export default class SummaryReporter extends BaseReporter {
227227
}
228228

229229
const contextInfo =
230-
contexts.size > 1
231-
? chalk.dim(' in ') + contexts.size + chalk.dim(' projects')
230+
testContexts.size > 1
231+
? chalk.dim(' in ') + testContexts.size + chalk.dim(' projects')
232232
: '';
233233

234234
return (

packages/jest-runtime/src/index.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ import type {
3333
import type {LegacyFakeTimers, ModernFakeTimers} from '@jest/fake-timers';
3434
import type * as JestGlobals from '@jest/globals';
3535
import type {SourceMapRegistry} from '@jest/source-map';
36-
import type {RuntimeTransformResult, V8CoverageResult} from '@jest/test-result';
36+
import type {
37+
RuntimeTransformResult,
38+
TestContext,
39+
V8CoverageResult,
40+
} from '@jest/test-result';
3741
import {
3842
CallerTransformOptions,
3943
ScriptTransformer,
@@ -57,9 +61,6 @@ import {
5761
decodePossibleOutsideJestVmPath,
5862
findSiblingsWithFileExtension,
5963
} from './helpers';
60-
import type {Context} from './types';
61-
62-
export type {Context} from './types';
6364

6465
const esmIsAvailable = typeof SourceTextModule === 'function';
6566

@@ -332,7 +333,7 @@ export default class Runtime {
332333
watch?: boolean;
333334
watchman: boolean;
334335
},
335-
): Promise<Context> {
336+
): Promise<TestContext> {
336337
createDirectory(config.cacheDirectory);
337338
const instance = await Runtime.createHasteMap(config, {
338339
console: options.console,

packages/jest-runtime/src/types.ts

-17
This file was deleted.

packages/jest-test-sequencer/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"@jest/test-result": "^28.0.0-alpha.8",
2121
"graceful-fs": "^4.2.9",
2222
"jest-haste-map": "^28.0.0-alpha.8",
23-
"jest-runtime": "^28.0.0-alpha.8",
2423
"slash": "^3.0.0"
2524
},
2625
"devDependencies": {

packages/jest-test-sequencer/src/__tests__/test_sequencer.test.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
import * as path from 'path';
99
import * as mockedFs from 'graceful-fs';
10-
import type {Test} from '@jest/test-result';
10+
import type {Test, TestContext} from '@jest/test-result';
1111
import {makeProjectConfig} from '@jest/test-utils';
12-
import type {Context} from 'jest-runtime';
1312
import TestSequencer from '../index';
1413

1514
jest.mock('graceful-fs', () => ({
@@ -24,7 +23,7 @@ let sequencer: TestSequencer;
2423

2524
const fs = jest.mocked(mockedFs);
2625

27-
const context: Context = {
26+
const context: TestContext = {
2827
config: makeProjectConfig({
2928
cache: true,
3029
cacheDirectory: '/cache',
@@ -36,7 +35,7 @@ const context: Context = {
3635
},
3736
};
3837

39-
const secondContext: Context = {
38+
const secondContext: TestContext = {
4039
config: makeProjectConfig({
4140
cache: true,
4241
cacheDirectory: '/cache2',

packages/jest-test-sequencer/src/index.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import * as crypto from 'crypto';
99
import * as path from 'path';
1010
import * as fs from 'graceful-fs';
1111
import slash = require('slash');
12-
import type {AggregatedResult, Test} from '@jest/test-result';
12+
import type {AggregatedResult, Test, TestContext} from '@jest/test-result';
1313
import HasteMap from 'jest-haste-map';
14-
import type {Context} from 'jest-runtime';
1514

1615
const FAIL = 0;
1716
const SUCCESS = 1;
@@ -39,10 +38,10 @@ export type ShardOptions = {
3938
* is called to store/update this information on the cache map.
4039
*/
4140
export default class TestSequencer {
42-
private _cache: Map<Context, Cache> = new Map();
41+
private _cache: Map<TestContext, Cache> = new Map();
4342

44-
_getCachePath(context: Context): string {
45-
const {config} = context;
43+
_getCachePath(testContext: TestContext): string {
44+
const {config} = testContext;
4645
const HasteMapClass = HasteMap.getStatic(config);
4746
return HasteMapClass.getCacheFilePath(
4847
config.cacheDirectory,

packages/jest-test-sequencer/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"exclude": ["./**/__tests__/**/*"],
99
"references": [
1010
{"path": "../jest-haste-map"},
11-
{"path": "../jest-runtime"},
1211
{"path": "../jest-test-result"},
1312
{"path": "../test-utils"}
1413
]

yarn.lock

-1
Original file line numberDiff line numberDiff line change
@@ -2847,7 +2847,6 @@ __metadata:
28472847
"@types/graceful-fs": ^4.1.3
28482848
graceful-fs: ^4.2.9
28492849
jest-haste-map: ^28.0.0-alpha.8
2850-
jest-runtime: ^28.0.0-alpha.8
28512850
slash: ^3.0.0
28522851
languageName: unknown
28532852
linkType: soft

0 commit comments

Comments
 (0)