Skip to content

Commit 7066c7b

Browse files
committed
add grep option
1 parent 0708f55 commit 7066c7b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

v-next/hardhat-node-test-runner/src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ const hardhatPlugin: HardhatPlugin = {
1515
name: "only",
1616
description: "Run all tests marked with .only",
1717
})
18+
.addOption({
19+
name: "grep",
20+
description: "Only run tests matching the given string or regexp",
21+
defaultValue: "",
22+
})
1823
.setAction(import.meta.resolve("./task-action.js"))
1924
.build(),
2025
],

v-next/hardhat-node-test-runner/src/task-action.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { HardhatConfig } from "@ignored/hardhat-vnext/types/config";
22
import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks";
3+
import type { LastParameter } from "@ignored/hardhat-vnext/types/utils";
34

45
import { finished } from "node:stream/promises";
56
import { run } from "node:test";
@@ -11,6 +12,7 @@ import { getAllFilesMatching } from "@ignored/hardhat-vnext-utils/fs";
1112
interface TestActionArguments {
1213
testFiles: string[];
1314
only: boolean;
15+
grep: string;
1416
}
1517

1618
function isTypescriptFile(path: string): boolean {
@@ -48,7 +50,7 @@ async function getTestFiles(
4850
* Note that we are testing this manually for now as you can't run a node:test within a node:test
4951
*/
5052
const testWithHardhat: NewTaskActionFunction<TestActionArguments> = async (
51-
{ testFiles, only },
53+
{ testFiles, only, grep },
5254
hre,
5355
) => {
5456
const files = await getTestFiles(testFiles, hre.config);
@@ -58,6 +60,13 @@ const testWithHardhat: NewTaskActionFunction<TestActionArguments> = async (
5860

5961
async function runTests(): Promise<number> {
6062
let failures = 0;
63+
64+
const nodeTestOptions: LastParameter<typeof run> = { files, only };
65+
66+
if (grep !== "") {
67+
nodeTestOptions.testNamePatterns = grep;
68+
}
69+
6170
const reporterStream = run({ files, only })
6271
.on("test:fail", (event) => {
6372
if (event.details.type === "suite") {

0 commit comments

Comments
 (0)