From eb9879577c684ac6ad16b03eb172ced1fc86a8df Mon Sep 17 00:00:00 2001 From: Armando Andini Date: Thu, 5 Dec 2024 08:57:36 -0300 Subject: [PATCH] Make arguments of Task.run() optional, defaulting to empty object --- .../src/internal/core/tasks/resolved-task.ts | 2 +- v-next/hardhat/src/types/tasks.ts | 2 +- .../test/internal/core/tasks/task-manager.ts | 26 +++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/v-next/hardhat/src/internal/core/tasks/resolved-task.ts b/v-next/hardhat/src/internal/core/tasks/resolved-task.ts index 25c9b82757..1263a11b5b 100644 --- a/v-next/hardhat/src/internal/core/tasks/resolved-task.ts +++ b/v-next/hardhat/src/internal/core/tasks/resolved-task.ts @@ -93,7 +93,7 @@ export class ResolvedTask implements Task { * @throws HardhatError if the task is empty, a required argument is missing, * a argument has an invalid type, or the file actions can't be resolved. */ - public async run(taskArguments: TaskArguments): Promise { + public async run(taskArguments: TaskArguments = {}): Promise { if (this.isEmpty) { throw new HardhatError(HardhatError.ERRORS.TASK_DEFINITIONS.EMPTY_TASK, { task: formatTaskId(this.id), diff --git a/v-next/hardhat/src/types/tasks.ts b/v-next/hardhat/src/types/tasks.ts index ef951b496b..22e994790e 100644 --- a/v-next/hardhat/src/types/tasks.ts +++ b/v-next/hardhat/src/types/tasks.ts @@ -387,7 +387,7 @@ export interface Task { /** * Runs a task. */ - run(taskArguments: TaskArguments): Promise; + run(taskArguments?: TaskArguments): Promise; } /** diff --git a/v-next/hardhat/test/internal/core/tasks/task-manager.ts b/v-next/hardhat/test/internal/core/tasks/task-manager.ts index d73aecc47d..296ee080e9 100644 --- a/v-next/hardhat/test/internal/core/tasks/task-manager.ts +++ b/v-next/hardhat/test/internal/core/tasks/task-manager.ts @@ -1474,7 +1474,7 @@ describe("TaskManagerImplementation", () => { const task1 = hre.tasks.getTask("task1"); assert.equal(taskRun, false); - await task1.run({}); + await task1.run(); assert.equal(taskRun, true); }); @@ -1496,7 +1496,7 @@ describe("TaskManagerImplementation", () => { ); const task1 = hre.tasks.getTask("task1"); - const result = await task1.run({}); + const result = await task1.run(); assert.equal(result, "task run successfully"); }); @@ -1530,7 +1530,7 @@ describe("TaskManagerImplementation", () => { const task1 = hre.tasks.getTask("task1"); assert.equal(taskRun, false); assert.equal(overrideTaskRun, false); - await task1.run({}); + await task1.run(); assert.equal(taskRun, true); assert.equal(overrideTaskRun, true); }); @@ -1588,7 +1588,7 @@ describe("TaskManagerImplementation", () => { assert.equal(override1TaskRun, false); assert.equal(override2TaskRun, false); assert.equal(override3TaskRun, false); - await task1.run({}); + await task1.run(); assert.equal(taskRun, true); assert.equal(override1TaskRun, true); assert.equal(override2TaskRun, true); @@ -1624,7 +1624,7 @@ describe("TaskManagerImplementation", () => { const task1 = hre.tasks.getTask("task1"); assert.equal(taskRun, false); assert.equal(overrideTaskRun, false); - await task1.run({}); + await task1.run(); assert.equal(taskRun, false); assert.equal(overrideTaskRun, true); }); @@ -1739,7 +1739,7 @@ describe("TaskManagerImplementation", () => { ); const task1 = hre.tasks.getTask("task1"); - await task1.run({}); + await task1.run(); }); it("should run an empty task that was overriden", async () => { @@ -1769,7 +1769,7 @@ describe("TaskManagerImplementation", () => { const task1 = hre.tasks.getTask("task1"); assert.equal(overrideTaskRun, false); - await task1.run({}); + await task1.run(); assert.equal(overrideTaskRun, true); }); @@ -1857,7 +1857,7 @@ describe("TaskManagerImplementation", () => { const task1 = hre.tasks.getTask("task1"); await assertRejectsWithHardhatError( - task1.run({}), + task1.run(), HardhatError.ERRORS.TASK_DEFINITIONS.EMPTY_TASK, { task: "task1", @@ -2057,7 +2057,7 @@ describe("TaskManagerImplementation", () => { const task1 = hre.tasks.getTask("task1"); await assertRejectsWithHardhatError( - task1.run({}), + task1.run(), HardhatError.ERRORS.TASK_DEFINITIONS.INVALID_ACTION_URL, { action: "file://not-a-module", @@ -2095,7 +2095,7 @@ describe("TaskManagerImplementation", () => { ); await assertRejectsWithHardhatError( - hre.tasks.getTask("task1").run({}), + hre.tasks.getTask("task1").run(), HardhatError.ERRORS.PLUGINS.PLUGIN_NOT_INSTALLED, { pluginId: "plugin1", @@ -2129,7 +2129,7 @@ describe("TaskManagerImplementation", () => { ); await assertRejectsWithHardhatError( - hre.tasks.getTask("task1").run({}), + hre.tasks.getTask("task1").run(), HardhatError.ERRORS.PLUGINS.PLUGIN_NOT_INSTALLED, { pluginId: "plugin2", @@ -2160,7 +2160,7 @@ describe("TaskManagerImplementation", () => { const task1 = hre.tasks.getTask("task1"); await assertRejectsWithHardhatError( - task1.run({}), + task1.run(), HardhatError.ERRORS.TASK_DEFINITIONS.INVALID_ACTION, { action: actionUrl, @@ -2192,7 +2192,7 @@ describe("TaskManagerImplementation", () => { const task1 = hre.tasks.getTask("task1"); await assertRejectsWithHardhatError( - task1.run({}), + task1.run(), HardhatError.ERRORS.TASK_DEFINITIONS.INVALID_ACTION, { action: actionUrl,