Skip to content

Commit 67037d5

Browse files
committed
Fix tests
1 parent b396232 commit 67037d5

File tree

4 files changed

+68
-31
lines changed

4 files changed

+68
-31
lines changed

v-next/hardhat/test/internal/cli/helpers/getGlobalHelpString.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ GLOBAL OPTIONS:
196196
--config A Hardhat config file.
197197
--help Shows this message, or a task's help if its name is provided.
198198
--show-stack-traces Show stack traces (always enabled on CI servers).
199-
--version Shows hardhat's version.
200199
--user-option-1 userOption1 description.
201200
--user-option-2 userOption2 description.
201+
--version Shows hardhat's version.
202202
203203
To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help`;
204204

@@ -207,7 +207,7 @@ To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help`;
207207
});
208208

209209
describe("when there are tasks, subtasks and global options", function () {
210-
it("should return the global help string with the tasks, subtasks and global options", async function () {
210+
it("should return the global help string with the tasks, subtasks and global options, all sorted by name", async function () {
211211
const tasks: Map<string, Task> = new Map([
212212
[
213213
"task1",
@@ -293,9 +293,9 @@ GLOBAL OPTIONS:
293293
--config A Hardhat config file.
294294
--help Shows this message, or a task's help if its name is provided.
295295
--show-stack-traces Show stack traces (always enabled on CI servers).
296-
--version Shows hardhat's version.
297296
--user-option-1 userOption1 description.
298297
--user-option-2 userOption2 description.
298+
--version Shows hardhat's version.
299299
300300
To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help`;
301301

v-next/hardhat/test/internal/cli/helpers/getHelpString.ts

+31-18
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ To get help for a specific task run: npx hardhat task <SUBTASK> --help`;
4646

4747
describe("when the task is not empty", function () {
4848
describe("when there are options", function () {
49-
it("should return the task's help string", async function () {
49+
it("should return the task's help string with options sorted by name", async function () {
5050
const task: Task = {
5151
id: ["task"],
5252
description: "task description",
@@ -73,12 +73,12 @@ To get help for a specific task run: npx hardhat task <SUBTASK> --help`;
7373

7474
const expected = `${chalk.bold("task description")}
7575
76-
Usage: hardhat [GLOBAL OPTIONS] task [--option <STRING>] [--another-option]
76+
Usage: hardhat [GLOBAL OPTIONS] task [--another-option] [--option <STRING>]
7777
7878
OPTIONS:
7979
80-
--option An example option
8180
--another-option Another example option
81+
--option An example option
8282
8383
For global options help run: hardhat --help`;
8484

@@ -87,7 +87,7 @@ For global options help run: hardhat --help`;
8787
});
8888

8989
describe("when there are positional arguments", function () {
90-
it("should return the task's help string", async function () {
90+
it("should return the task's help string with options and positional arguments sorted by name, except in the usage string", async function () {
9191
const task: Task = {
9292
id: ["task"],
9393
description: "task description",
@@ -110,6 +110,12 @@ For global options help run: hardhat --help`;
110110
type: ArgumentType.STRING,
111111
isVariadic: false,
112112
},
113+
{
114+
name: "anotherPositionalArgument",
115+
description: "Another example positional argument",
116+
type: ArgumentType.STRING,
117+
isVariadic: false,
118+
},
113119
],
114120
pluginId: "task-plugin-id",
115121
subtasks: new Map(),
@@ -121,16 +127,17 @@ For global options help run: hardhat --help`;
121127

122128
const expected = `${chalk.bold("task description")}
123129
124-
Usage: hardhat [GLOBAL OPTIONS] task [--option <STRING>] [--another-option] [--] positionalArgument
130+
Usage: hardhat [GLOBAL OPTIONS] task [--another-option] [--option <STRING>] [--] positionalArgument anotherPositionalArgument
125131
126132
OPTIONS:
127133
128-
--option An example option
129-
--another-option Another example option
134+
--another-option Another example option
135+
--option An example option
130136
131137
POSITIONAL ARGUMENTS:
132138
133-
positionalArgument An example positional argument
139+
anotherPositionalArgument Another example positional argument
140+
positionalArgument An example positional argument
134141
135142
For global options help run: hardhat --help`;
136143

@@ -139,7 +146,7 @@ For global options help run: hardhat --help`;
139146
});
140147

141148
describe("when there are subtasks", function () {
142-
it("should return the task's help string", async function () {
149+
it("should return the task's help string with subtasks sorted by name", async function () {
143150
const task: Task = {
144151
id: ["task"],
145152
description: "task description",
@@ -164,10 +171,15 @@ For global options help run: hardhat --help`;
164171
},
165172
],
166173
pluginId: "task-plugin-id",
167-
subtasks: new Map().set("subtask", {
168-
id: ["task", "subtask"],
169-
description: "An example subtask",
170-
}),
174+
subtasks: new Map()
175+
.set("subtask", {
176+
id: ["task", "subtask"],
177+
description: "An example subtask",
178+
})
179+
.set("another-subtask", {
180+
id: ["task", "another-subtask"],
181+
description: "Another example subtask",
182+
}),
171183
isEmpty: false,
172184
run: async () => {},
173185
};
@@ -176,20 +188,21 @@ For global options help run: hardhat --help`;
176188

177189
const expected = `${chalk.bold("task description")}
178190
179-
Usage: hardhat [GLOBAL OPTIONS] task [--option <STRING>] [--another-option] [--] positionalArgument
191+
Usage: hardhat [GLOBAL OPTIONS] task [--another-option] [--option <STRING>] [--] positionalArgument
180192
181193
OPTIONS:
182194
183-
--option An example option
184-
--another-option Another example option
195+
--another-option Another example option
196+
--option An example option
185197
186198
POSITIONAL ARGUMENTS:
187199
188-
positionalArgument An example positional argument
200+
positionalArgument An example positional argument
189201
190202
AVAILABLE SUBTASKS:
191203
192-
task subtask An example subtask
204+
task another-subtask Another example subtask
205+
task subtask An example subtask
193206
194207
For global options help run: hardhat --help`;
195208

v-next/hardhat/test/internal/cli/helpers/utils.ts

+33-9
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,25 @@ describe("utils", function () {
196196
});
197197

198198
describe("getSection", function () {
199-
it("should return a section", function () {
199+
it("should return a section with items sorted by name", function () {
200200
const section = getSection(
201201
"Section Title",
202202
[
203203
{ name: "content", description: "content description" },
204204
{ name: "content2", description: "content description2" },
205205
{ name: "content3", description: "content description3" },
206+
{ name: "another-item", description: "content description4" },
206207
],
207-
14,
208+
18,
208209
);
209210

210211
const expected = `
211212
Section Title:
212213
213-
content content description
214-
content2 content description2
215-
content3 content description3
214+
another-item content description4
215+
content content description
216+
content2 content description2
217+
content3 content description3
216218
`;
217219

218220
assert.equal(section, expected);
@@ -221,7 +223,7 @@ Section Title:
221223

222224
describe("getUsageString", function () {
223225
describe("with a required positional argument", function () {
224-
it("should return a usage string", function () {
226+
it("should return a usage string with options sorted by name, preserving positional argument order", function () {
225227
const task: Task = {
226228
id: ["task"],
227229
description: "task description",
@@ -244,6 +246,12 @@ Section Title:
244246
type: ArgumentType.STRING,
245247
isVariadic: false,
246248
},
249+
{
250+
name: "anotherPositionalArgument",
251+
description: "Another example argument",
252+
type: ArgumentType.STRING,
253+
isVariadic: false,
254+
},
247255
],
248256
pluginId: "task-plugin-id",
249257
subtasks: new Map(),
@@ -271,17 +279,22 @@ Section Title:
271279
description: "An example argument",
272280
isRequired: true,
273281
},
282+
{
283+
name: "anotherPositionalArgument",
284+
description: "Another example argument",
285+
isRequired: true,
286+
},
274287
],
275288
);
276289

277-
const expected = `Usage: hardhat [GLOBAL OPTIONS] task [--option <STRING>] [--another-option] [--] positionalArgument`;
290+
const expected = `Usage: hardhat [GLOBAL OPTIONS] task [--another-option] [--option <STRING>] [--] positionalArgument anotherPositionalArgument`;
278291

279292
assert.equal(usageString, expected);
280293
});
281294
});
282295

283296
describe("with an optional positional argument", function () {
284-
it("should return a usage string", function () {
297+
it("should return a usage string with options sorted by name, preserving positional argument order", function () {
285298
const task: Task = {
286299
id: ["task"],
287300
description: "task description",
@@ -304,6 +317,12 @@ Section Title:
304317
type: ArgumentType.STRING,
305318
isVariadic: false,
306319
},
320+
{
321+
name: "anotherPositionalArgument",
322+
description: "Another example argument",
323+
type: ArgumentType.STRING,
324+
isVariadic: false,
325+
},
307326
],
308327
pluginId: "task-plugin-id",
309328
subtasks: new Map(),
@@ -331,10 +350,15 @@ Section Title:
331350
description: "An example argument",
332351
isRequired: false,
333352
},
353+
{
354+
name: "anotherPositionalArgument",
355+
description: "Another example argument",
356+
isRequired: false,
357+
},
334358
],
335359
);
336360

337-
const expected = `Usage: hardhat [GLOBAL OPTIONS] task [--option <STRING>] [--another-option] [--] [positionalArgument]`;
361+
const expected = `Usage: hardhat [GLOBAL OPTIONS] task [--another-option] [--option <STRING>] [--] [positionalArgument] [anotherPositionalArgument]`;
338362

339363
assert.equal(usageString, expected);
340364
});

v-next/hardhat/test/internal/cli/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ AVAILABLE TASKS:
225225
GLOBAL OPTIONS:
226226
227227
--config A Hardhat config file.
228+
--foo-plugin-flag A flag
228229
--help Shows this message, or a task's help if its name is provided.
229230
--show-stack-traces Show stack traces (always enabled on CI servers).
230231
--version Shows hardhat's version.
231-
--foo-plugin-flag A flag
232232
233233
To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help`;
234234

0 commit comments

Comments
 (0)