Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor(jest-runtime)!: remove Context type, it must be imported from @jest/test-result #12685

Merged
merged 4 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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))
Expand Down
9 changes: 4 additions & 5 deletions packages/jest-core/src/SearchSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -41,7 +40,7 @@ const regexToMatcher = (testRegex: Config.ProjectConfig['testRegex']) => {
});
};

const toTests = (context: Context, tests: Array<string>) =>
const toTests = (context: TestContext, tests: Array<string>) =>
tests.map(path => ({
context,
duration: undefined,
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-core/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -227,7 +227,7 @@ const _run10000 = async (
};

const runWatch = async (
contexts: Array<Context>,
contexts: Array<TestContext>,
_configs: Array<Config.ProjectConfig>,
hasDeprecationWarnings: boolean,
globalConfig: Config.GlobalConfig,
Expand Down Expand Up @@ -265,7 +265,7 @@ const runWatch = async (

const runWithoutWatch = async (
globalConfig: Config.GlobalConfig,
contexts: Array<Context>,
contexts: Array<TestContext>,
outputStream: NodeJS.WriteStream,
onComplete: OnCompleteCallback,
changedFilesPromise?: ChangedFilesPromise,
Expand Down
5 changes: 3 additions & 2 deletions packages/jest-core/src/lib/createContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-core/src/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {CustomConsole} from '@jest/console';
import {
AggregatedResult,
Test,
TestContext,
TestResultsProcessor,
formatTestResults,
makeEmptyAggregatedTestResult,
Expand All @@ -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';
Expand Down Expand Up @@ -136,7 +136,7 @@ export default async function runJest({
filter,
}: {
globalConfig: Config.GlobalConfig;
contexts: Array<Context>;
contexts: Array<TestContext>;
outputStream: NodeJS.WriteStream;
testWatcher: TestWatcher;
jestHooks?: JestHookEmitter;
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,7 +16,7 @@ export type Stats = {
};

export type TestRunData = Array<{
context: Context;
context: TestContext;
matches: {
allTests: number;
tests: Array<Test>;
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-core/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -91,7 +91,7 @@ const RESERVED_KEY_PLUGINS = new Map<

export default async function watch(
initialGlobalConfig: Config.GlobalConfig,
contexts: Array<Context>,
contexts: Array<TestContext>,
outputStream: NodeJS.WriteStream,
hasteMapInstances: Array<HasteMap>,
stdin: NodeJS.ReadStream = process.stdin,
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-reporters/src/SummaryReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default class SummaryReporter extends BaseReporter {
}

private _getTestSummary(
contexts: Set<TestContext>,
testContexts: Set<TestContext>,
globalConfig: Config.GlobalConfig,
) {
const getMatchingTestsInfo = () => {
Expand Down Expand Up @@ -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 (
Expand Down
11 changes: 6 additions & 5 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -57,9 +61,6 @@ import {
decodePossibleOutsideJestVmPath,
findSiblingsWithFileExtension,
} from './helpers';
import type {Context} from './types';

export type {Context} from './types';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be fine to keep reexport, but is it useful?


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

Expand Down Expand Up @@ -332,7 +333,7 @@ export default class Runtime {
watch?: boolean;
watchman: boolean;
},
): Promise<Context> {
): Promise<TestContext> {
createDirectory(config.cacheDirectory);
const instance = await Runtime.createHasteMap(config, {
console: options.console,
Expand Down
17 changes: 0 additions & 17 deletions packages/jest-runtime/src/types.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/jest-test-sequencer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand All @@ -24,7 +23,7 @@ let sequencer: TestSequencer;

const fs = jest.mocked(mockedFs);

const context: Context = {
const context: TestContext = {
config: makeProjectConfig({
cache: true,
cacheDirectory: '/cache',
Expand All @@ -36,7 +35,7 @@ const context: Context = {
},
};

const secondContext: Context = {
const secondContext: TestContext = {
config: makeProjectConfig({
cache: true,
cacheDirectory: '/cache2',
Expand Down
9 changes: 4 additions & 5 deletions packages/jest-test-sequencer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Context, Cache> = new Map();
private _cache: Map<TestContext, Cache> = 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,
Expand Down
1 change: 0 additions & 1 deletion packages/jest-test-sequencer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"exclude": ["./**/__tests__/**/*"],
"references": [
{"path": "../jest-haste-map"},
{"path": "../jest-runtime"},
{"path": "../jest-test-result"},
{"path": "../test-utils"}
]
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down