Skip to content

Commit 8ea6115

Browse files
cpojerFacebook Github Bot 7
authored andcommitted
Fix unmock cache initialization.
Summary: We removed global mock caches in #934 but for some reason I forgot to move this cache in the constructor. We only unmock the setup files a single time which isn't useful for subsequent tests. This makes it so we do this every time. It shouldn't have a big perf impact. Closes #942 Differential Revision: D3229346 fb-gh-sync-id: f58a2b5cc65160c2d0a63e874bb9257d3218f1a6 fbshipit-source-id: f58a2b5cc65160c2d0a63e874bb9257d3218f1a6
1 parent 60506b7 commit 8ea6115

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/Runtime/Runtime.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ const mockParentModule = {
2727
const moduleNameCache = Object.create(null);
2828
const modulePathCache = Object.create(null);
2929
const normalizedIDCache = Object.create(null);
30-
31-
const unmockCacheInitialized = new WeakMap();
3230
const unmockRegExpCache = new WeakMap();
3331

3432
const getModulePaths = from => {
@@ -77,19 +75,15 @@ class Runtime {
7775
unmockRegExpCache.set(config, this._unmockList);
7876
}
7977

80-
if (!unmockCacheInitialized.get(config)) {
81-
const unmockPath = filePath => {
82-
if (filePath && filePath.includes(constants.NODE_MODULES)) {
83-
const moduleID = this._getNormalizedModuleID(filePath);
84-
this._transitiveShouldMock[moduleID] = false;
85-
}
86-
};
87-
88-
unmockPath(config.setupEnvScriptFile);
89-
config.setupFiles.forEach(unmockPath);
90-
unmockCacheInitialized.set(config, true);
91-
}
78+
const unmockPath = filePath => {
79+
if (filePath && filePath.includes(constants.NODE_MODULES)) {
80+
const moduleID = this._getNormalizedModuleID(filePath);
81+
this._transitiveShouldMock[moduleID] = false;
82+
}
83+
};
9284

85+
unmockPath(config.setupEnvScriptFile);
86+
config.setupFiles.forEach(unmockPath);
9387
// Workers communicate the config as JSON so we have to create a regex
9488
// object in the module loader instance.
9589
this._mappedModuleNames = Object.create(null);

0 commit comments

Comments
 (0)