Skip to content

Commit

Permalink
chore(runtime): make arguments mandatory (#10975)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Dec 23, 2020
1 parent ac02f02 commit e651a21
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const jestAdapter = async (
localRequire: runtime.requireModule.bind(runtime),
parentProcess: process,
sendMessageToJest,
setGlobalsForRuntime: runtime.setGlobalsForRuntime?.bind(runtime),
setGlobalsForRuntime: runtime.setGlobalsForRuntime.bind(runtime),
testPath,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const initialize = async ({
testPath: Config.Path;
parentProcess: Process;
sendMessageToJest?: TestFileEvent;
setGlobalsForRuntime?: (globals: JestGlobals) => void;
setGlobalsForRuntime: (globals: JestGlobals) => void;
}): Promise<{
globals: Global.TestFrameworkGlobals;
snapshotState: SnapshotStateType;
Expand Down Expand Up @@ -126,11 +126,9 @@ export const initialize = async ({
...globalsObject,
expect: createExpect(globalConfig),
};
// TODO: `jest-circus` might be newer than `jest-runtime` - remove `?.` for Jest 27
setGlobalsForRuntime?.(runtimeGlobals);
setGlobalsForRuntime(runtimeGlobals);

// TODO: `jest-circus` might be newer than `jest-config` - remove `??` for Jest 27
if (config.injectGlobals ?? true) {
if (config.injectGlobals) {
Object.assign(environment.global, runtimeGlobals);
}

Expand Down
9 changes: 8 additions & 1 deletion packages/jest-repl/src/cli/runtime-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ export async function run(
environment,
hasteMap.resolver,
new Map(),
undefined,
{
changedFiles: undefined,
collectCoverage: false,
collectCoverageFrom: [],
collectCoverageOnlyFrom: undefined,
coverageProvider: 'v8',
sourcesRelatedToTestsInChangedFiles: undefined,
},
filePath,
);

Expand Down
9 changes: 8 additions & 1 deletion packages/jest-runtime/src/__mocks__/createRuntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ module.exports = async function createRuntime(filename, config) {
environment,
Runtime.createResolver(config, hasteMap.moduleMap),
new Map(),
undefined,
{
changedFiles: undefined,
collectCoverage: false,
collectCoverageFrom: [],
collectCoverageOnlyFrom: undefined,
coverageProvider: 'v8',
sourcesRelatedToTestsInChangedFiles: undefined,
},
filename,
);

Expand Down
16 changes: 4 additions & 12 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default class Runtime {
private _isolatedModuleRegistry: ModuleRegistry | null;
private _moduleRegistry: ModuleRegistry;
private readonly _esmoduleRegistry: Map<string, EsmModuleCache>;
private readonly _testPath: Config.Path | undefined;
private readonly _testPath: Config.Path;
private readonly _resolver: Resolver;
private _shouldAutoMock: boolean;
private readonly _shouldMockModuleCache: Map<string, boolean>;
Expand All @@ -191,20 +191,12 @@ export default class Runtime {
environment: JestEnvironment,
resolver: Resolver,
cacheFS: Map<string, string>,
coverageOptions?: ShouldInstrumentOptions,
// TODO: Make mandatory in Jest 27
testPath?: Config.Path,
coverageOptions: ShouldInstrumentOptions,
testPath: Config.Path,
) {
this._cacheFS = cacheFS;
this._config = config;
this._coverageOptions = coverageOptions || {
changedFiles: undefined,
collectCoverage: false,
collectCoverageFrom: [],
collectCoverageOnlyFrom: undefined,
coverageProvider: 'babel',
sourcesRelatedToTestsInChangedFiles: undefined,
};
this._coverageOptions = coverageOptions;
this._currentlyExecutingModulePath = '';
this._environment = environment;
this._explicitShouldMock = new Map();
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-test-result/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import type {ConsoleBuffer} from '@jest/console';
import type {Config, TestResult, TransformTypes} from '@jest/types';

export interface RuntimeTransformResult extends TransformTypes.TransformResult {
// TODO: Make mandatory in Jest 27
wrapperLength?: number;
wrapperLength: number;
}

export type V8CoverageResult = Array<{
Expand Down

0 comments on commit e651a21

Please sign in to comment.