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

chore(runtime): make arguments mandatory #10975

Merged
merged 1 commit into from
Dec 23, 2020
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
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