|
| 1 | +import type { HardhatRuntimeEnvironment } from "@ignored/hardhat-vnext-core/types/hre"; |
| 2 | + |
| 3 | +import assert from "node:assert/strict"; |
| 4 | +import { before, describe, it } from "node:test"; |
| 5 | + |
| 6 | +import { ensureError } from "@ignored/hardhat-vnext-utils/error"; |
| 7 | + |
| 8 | +import { createHardhatRuntimeEnvironment } from "../../../../src/hre.js"; |
| 9 | +import consoleAction from "../../../../src/internal/builtin-plugins/console/task-action.js"; |
| 10 | +import { useFixtureProject } from "../../../helpers/project.js"; |
| 11 | + |
| 12 | +describe("console/task-action", function () { |
| 13 | + let hre: HardhatRuntimeEnvironment; |
| 14 | + |
| 15 | + before(async function () { |
| 16 | + hre = await createHardhatRuntimeEnvironment({}); |
| 17 | + }); |
| 18 | + |
| 19 | + describe("javascript", function () { |
| 20 | + useFixtureProject("run-js-script"); |
| 21 | + |
| 22 | + it("should throw inside the console if script does not exist", async function () { |
| 23 | + const replServer = await consoleAction( |
| 24 | + { commands: ['await import("./scripts/non-existent.js");', ".exit"] }, |
| 25 | + hre, |
| 26 | + ); |
| 27 | + ensureError(replServer.lastError); |
| 28 | + }); |
| 29 | + |
| 30 | + it("should run a script inside the console successfully", async function () { |
| 31 | + const replServer = await consoleAction( |
| 32 | + { commands: ['await import("./scripts/success.js");', ".exit"] }, |
| 33 | + hre, |
| 34 | + ); |
| 35 | + assert.equal(replServer.lastError, undefined); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should throw inside the console if the script throws", async function () { |
| 39 | + const replServer = await consoleAction( |
| 40 | + { commands: ['await import("./scripts/throws.js");', ".exit"] }, |
| 41 | + hre, |
| 42 | + ); |
| 43 | + ensureError(replServer.lastError); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + describe("typescript", function () { |
| 48 | + useFixtureProject("run-ts-script"); |
| 49 | + |
| 50 | + it("should throw inside the console if script does not exist", async function () { |
| 51 | + const replServer = await consoleAction( |
| 52 | + { commands: ['await import("./scripts/non-existent.ts");', ".exit"] }, |
| 53 | + hre, |
| 54 | + ); |
| 55 | + ensureError(replServer.lastError); |
| 56 | + }); |
| 57 | + |
| 58 | + it("should run a script inside the console successfully", async function () { |
| 59 | + const replServer = await consoleAction( |
| 60 | + { commands: ['await import("./scripts/success.ts");', ".exit"] }, |
| 61 | + hre, |
| 62 | + ); |
| 63 | + assert.equal(replServer.lastError, undefined); |
| 64 | + }); |
| 65 | + |
| 66 | + it("should throw inside the console if the script throws", async function () { |
| 67 | + const replServer = await consoleAction( |
| 68 | + { commands: ['await import("./scripts/throws.ts");', ".exit"] }, |
| 69 | + hre, |
| 70 | + ); |
| 71 | + ensureError(replServer.lastError); |
| 72 | + }); |
| 73 | + }); |
| 74 | +}); |
0 commit comments