Skip to content

Commit

Permalink
chore: convert jest-runtime to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Sep 21, 2020
1 parent 6499deb commit 057b7b6
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

### Chore & Maintenance

- `[jest-runtime]` [**BREAKING**] Convert to ESM ([#10325](https://github.com/facebook/jest/pull/10325))

### Performance

## 26.4.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {Config} from '@jest/types';
import type {JestEnvironment} from '@jest/environment';
import type {TestResult} from '@jest/test-result';
import type {TestFileEvent} from 'jest-runner';
import type {RuntimeType as Runtime} from 'jest-runtime';
import type Runtime from 'jest-runtime';
import type {SnapshotStateType} from 'jest-snapshot';
import {deepCyclicCopy} from 'jest-util';

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/__tests__/SearchSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import * as path from 'path';
import Runtime = require('jest-runtime');
import Runtime from 'jest-runtime';
import {normalize} from 'jest-config';
import {Test} from 'jest-runner';
import type {Config} from '@jest/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as path from 'path';
import {tmpdir} from 'os';
import * as fs from 'graceful-fs';
import {JestHook} from 'jest-watcher';
import Runtime = require('jest-runtime');
import Runtime from 'jest-runtime';
import {normalize} from 'jest-config';
import HasteMap = require('jest-haste-map');
import rimraf = require('rimraf');
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-core/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {AggregatedResult} from '@jest/test-result';
import {CustomConsole} from '@jest/console';
import {createDirectory, preRunMessage} from 'jest-util';
import {readConfigs} from 'jest-config';
import Runtime = require('jest-runtime');
import Runtime, {Context} from 'jest-runtime';
import type {ChangedFilesPromise} from 'jest-changed-files';
import HasteMap = require('jest-haste-map');
import chalk = require('chalk');
Expand Down Expand Up @@ -218,7 +218,7 @@ const _run10000 = async (
};

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

const runWithoutWatch = async (
globalConfig: Config.GlobalConfig,
contexts: Array<Runtime.Context>,
contexts: Array<Context>,
outputStream: NodeJS.WriteStream,
onComplete: OnCompleteCallback,
changedFilesPromise?: ChangedFilesPromise,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-core/src/lib/create_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/

import type {Config} from '@jest/types';
import Runtime = require('jest-runtime');
import Runtime, {Context} from 'jest-runtime';
import type {HasteMapObject} from 'jest-haste-map';

export default (
config: Config.ProjectConfig,
{hasteFS, moduleMap}: HasteMapObject,
): Runtime.Context => ({
): Context => ({
config,
hasteFS,
moduleMap,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {Config, Global} from '@jest/types';
import type {AssertionResult, TestResult} from '@jest/test-result';
import type {JestEnvironment} from '@jest/environment';
import type {SnapshotStateType} from 'jest-snapshot';
import type {RuntimeType as Runtime} from 'jest-runtime';
import type Runtime from 'jest-runtime';

import {getCallsite} from '@jest/source-map';
import installEach from './each';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-repl/src/cli/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import type {Options} from 'yargs';
import Runtime = require('jest-runtime');
import Runtime from 'jest-runtime';

export const usage = 'Usage: $0 [--config=<pathToConfigFile>]';

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-repl/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
*/

import Runtime = require('jest-runtime');
import Runtime from 'jest-runtime';
import yargs = require('yargs');
import {validateCLIOptions} from 'jest-validate';
import {deprecationEntries} from 'jest-config';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const filter = (path: Config.Path) =>
Object.keys(cases).every(key => cases[key](path));

beforeEach(() => {
Runtime = require('jest-runtime');
Runtime = require('jest-runtime').default;
config = makeProjectConfig({
cacheDirectory: path.resolve(tmpdir(), 'jest-resolve-dependencies-test'),
moduleDirectories: ['node_modules'],
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runner/src/testWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {SerializableError, TestResult} from '@jest/test-result';
import HasteMap = require('jest-haste-map');
import exit = require('exit');
import {separateMessageFromStack} from 'jest-message-util';
import Runtime = require('jest-runtime');
import Runtime from 'jest-runtime';
import type {ResolverType} from 'jest-resolve';
import {messageParent} from 'jest-worker';
import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runner/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
import type {JestEnvironment} from '@jest/environment';
import type {FS as HasteFS, ModuleMap} from 'jest-haste-map';
import type {ResolverType} from 'jest-resolve';
import type {RuntimeType} from 'jest-runtime';
import type RuntimeType from 'jest-runtime';

export type ErrorWithCode = Error & {code?: string};
export type Test = {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runtime/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function run(
automock: false,
};

const Runtime: typeof import('..') = require('..');
const {default: Runtime} = await import('..');

try {
const hasteMap = await Runtime.createContext(config, {
Expand Down
16 changes: 5 additions & 11 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import HasteMap = require('jest-haste-map');
import Resolver = require('jest-resolve');
import Snapshot = require('jest-snapshot');
import stripBOM = require('strip-bom');
import type {Context as JestContext} from './types';
import type {Context} from './types';
import {
createOutsideJestVmPath,
decodePossibleOutsideJestVmPath,
Expand All @@ -57,6 +57,8 @@ import {
import {options as cliOptions} from './cli/args';
import {run as cliRun} from './cli';

export type {Context} from './types';

interface JestGlobals extends Global.TestFrameworkGlobals {
expect: typeof JestGlobals.expect;
}
Expand Down Expand Up @@ -108,12 +110,6 @@ const fromEntries: typeof Object.fromEntries =
}, {});
};

namespace Runtime {
export type Context = JestContext;
// ditch this export when moving to esm - for now we need it for to avoid faulty type elision
export type RuntimeType = Runtime;
}

const testTimeoutSymbol = Symbol.for('TEST_TIMEOUT_SYMBOL');
const retryTimesSymbol = Symbol.for('RETRY_TIMES');

Expand All @@ -140,7 +136,7 @@ type RunScriptEvalResult = {[EVAL_RESULT_VARIABLE]: ModuleWrapper};

const runtimeSupportsVmModules = typeof SyntheticModule === 'function';

class Runtime {
export default class Runtime {
private _cacheFS: StringMap;
private _config: Config.ProjectConfig;
private _coverageOptions: ShouldInstrumentOptions;
Expand Down Expand Up @@ -259,7 +255,7 @@ class Runtime {
watch?: boolean;
watchman: boolean;
},
): Promise<JestContext> {
): Promise<Context> {
createDirectory(config.cacheDirectory);
const instance = Runtime.createHasteMap(config, {
console: options.console,
Expand Down Expand Up @@ -1737,5 +1733,3 @@ function invariant(condition: unknown, message?: string): asserts condition {
function notEmpty<T>(value: T | null | undefined): value is T {
return value !== null && value !== undefined;
}

export = Runtime;

0 comments on commit 057b7b6

Please sign in to comment.