diff --git a/v-next/hardhat-node-test-runner/src/index.ts b/v-next/hardhat-node-test-runner/src/index.ts index 83f934a8945..4952fbcbc16 100644 --- a/v-next/hardhat-node-test-runner/src/index.ts +++ b/v-next/hardhat-node-test-runner/src/index.ts @@ -15,6 +15,11 @@ const hardhatPlugin: HardhatPlugin = { name: "only", description: "Run all tests marked with .only", }) + .addOption({ + name: "grep", + description: "Only run tests matching the given string or regexp", + defaultValue: "", + }) .setAction(import.meta.resolve("./task-action.js")) .build(), ], diff --git a/v-next/hardhat-node-test-runner/src/task-action.ts b/v-next/hardhat-node-test-runner/src/task-action.ts index 4793d631f91..9e69162b130 100644 --- a/v-next/hardhat-node-test-runner/src/task-action.ts +++ b/v-next/hardhat-node-test-runner/src/task-action.ts @@ -1,5 +1,6 @@ import type { HardhatConfig } from "@ignored/hardhat-vnext/types/config"; import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks"; +import type { LastParameter } from "@ignored/hardhat-vnext/types/utils"; import { finished } from "node:stream/promises"; import { run } from "node:test"; @@ -11,6 +12,7 @@ import { getAllFilesMatching } from "@ignored/hardhat-vnext-utils/fs"; interface TestActionArguments { testFiles: string[]; only: boolean; + grep: string; } function isTypescriptFile(path: string): boolean { @@ -48,7 +50,7 @@ async function getTestFiles( * Note that we are testing this manually for now as you can't run a node:test within a node:test */ const testWithHardhat: NewTaskActionFunction = async ( - { testFiles, only }, + { testFiles, only, grep }, hre, ) => { const files = await getTestFiles(testFiles, hre.config); @@ -58,6 +60,13 @@ const testWithHardhat: NewTaskActionFunction = async ( async function runTests(): Promise { let failures = 0; + + const nodeTestOptions: LastParameter = { files, only }; + + if (grep !== "") { + nodeTestOptions.testNamePatterns = grep; + } + const reporterStream = run({ files, only }) .on("test:fail", (event) => { if (event.details.type === "suite") {