Skip to content

Commit

Permalink
Reevaluate modules in every context
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed May 5, 2020
1 parent 86615a4 commit 2d3e97a
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import checkDuplicatedNodes from "babel-check-duplicated-nodes";

import diff from "jest-diff";

const moduleCache = {};
const contextModuleCache = new WeakMap();
const sharedTestContext = createContext();

function createContext() {
Expand All @@ -33,6 +33,8 @@ function createContext() {
});
context.global = context;

contextModuleCache.set(context, Object.create(null));

// Initialize the test context with the polyfill, and then freeze the global to prevent implicit
// global creation in tests, which could cause things to bleed between tests.
runModuleInTestContext("@babel/polyfill", __filename, context);
Expand Down Expand Up @@ -66,6 +68,7 @@ function runModuleInTestContext(
// the context's global scope.
if (filename === id) return require(id);

const moduleCache = contextModuleCache.get(context);
if (moduleCache[filename]) return moduleCache[filename].exports;

const module = (moduleCache[filename] = {
Expand Down

0 comments on commit 2d3e97a

Please sign in to comment.