UNPKG

1.26 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.resetHardhatContext = void 0;
4const context_1 = require("./context");
5// This function isn't meant to be used during the Hardhat execution,
6// but rather to reset Hardhat in between tests.
7function resetHardhatContext() {
8 if (context_1.HardhatContext.isCreated()) {
9 const ctx = context_1.HardhatContext.getHardhatContext();
10 if (ctx.environment !== undefined) {
11 const globalAsAny = global;
12 for (const key of Object.keys(ctx.environment)) {
13 globalAsAny.hre = undefined;
14 globalAsAny[key] = undefined;
15 }
16 }
17 const filesLoadedDuringConfig = ctx.getFilesLoadedDuringConfig();
18 filesLoadedDuringConfig.forEach(unloadModule);
19 context_1.HardhatContext.deleteHardhatContext();
20 }
21 // Unload all the hardhat's entry-points.
22 unloadModule("../register");
23 unloadModule("./cli/cli");
24 unloadModule("./lib/hardhat-lib");
25}
26exports.resetHardhatContext = resetHardhatContext;
27function unloadModule(path) {
28 try {
29 delete require.cache[require.resolve(path)];
30 }
31 catch {
32 // module wasn't loaded
33 }
34}
35//# sourceMappingURL=reset.js.map
\No newline at end of file