Skip to content

Commit

Permalink
create hre locally in test
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeyTM committed Aug 27, 2024
1 parent 6870318 commit 29c470e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 34 deletions.
4 changes: 0 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions v-next/example-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,5 @@
"mocha": "^10.0.0",
"prettier": "3.2.5",
"typescript": "~5.5.0"
},
"dependencies": {
"tsx": "^4.11.0"
}
}
33 changes: 16 additions & 17 deletions v-next/hardhat-mocha-test-runner/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "node:assert/strict";
import { describe, it, afterEach } from "node:test";
import { describe, it } from "node:test";

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

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

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

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

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

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

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

_resetGlobalHardhatRuntimeEnvironment();
});

it("should fail", async () => {
const errors =
"\t* Config error in config.mocha.delay: Expected boolean, received number";

const hardhatConfig = await import(
"./fixture-projects/invalid-mocha-config/hardhat.config.js"
);

await assertRejectsWithHardhatError(
// @ts-expect-error -- we need to invalidate the import cache to re-import the HRE
import("@ignored/hardhat-vnext?config=invalid"),
createHardhatRuntimeEnvironment(hardhatConfig.default),
HardhatError.ERRORS.GENERAL.INVALID_CONFIG,
{ errors },
);
Expand Down
1 change: 0 additions & 1 deletion v-next/hardhat-zod-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"zod": "^3.23.8"
},
"peerDependencies": {
"@ignored/hardhat-vnext-core": "workspace:^3.0.0-next.2",
"zod": "^3.23.8"
}
}
9 changes: 0 additions & 9 deletions v-next/hardhat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { createHardhatRuntimeEnvironment } from "./hre.js";
import {
getGlobalHardhatRuntimeEnvironment,
setGlobalHardhatRuntimeEnvironment,
resetGlobalHardhatRuntimeEnvironment,
} from "./internal/global-hre-instance.js";
import { importUserConfig } from "./internal/helpers/config-loading.js";

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

// We need to re-export this function so that plugins can use it.
export const _resetGlobalHardhatRuntimeEnvironment: typeof resetGlobalHardhatRuntimeEnvironment =
function (): void {
maybeHre = undefined;

resetGlobalHardhatRuntimeEnvironment();
};

export default hre;

0 comments on commit 29c470e

Please sign in to comment.