Skip to content

Commit

Permalink
add grep option
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeyTM committed Aug 19, 2024
1 parent 79c2c99 commit fc16205
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions v-next/hardhat-node-test-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
],
Expand Down
11 changes: 10 additions & 1 deletion v-next/hardhat-node-test-runner/src/task-action.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 {
Expand Down Expand Up @@ -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<TestActionArguments> = async (
{ testFiles, only },
{ testFiles, only, grep },
hre,
) => {
const files = await getTestFiles(testFiles, hre.config);
Expand All @@ -58,6 +60,13 @@ const testWithHardhat: NewTaskActionFunction<TestActionArguments> = async (

async function runTests(): Promise<number> {
let failures = 0;

const nodeTestOptions: LastParameter<typeof run> = { files, only };

if (grep !== "") {
nodeTestOptions.testNamePatterns = grep;
}

const reporterStream = run({ files, only })
.on("test:fail", (event) => {
if (event.details.type === "suite") {
Expand Down

0 comments on commit fc16205

Please sign in to comment.