Skip to content

Commit 8feb622

Browse files
committed
update imports and fix redundant testing
1 parent 045ea1d commit 8feb622

File tree

3 files changed

+29
-35
lines changed

3 files changed

+29
-35
lines changed

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import type { HardhatPlugin } from "@nomicfoundation/hardhat-core/types/plugins"
22

33
import { ParameterType, task } from "@nomicfoundation/hardhat-core/config";
44

5-
import { runScriptWithHardhat } from "./runScriptWithHardhat.js";
6-
75
export default {
86
id: "run",
97
tasks: [
@@ -17,7 +15,7 @@ export default {
1715
name: "noCompile",
1816
description: "Don't compile before running this task",
1917
})
20-
.setAction(runScriptWithHardhat)
18+
.setAction(import.meta.resolve("./runScriptWithHardhat.js"))
2119
.build(),
2220
],
2321
} satisfies HardhatPlugin;

v-next/hardhat/src/internal/builtin-plugins/run/runScriptWithHardhat.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "@nomicfoundation/hardhat-errors";
1010
import { exists } from "@nomicfoundation/hardhat-utils/fs";
1111

12-
export const runScriptWithHardhat: NewTaskActionFunction = async (
12+
const runScriptWithHardhat: NewTaskActionFunction = async (
1313
{ script, noCompile },
1414
_hre,
1515
) => {
@@ -55,3 +55,5 @@ export const runScriptWithHardhat: NewTaskActionFunction = async (
5555
throw error;
5656
}
5757
};
58+
59+
export default runScriptWithHardhat;

v-next/hardhat/test/src/internal/builtin-plugins/run/runScriptWIthHardhat.ts

+25-31
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { before, describe, it } from "node:test";
66
import { createHardhatRuntimeEnvironment } from "@nomicfoundation/hardhat-core";
77
import { HardhatError } from "@nomicfoundation/hardhat-errors";
88

9-
import { runScriptWithHardhat } from "../../../../../src/internal/builtin-plugins/run/runScriptWithHardhat.js";
9+
import runScriptWithHardhat from "../../../../../src/internal/builtin-plugins/run/runScriptWithHardhat.js";
1010
import { useFixtureProject } from "../../../../helpers/project.js";
1111

1212
describe("runScriptWithHardhat", function () {
@@ -17,28 +17,28 @@ describe("runScriptWithHardhat", function () {
1717
});
1818

1919
it("should throw if script is not a string", async function () {
20-
await assert.rejects(async () => {
21-
await runScriptWithHardhat({ script: 123, noCompile: false }, hre);
22-
}, /An internal invariant was violated: Expected script to be a string/);
20+
await assert.rejects(
21+
runScriptWithHardhat({ script: 123, noCompile: false }, hre),
22+
/An internal invariant was violated: Expected script to be a string/,
23+
);
2324
});
2425

2526
it("should throw if noCompile is not a boolean", async function () {
26-
await assert.rejects(async () => {
27-
await runScriptWithHardhat({ script: "script.js", noCompile: 123 }, hre);
28-
}, /An internal invariant was violated: Expected noCompile to be a boolean/);
27+
await assert.rejects(
28+
runScriptWithHardhat({ script: "script.js", noCompile: 123 }, hre),
29+
/An internal invariant was violated: Expected noCompile to be a boolean/,
30+
);
2931
});
3032

3133
describe("javascript", function () {
3234
useFixtureProject("run-js-script");
3335

3436
it("should throw if script does not exist", async function () {
3537
await assert.rejects(
36-
async () => {
37-
await runScriptWithHardhat(
38-
{ script: "./scripts/non-existent.js", noCompile: false },
39-
hre,
40-
);
41-
},
38+
runScriptWithHardhat(
39+
{ script: "./scripts/non-existent.js", noCompile: false },
40+
hre,
41+
),
4242
new HardhatError(HardhatError.ERRORS.BUILTIN_TASKS.RUN_FILE_NOT_FOUND, {
4343
script: "./scripts/non-existent.js",
4444
}),
@@ -54,12 +54,10 @@ describe("runScriptWithHardhat", function () {
5454

5555
it("should throw if the script throws", async function () {
5656
await assert.rejects(
57-
async () => {
58-
await runScriptWithHardhat(
59-
{ script: "./scripts/throws.js", noCompile: false },
60-
hre,
61-
);
62-
},
57+
runScriptWithHardhat(
58+
{ script: "./scripts/throws.js", noCompile: false },
59+
hre,
60+
),
6361
new HardhatError(HardhatError.ERRORS.BUILTIN_TASKS.RUN_SCRIPT_ERROR, {
6462
script: "./scripts/throws.js",
6563
error: "broken script",
@@ -73,12 +71,10 @@ describe("runScriptWithHardhat", function () {
7371

7472
it("should throw if script does not exist", async function () {
7573
await assert.rejects(
76-
async () => {
77-
await runScriptWithHardhat(
78-
{ script: "./scripts/non-existent.ts", noCompile: false },
79-
hre,
80-
);
81-
},
74+
runScriptWithHardhat(
75+
{ script: "./scripts/non-existent.ts", noCompile: false },
76+
hre,
77+
),
8278
new HardhatError(HardhatError.ERRORS.BUILTIN_TASKS.RUN_FILE_NOT_FOUND, {
8379
script: "./scripts/non-existent.ts",
8480
}),
@@ -94,12 +90,10 @@ describe("runScriptWithHardhat", function () {
9490

9591
it("should throw if the script throws", async function () {
9692
await assert.rejects(
97-
async () => {
98-
await runScriptWithHardhat(
99-
{ script: "./scripts/throws.ts", noCompile: false },
100-
hre,
101-
);
102-
},
93+
runScriptWithHardhat(
94+
{ script: "./scripts/throws.ts", noCompile: false },
95+
hre,
96+
),
10397
new HardhatError(HardhatError.ERRORS.BUILTIN_TASKS.RUN_SCRIPT_ERROR, {
10498
script: "./scripts/throws.ts",
10599
error: "broken script",

0 commit comments

Comments
 (0)