Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move parseTaskAndArguments into the tests as a temporary fix for tests #5424

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 1 addition & 34 deletions v-next/hardhat/src/internal/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,39 +249,6 @@ export function parseTask(
return taskOrId;
}

/**
* Parses the task id and its arguments.
*
* @returns The task and its arguments, or an array with the unrecognized task
* id. If no task id is provided, an empty array is returned.
*/
// todo: this function isn't used anymore and needs to be removed
export function parseTaskAndArguments(
cliArguments: string[],
usedCliArguments: boolean[],
hre: HardhatRuntimeEnvironment,
):
| {
task: Task;
taskArguments: TaskArguments;
}
| string[] {
const taskOrId = parseTask(cliArguments, usedCliArguments, hre);
if (Array.isArray(taskOrId)) {
return taskOrId;
}

const task = taskOrId;

const taskArguments = parseTaskArguments(
cliArguments,
usedCliArguments,
task,
);

return { task, taskArguments };
}

function getTaskFromCliArguments(
cliArguments: string[],
usedCliArguments: boolean[],
Expand Down Expand Up @@ -341,7 +308,7 @@ function getTaskFromCliArguments(
return task;
}

function parseTaskArguments(
export function parseTaskArguments(
cliArguments: string[],
usedCliArguments: boolean[],
task: Task,
Expand Down
32 changes: 31 additions & 1 deletion v-next/hardhat/test/internal/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import type { HardhatRuntimeEnvironment } from "@nomicfoundation/hardhat-core/ty
import type {
NewTaskDefinition,
NewTaskDefinitionBuilder,
Task,
TaskArguments,
} from "@nomicfoundation/hardhat-core/types/tasks";

import assert from "node:assert/strict";
Expand All @@ -27,7 +29,8 @@ import {
main,
parseGlobalOptions,
parseHardhatSpecialArguments,
parseTaskAndArguments,
parseTask,
parseTaskArguments,
} from "../../../src/internal/cli/main.js";
import { resetHardhatRuntimeEnvironmentSingleton } from "../../../src/internal/hre-singleton.js";
import { getHardhatVersion } from "../../../src/internal/utils/package.js";
Expand Down Expand Up @@ -465,6 +468,33 @@ For global options help run: hardhat --help`;
});

describe("parseTaskAndArguments", function () {
// This is not an ideal way to test these two functions now that they're split apart,
// but I don't think it's worth the time to refactor all of these tests right now since the logic is the same.
function parseTaskAndArguments(
cliArguments: string[],
usedCliArguments: boolean[],
hreLocal: HardhatRuntimeEnvironment,
):
| {
task: Task;
taskArguments: TaskArguments;
}
| string[] {
const parsedTask = parseTask(cliArguments, usedCliArguments, hreLocal);
if (Array.isArray(parsedTask)) {
return parsedTask;
}

return {
task: parsedTask,
taskArguments: parseTaskArguments(
cliArguments,
usedCliArguments,
parsedTask,
),
};
}

let hre: HardhatRuntimeEnvironment;
let tasks: NewTaskDefinition[];
let subtasks: NewTaskDefinition[];
Expand Down