Skip to content

Commit cbac939

Browse files
authored
Merge pull request #6186 from NomicFoundation/solidity-test-file
feat: add testFiles option to test solidity
2 parents e482233 + d0cc44c commit cbac939

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

v-next/hardhat/src/internal/builtin-plugins/solidity-test/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const hardhatPlugin: HardhatPlugin = {
1111
},
1212
tasks: [
1313
task(["test", "solidity"], "Run the Solidity tests")
14+
.addVariadicArgument({
15+
name: "testFiles",
16+
description: "An optional list of files to test",
17+
defaultValue: [],
18+
})
1419
.setAction(import.meta.resolve("./task-action.js"))
1520
.build(),
1621
],

v-next/hardhat/src/internal/builtin-plugins/solidity-test/task-action.ts

+25-15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { SolidityTestRunnerConfigArgs } from "@ignored/edr";
77
import { finished } from "node:stream/promises";
88

99
import { getAllFilesMatching } from "@ignored/hardhat-vnext-utils/fs";
10+
import { resolveFromRoot } from "@ignored/hardhat-vnext-utils/path";
1011
import { createNonClosingWriter } from "@ignored/hardhat-vnext-utils/stream";
1112

1213
import { shouldMergeCompilationJobs } from "../solidity/build-profiles.js";
@@ -22,25 +23,34 @@ import {
2223
import { testReporter } from "./reporter.js";
2324
import { run } from "./runner.js";
2425

25-
// eslint-disable-next-line @typescript-eslint/no-empty-interface -- the interface is expected to be expanded in the future
26-
interface TestActionArguments {}
26+
interface TestActionArguments {
27+
testFiles: string[];
28+
}
2729

2830
const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
29-
{},
31+
{ testFiles },
3032
hre,
3133
) => {
32-
// NOTE: A test file is either a file with a `.sol` extension in the `tests.solidity`
33-
// directory or a file with a `.t.sol` extension in the `sources.solidity` directory
34-
const rootFilePaths = (
35-
await Promise.all([
36-
getAllFilesMatching(hre.config.paths.tests.solidity, (f) =>
37-
f.endsWith(".sol"),
38-
),
39-
...hre.config.paths.sources.solidity.map(async (dir) => {
40-
return getAllFilesMatching(dir, (f) => f.endsWith(".t.sol"));
41-
}),
42-
])
43-
).flat(1);
34+
let rootFilePaths: string[];
35+
36+
if (testFiles.length > 0) {
37+
rootFilePaths = testFiles.map((f) =>
38+
resolveFromRoot(hre.config.paths.root, f),
39+
);
40+
} else {
41+
// NOTE: A test file is either a file with a `.sol` extension in the `tests.solidity`
42+
// directory or a file with a `.t.sol` extension in the `sources.solidity` directory
43+
rootFilePaths = (
44+
await Promise.all([
45+
getAllFilesMatching(hre.config.paths.tests.solidity, (f) =>
46+
f.endsWith(".sol"),
47+
),
48+
...hre.config.paths.sources.solidity.map(async (dir) => {
49+
return getAllFilesMatching(dir, (f) => f.endsWith(".t.sol"));
50+
}),
51+
])
52+
).flat(1);
53+
}
4454

4555
const buildOptions: BuildOptions = {
4656
force: false,

0 commit comments

Comments
 (0)