Skip to content

Commit 8c98257

Browse files
committed
create hre locally in test
1 parent 6870318 commit 8c98257

File tree

5 files changed

+17
-34
lines changed

5 files changed

+17
-34
lines changed

pnpm-lock.yaml

-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v-next/example-project/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,5 @@
2929
"mocha": "^10.0.0",
3030
"prettier": "3.2.5",
3131
"typescript": "~5.5.0"
32-
},
33-
"dependencies": {
34-
"tsx": "^4.11.0"
3532
}
3633
}

v-next/hardhat-mocha-test-runner/test/index.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import assert from "node:assert/strict";
2-
import { describe, it, afterEach } from "node:test";
2+
import path from "node:path";
3+
import { describe, it } from "node:test";
34

45
import { HardhatError } from "@ignored/hardhat-vnext-errors";
56
import {
@@ -11,16 +12,16 @@ describe("Hardhat Mocha plugin", () => {
1112
describe("Success", () => {
1213
useFixtureProject("test-project");
1314

14-
afterEach(async () => {
15-
const { _resetGlobalHardhatRuntimeEnvironment } = await import(
16-
"@ignored/hardhat-vnext"
15+
it("should work", async () => {
16+
const { createHardhatRuntimeEnvironment } = await import(
17+
"@ignored/hardhat-vnext/hre"
1718
);
1819

19-
_resetGlobalHardhatRuntimeEnvironment();
20-
});
20+
const hardhatConfig = await import(
21+
path.resolve(process.cwd(), "hardhat.config.ts")
22+
);
2123

22-
it("should work", async () => {
23-
const hre = await import("@ignored/hardhat-vnext");
24+
const hre = await createHardhatRuntimeEnvironment(hardhatConfig.default);
2425

2526
const result = await hre.tasks.getTask("test").run({});
2627

@@ -31,21 +32,20 @@ describe("Hardhat Mocha plugin", () => {
3132
describe("Failure", () => {
3233
useFixtureProject("invalid-mocha-config");
3334

34-
afterEach(async () => {
35-
const { _resetGlobalHardhatRuntimeEnvironment } = await import(
36-
"@ignored/hardhat-vnext"
35+
it("should fail", async () => {
36+
const { createHardhatRuntimeEnvironment } = await import(
37+
"@ignored/hardhat-vnext/hre"
3738
);
3839

39-
_resetGlobalHardhatRuntimeEnvironment();
40-
});
41-
42-
it("should fail", async () => {
4340
const errors =
4441
"\t* Config error in config.mocha.delay: Expected boolean, received number";
4542

43+
const hardhatConfig = await import(
44+
path.resolve(process.cwd(), "hardhat.config.ts")
45+
);
46+
4647
await assertRejectsWithHardhatError(
47-
// @ts-expect-error -- we need to invalidate the import cache to re-import the HRE
48-
import("@ignored/hardhat-vnext?config=invalid"),
48+
createHardhatRuntimeEnvironment(hardhatConfig.default),
4949
HardhatError.ERRORS.GENERAL.INVALID_CONFIG,
5050
{ errors },
5151
);

v-next/hardhat-zod-utils/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"zod": "^3.23.8"
6262
},
6363
"peerDependencies": {
64-
"@ignored/hardhat-vnext-core": "workspace:^3.0.0-next.2",
6564
"zod": "^3.23.8"
6665
}
6766
}

v-next/hardhat/src/index.ts

-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { createHardhatRuntimeEnvironment } from "./hre.js";
1212
import {
1313
getGlobalHardhatRuntimeEnvironment,
1414
setGlobalHardhatRuntimeEnvironment,
15-
resetGlobalHardhatRuntimeEnvironment,
1615
} from "./internal/global-hre-instance.js";
1716
import { importUserConfig } from "./internal/helpers/config-loading.js";
1817

@@ -39,12 +38,4 @@ export const globalOptions: GlobalOptions = hre.globalOptions;
3938
export const hooks: HookManager = hre.hooks;
4039
export const interruptions: UserInterruptionManager = hre.interruptions;
4140

42-
// We need to re-export this function so that plugins can use it.
43-
export const _resetGlobalHardhatRuntimeEnvironment: typeof resetGlobalHardhatRuntimeEnvironment =
44-
function (): void {
45-
maybeHre = undefined;
46-
47-
resetGlobalHardhatRuntimeEnvironment();
48-
};
49-
5041
export default hre;

0 commit comments

Comments
 (0)