Skip to content

Commit 31970e0

Browse files
committed
Update hardhat-node-test-runner
1 parent e6fee07 commit 31970e0

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

packages/hardhat-node-test-runner/src/task-action.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ const testWithHardhat: NewTaskActionFunction<TestActionArguments> = async (
6969
setGlobalOptionsAsEnvVariables(hre.globalOptions);
7070

7171
if (!noCompile) {
72-
await hre.tasks.getTask("build").run({
73-
noTests: true,
74-
});
72+
const noTests = hre.config.solidity.splitTestsCompilation;
73+
await hre.tasks.getTask("build").run({ noTests });
7574
console.log();
7675
}
7776

packages/hardhat-node-test-runner/test/index.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import assert from "node:assert/strict";
22
import { describe, it } from "node:test";
33

44
import { useFixtureProject } from "@nomicfoundation/hardhat-test-utils";
5+
import { overrideTask } from "hardhat/config";
56
import { createHardhatRuntimeEnvironment } from "hardhat/hre";
67

8+
import HardhatNodeTestRunnerPlugin from "../src/index.js";
9+
710
describe("Hardhat Node plugin", () => {
811
useFixtureProject("test-project");
912

@@ -44,4 +47,71 @@ describe("Hardhat Node plugin", () => {
4447
process.env.NODE_ENV = nodeEnv;
4548
}
4649
});
50+
51+
describe("build invocation", () => {
52+
function buildArgCaptor() {
53+
const buildArgs: any[] = [];
54+
const buildOverride = overrideTask("build")
55+
.setAction(async () => {
56+
return {
57+
default: (args: any) => {
58+
buildArgs.push(args);
59+
return { contractRootPaths: [], testRootPaths: [] };
60+
},
61+
};
62+
})
63+
.build();
64+
return { buildArgs, buildOverride };
65+
}
66+
67+
it("should call build without noTests when splitTestsCompilation is false", async () => {
68+
const { buildArgs, buildOverride } = buildArgCaptor();
69+
const hre = await createHardhatRuntimeEnvironment({
70+
plugins: [HardhatNodeTestRunnerPlugin],
71+
tasks: [buildOverride],
72+
});
73+
74+
// The task may throw because of the ESM re-run guard, but we only
75+
// care about the build invocation args captured before that point.
76+
try {
77+
await hre.tasks.getTask(["test", "nodejs"]).run({});
78+
} catch {}
79+
80+
assert.equal(buildArgs.length, 1);
81+
assert.equal(buildArgs[0].noTests, false);
82+
});
83+
84+
it("should call build with noTests when splitTestsCompilation is true", async () => {
85+
const { buildArgs, buildOverride } = buildArgCaptor();
86+
const hre = await createHardhatRuntimeEnvironment({
87+
solidity: {
88+
version: "0.8.28",
89+
splitTestsCompilation: true,
90+
},
91+
plugins: [HardhatNodeTestRunnerPlugin],
92+
tasks: [buildOverride],
93+
});
94+
95+
try {
96+
await hre.tasks.getTask(["test", "nodejs"]).run({});
97+
} catch {}
98+
99+
assert.equal(buildArgs.length, 1);
100+
assert.equal(buildArgs[0].noTests, true);
101+
});
102+
103+
it("should skip compilation when noCompile is true regardless of splitTestsCompilation", async () => {
104+
const { buildArgs, buildOverride } = buildArgCaptor();
105+
const hre = await createHardhatRuntimeEnvironment({
106+
plugins: [HardhatNodeTestRunnerPlugin],
107+
tasks: [buildOverride],
108+
});
109+
110+
try {
111+
await hre.tasks.getTask(["test", "nodejs"]).run({ noCompile: true });
112+
} catch {}
113+
114+
assert.equal(buildArgs.length, 0);
115+
});
116+
});
47117
});

0 commit comments

Comments
 (0)