Skip to content

Commit

Permalink
Merge pull request #6016 from NomicFoundation/task-run-arguments-opti…
Browse files Browse the repository at this point in the history
…onal

Make arguments of Task.run() optional, defaulting to empty object
  • Loading branch information
antico5 authored Dec 13, 2024
2 parents 2fb23a7 + eb98795 commit d2b3bc8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion v-next/hardhat/src/internal/core/tasks/resolved-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
public async run(taskArguments: TaskArguments = {}): Promise<any> {
if (this.isEmpty) {
throw new HardhatError(HardhatError.ERRORS.TASK_DEFINITIONS.EMPTY_TASK, {
task: formatTaskId(this.id),
Expand Down
2 changes: 1 addition & 1 deletion v-next/hardhat/src/types/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export interface Task {
/**
* Runs a task.
*/
run(taskArguments: TaskArguments): Promise<any>;
run(taskArguments?: TaskArguments): Promise<any>;
}

/**
Expand Down
26 changes: 13 additions & 13 deletions v-next/hardhat/test/internal/core/tasks/task-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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");
});

Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d2b3bc8

Please sign in to comment.