Skip to content
/ jest Public
forked from jestjs/jest

Commit

Permalink
throw if length mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Dec 1, 2019
1 parent 9289c94 commit 6639ee3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/jest-environment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type EnvironmentContext = Partial<{

// Different Order than https://nodejs.org/api/modules.html#modules_the_module_wrapper , however needs to be in the form [jest-transform]ScriptTransformer accepts
export type ModuleWrapper = (
this: Module['exports'],
module: Module,
exports: Module['exports'],
require: Module['require'],
Expand Down
19 changes: 16 additions & 3 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
JestEnvironment,
LocalModuleRequire,
Module,
ModuleWrapper,
} from '@jest/environment';
import {SourceMapRegistry} from '@jest/source-map';
import jestMock = require('jest-mock');
Expand Down Expand Up @@ -736,9 +737,7 @@ class Runtime {
return;
}

//Wrapper
runScript[ScriptTransformer.EVAL_RESULT_VARIABLE].call(
localModule.exports,
const args: Parameters<ModuleWrapper> = [
localModule as NodeModule, // module object
localModule.exports, // module exports
localModule.require as NodeRequireFunction, // require implementation
Expand All @@ -758,6 +757,20 @@ class Runtime {
`You have requested '${globalVariable}' as a global variable, but it was not present. Please check your config or your global environment.`,
);
}),
];

const injectedModuleArguments = this.constructInjectedModuleArguments();

if (injectedModuleArguments.length !== args.length) {
throw new ReferenceError(
`We are injecting ${args.length} arguments into module wrapper, expected ${injectedModuleArguments.length}.\n\nThis is a bug in Jest, please report it`,
);
}

//Wrapper
runScript[ScriptTransformer.EVAL_RESULT_VARIABLE].apply(
localModule.exports,
args,
);

this._isCurrentlyExecutingManualMock = origCurrExecutingManualMock;
Expand Down

0 comments on commit 6639ee3

Please sign in to comment.