Skip to content

Commit

Permalink
does having a teardown make a difference?
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Apr 27, 2020
1 parent c803545 commit bdae3ac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/jest-runner/src/runTest.ts
Expand Up @@ -300,6 +300,8 @@ async function runTestInternal(
});
} finally {
await environment.teardown();
// this function might be missing
runtime.teardown?.();

sourcemapSupport.resetRetrieveHandlers();
}
Expand Down
24 changes: 24 additions & 0 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -843,6 +843,30 @@ class Runtime {
this._moduleMocker.clearAllMocks();
}

teardown(): void {
this.resetAllMocks();
this.resetAllMocks();

this._cacheFS.clear();
this._internalModuleRegistry.clear();
this._mockFactories.clear();
this._mockMetaDataCache.clear();
this._mockRegistry.clear();
this._isolatedMockRegistry?.clear();
this._isolatedModuleRegistry?.clear();
this._moduleRegistry.clear();
this._esmoduleRegistry.clear();
this._shouldMockModuleCache.clear();
this._shouldUnmockTransitiveDependenciesCache.clear();
this._sourceMapRegistry.clear();
this._fileTransforms.clear();
this._v8CoverageResult = [];
this._transitiveShouldMock.clear();
this._virtualMocks.clear();
this._moduleImplementation = undefined;
this.jestObjectCaches.clear();
}

private _resolveModule(from: Config.Path, to?: string) {
return to ? this._resolver.resolveModule(from, to) : from;
}
Expand Down

0 comments on commit bdae3ac

Please sign in to comment.