Skip to content

Commit 29c470e

Browse files
committed
create hre locally in test
1 parent 6870318 commit 29c470e

File tree

5 files changed

+16
-34
lines changed

5 files changed

+16
-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

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

44
import { HardhatError } from "@ignored/hardhat-vnext-errors";
55
import {
@@ -11,16 +11,16 @@ describe("Hardhat Mocha plugin", () => {
1111
describe("Success", () => {
1212
useFixtureProject("test-project");
1313

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

19-
_resetGlobalHardhatRuntimeEnvironment();
20-
});
19+
const hardhatConfig = await import(
20+
"./fixture-projects/test-project/hardhat.config.js"
21+
);
2122

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

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

@@ -31,21 +31,20 @@ describe("Hardhat Mocha plugin", () => {
3131
describe("Failure", () => {
3232
useFixtureProject("invalid-mocha-config");
3333

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

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

42+
const hardhatConfig = await import(
43+
"./fixture-projects/invalid-mocha-config/hardhat.config.js"
44+
);
45+
4646
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"),
47+
createHardhatRuntimeEnvironment(hardhatConfig.default),
4948
HardhatError.ERRORS.GENERAL.INVALID_CONFIG,
5049
{ errors },
5150
);

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)