@@ -21,6 +21,7 @@ import {
21
21
} from "@nomicfoundation/hardhat-core/config" ;
22
22
import { HardhatError } from "@nomicfoundation/hardhat-errors" ;
23
23
import { isCi } from "@nomicfoundation/hardhat-utils/ci" ;
24
+ import chalk from "chalk" ;
24
25
25
26
import {
26
27
main ,
@@ -207,63 +208,83 @@ describe("main", function () {
207
208
} ) ;
208
209
} ) ;
209
210
210
- // TODO: as soon as the 'help task' is done, this test should be updated
211
211
describe ( "global help" , function ( ) {
212
212
useFixtureProject ( "cli/parsing/base-project" ) ;
213
213
214
- it . todo ( "should print the global help" , async function ( ) {
215
- const lines : string [ ] = [ ] ;
214
+ it ( "should print the global help" , async function ( ) {
215
+ let lines : string = "" ;
216
216
217
217
const command = "npx hardhat" ;
218
218
const cliArguments = command . split ( " " ) . slice ( 2 ) ;
219
219
220
220
await main ( cliArguments , ( msg ) => {
221
- lines . push ( msg ) ;
221
+ lines = msg ;
222
222
} ) ;
223
223
224
- assert . equal ( lines . length , 2 ) ;
225
- assert . equal ( lines [ 1 ] , "Global help" ) ;
224
+ const expected = `Hardhat version 3.0.0
225
+
226
+ Usage: hardhat [GLOBAL OPTIONS] <TASK> [SUBTASK] [TASK OPTIONS] [--] [TASK ARGUMENTS]
227
+
228
+ AVAILABLE TASKS:
229
+
230
+ example Example task
231
+ task A task that uses param1
232
+
233
+ GLOBAL OPTIONS:
234
+
235
+ --config A Hardhat config file.
236
+ --help Shows this message, or a task's help if its name is provided
237
+ --show-stack-traces Show stack traces (always enabled on CI servers).
238
+ --version Shows hardhat's version.
239
+
240
+ To get help for a specific task run: npx hardhat <TASK> [SUBTASK] --help` ;
241
+
242
+ assert . equal ( lines , expected ) ;
226
243
} ) ;
227
244
} ) ;
228
245
229
- // TODO: as soon as the 'help task' is done, this test should be updated
230
246
describe ( "subtask help" , function ( ) {
231
247
useFixtureProject ( "cli/parsing/subtask-help" ) ;
232
248
233
- it . todo (
234
- "should print an help message for the task's subtask" ,
235
- async function ( ) {
236
- const lines : string [ ] = [ ] ;
249
+ it ( "should print an help message for the task's subtask" , async function ( ) {
250
+ let lines : string = "" ;
237
251
238
- const command = "npx hardhat empty-task --help" ;
239
- const cliArguments = command . split ( " " ) . slice ( 2 ) ;
252
+ const command = "npx hardhat empty-task --help" ;
253
+ const cliArguments = command . split ( " " ) . slice ( 2 ) ;
240
254
241
- await main ( cliArguments , ( msg ) => {
242
- lines . push ( msg ) ;
243
- } ) ;
255
+ await main ( cliArguments , ( msg ) => {
256
+ lines = msg ;
257
+ } ) ;
244
258
245
- assert . equal ( lines . length , 2 ) ;
246
- assert . equal ( lines [ 1 ] , "Info about subtasks" ) ;
247
- } ,
248
- ) ;
259
+ const expected = `${ chalk . bold ( "empty task description" ) }
260
+
261
+ Usage: hardhat [GLOBAL OPTIONS] empty-task <SUBTASK> [SUBTASK OPTIONS] [--] [SUBTASK POSITIONAL ARGUMENTS]
262
+ ` ;
263
+
264
+ assert . equal ( lines , expected ) ;
265
+ } ) ;
249
266
} ) ;
250
267
251
- // TODO: as soon as the 'help task' is done, this test should be updated
252
268
describe ( "task help" , function ( ) {
253
269
useFixtureProject ( "cli/parsing/base-project" ) ;
254
270
255
- it . todo ( "should print an help message for the task" , async function ( ) {
256
- const lines : string [ ] = [ ] ;
271
+ it ( "should print an help message for the task" , async function ( ) {
272
+ let lines : string = "" ;
257
273
258
274
const command = "npx hardhat task --help" ;
259
275
const cliArguments = command . split ( " " ) . slice ( 2 ) ;
260
276
261
277
await main ( cliArguments , ( msg ) => {
262
- lines . push ( msg ) ;
278
+ lines = msg ;
263
279
} ) ;
264
280
265
- assert . equal ( lines . length , 2 ) ;
266
- assert . equal ( lines [ 1 ] , "Help message of the task" ) ;
281
+ const expected = `${ chalk . bold ( "A task that uses param1" ) }
282
+
283
+ Usage: hardhat [GLOBAL OPTIONS] task
284
+
285
+ For global options help run: hardhat --help` ;
286
+
287
+ assert . equal ( lines , expected ) ;
267
288
} ) ;
268
289
} ) ;
269
290
} ) ;
0 commit comments