Skip to content

Commit 03d4eac

Browse files
authored
Merge pull request #7698 from NomicFoundation/typechain-imports-hardhat-ethers
Add `hardhat-ethers` to the mocha+ethers devDependencies
2 parents 6080ec7 + ea2eb88 commit 03d4eac

File tree

4 files changed

+43
-26
lines changed

4 files changed

+43
-26
lines changed

.changeset/gentle-seals-tan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
Fix the initialization of the Mocha and Ethers sample project when using pnpm

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v-next/hardhat-toolbox-mocha-ethers/test/index.ts

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,40 @@ describe("hardhat-toolbox-mocha-ethers", function () {
1212
useFixtureProject("toolbox");
1313

1414
it("should not throw because all the plugins should exist", async function () {
15-
const hardhatConfig = await import(
16-
pathToFileURL(path.join(process.cwd(), "hardhat.config.js")).href
17-
);
18-
19-
const hre = await createHardhatRuntimeEnvironment(hardhatConfig.default);
20-
21-
// This will check that the node test runner is available
22-
assert.notEqual(hre.tasks.getTask(["test", "mocha"]), undefined);
23-
24-
// This will check that ethers, chai and network helpers are available
25-
await hre.tasks.getTask(["run"]).run({ script: "scripts/script.ts" });
26-
27-
// This will check that the keystore is available
28-
assert.notEqual(hre.tasks.getTask(["keystore", "list"]), undefined);
29-
30-
// This will check that ignition is available
31-
assert.notEqual(hre.tasks.getTask(["ignition"]), undefined);
32-
33-
// This will check that typechain is available
34-
await remove(path.join(process.cwd(), "types")); // Be sure the folder doesn't exist
35-
await hre.tasks.getTask(["build"]).run();
36-
await exists(path.join(process.cwd(), "types"));
37-
await remove(path.join(process.cwd(), "types"));
15+
try {
16+
const hardhatConfig = await import(
17+
pathToFileURL(path.join(process.cwd(), "hardhat.config.js")).href
18+
);
19+
20+
const hre = await createHardhatRuntimeEnvironment(
21+
hardhatConfig.default,
22+
);
23+
24+
// This will check that the node test runner is available
25+
assert.notEqual(hre.tasks.getTask(["test", "mocha"]), undefined);
26+
27+
// This will check that ethers, chai and network helpers are available
28+
await hre.tasks.getTask(["run"]).run({ script: "scripts/script.ts" });
29+
30+
// This will check that the keystore is available
31+
assert.notEqual(hre.tasks.getTask(["keystore", "list"]), undefined);
32+
33+
// This will check that ignition is available
34+
assert.notEqual(hre.tasks.getTask(["ignition"]), undefined);
35+
36+
// This will check that typechain is available
37+
await remove(path.join(process.cwd(), "types")); // Be sure the folder doesn't exist
38+
39+
await hre.tasks.getTask(["build"]).run();
40+
assert.equal(await exists(path.join(process.cwd(), "types")), true);
41+
} finally {
42+
// We need to make sure we remove it, because the generated files
43+
// don't compile with --isolatedDeclarations and otherwise break the
44+
// build process
45+
if (await exists(path.join(process.cwd(), "types"))) {
46+
await remove(path.join(process.cwd(), "types"));
47+
}
48+
}
3849
});
3950
});
4051
});

v-next/hardhat/templates/hardhat-3/02-mocha-ethers/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"devDependencies": {
88
"hardhat": "workspace:^3.0.14",
99
"@nomicfoundation/hardhat-toolbox-mocha-ethers": "workspace:^3.0.1",
10+
"@nomicfoundation/hardhat-ethers": "workspace:^4.0.2",
1011
"@nomicfoundation/hardhat-ignition": "workspace:^3.0.5",
1112
"@types/chai": "^4.2.0",
1213
"@types/chai-as-promised": "^8.0.1",

0 commit comments

Comments
 (0)