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

fix: expose vm context directly from test envs #9428

Merged
merged 5 commits into from
Jan 21, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
always use getVmContext if available
  • Loading branch information
SimenB committed Jan 19, 2020
commit 383610c58c9397c01f0ddd5e6714e939a254cc28
43 changes: 29 additions & 14 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,24 +785,39 @@ class Runtime {

let compiledFunction: ModuleWrapper | null = null;

if (
typeof compileFunction === 'function' &&
typeof this._environment.getVmContext === 'function'
) {
// Use this if available instead of deprecated `JestEnvironment.runScript`
if (typeof this._environment.getVmContext === 'function') {
const vmContext = this._environment.getVmContext();

if (vmContext) {
try {
compiledFunction = compileFunction(
if (typeof compileFunction === 'function') {
try {
compiledFunction = compileFunction(
transformedFile.code,
this.constructInjectedModuleParameters(),
{
filename,
parsingContext: vmContext,
},
) as ModuleWrapper;
} catch (e) {
throw handlePotentialSyntaxError(e);
}
} else {
const script = this.createScriptFromCode(
transformedFile.code,
this.constructInjectedModuleParameters(),
{
filename,
parsingContext: vmContext,
},
) as ModuleWrapper;
} catch (e) {
throw handlePotentialSyntaxError(e);
filename,
);

const runScript = script.runInContext(
vmContext,
) as RunScriptEvalResult;

if (runScript === null) {
compiledFunction = null;
} else {
compiledFunction = runScript[EVAL_RESULT_VARIABLE];
}
}
}
} else {
Expand Down