11#!/usr/bin/env node
2- const program = require ( 'commander' ) ;
3- const Codecept = require ( '../lib/codecept' ) ;
4- const { print, error } = require ( '../lib/output' ) ;
5- const { printError } = require ( '../lib/command/utils' ) ;
2+ const program = require ( 'commander' )
3+ const Codecept = require ( '../lib/codecept' )
4+ const { print, error } = require ( '../lib/output' )
5+ const { printError } = require ( '../lib/command/utils' )
66
77const commandFlags = {
88 ai : {
@@ -29,104 +29,120 @@ const commandFlags = {
2929 flag : '--steps' ,
3030 description : 'show step-by-step execution' ,
3131 } ,
32- } ;
33-
34- const errorHandler = ( fn ) => async ( ...args ) => {
35- try {
36- await fn ( ...args ) ;
37- } catch ( e ) {
38- printError ( e ) ;
39- process . exitCode = 1 ;
32+ }
33+
34+ const errorHandler =
35+ ( fn ) =>
36+ async ( ...args ) => {
37+ try {
38+ await fn ( ...args )
39+ } catch ( e ) {
40+ printError ( e )
41+ process . exitCode = 1
42+ }
4043 }
41- } ;
4244
4345if ( process . versions . node && process . versions . node . split ( '.' ) && process . versions . node . split ( '.' ) [ 0 ] < 12 ) {
44- error ( 'NodeJS >= 12 is required to run.' ) ;
45- print ( ) ;
46- print ( 'Please upgrade your NodeJS engine' ) ;
47- print ( `Current NodeJS version: ${ process . version } ` ) ;
48- process . exit ( 1 ) ;
46+ error ( 'NodeJS >= 12 is required to run.' )
47+ print ( )
48+ print ( 'Please upgrade your NodeJS engine' )
49+ print ( `Current NodeJS version: ${ process . version } ` )
50+ process . exit ( 1 )
4951}
5052
51- program . usage ( '<command> [options]' ) ;
52- program . version ( Codecept . version ( ) ) ;
53+ program . usage ( '<command> [options]' )
54+ program . version ( Codecept . version ( ) )
5355
54- program . command ( 'init [path]' )
56+ program
57+ . command ( 'init [path]' )
5558 . description ( 'Creates dummy config in current dir or [path]' )
56- . action ( errorHandler ( require ( '../lib/command/init' ) ) ) ;
59+ . action ( errorHandler ( require ( '../lib/command/init' ) ) )
5760
58- program . command ( 'migrate [path]' )
61+ program
62+ . command ( 'migrate [path]' )
5963 . description ( 'Migrate json config to js config in current dir or [path]' )
60- . action ( errorHandler ( require ( '../lib/command/configMigrate' ) ) ) ;
64+ . action ( errorHandler ( require ( '../lib/command/configMigrate' ) ) )
6165
62- program . command ( 'shell [path]' )
66+ program
67+ . command ( 'shell [path]' )
6368 . alias ( 'sh' )
6469 . description ( 'Interactive shell' )
6570 . option ( commandFlags . verbose . flag , commandFlags . verbose . description )
6671 . option ( commandFlags . profile . flag , commandFlags . profile . description )
6772 . option ( commandFlags . ai . flag , commandFlags . ai . description )
6873 . option ( commandFlags . config . flag , commandFlags . config . description )
69- . action ( errorHandler ( require ( '../lib/command/interactive' ) ) ) ;
74+ . action ( errorHandler ( require ( '../lib/command/interactive' ) ) )
7075
71- program . command ( 'list [path]' )
76+ program
77+ . command ( 'list [path]' )
7278 . alias ( 'l' )
7379 . description ( 'List all actions for I.' )
74- . action ( errorHandler ( require ( '../lib/command/list' ) ) ) ;
80+ . action ( errorHandler ( require ( '../lib/command/list' ) ) )
7581
76- program . command ( 'def [path]' )
82+ program
83+ . command ( 'def [path]' )
7784 . description ( 'Generates TypeScript definitions for all I actions.' )
7885 . option ( commandFlags . config . flag , commandFlags . config . description )
7986 . option ( '-o, --output [folder]' , 'target folder to paste definitions' )
80- . action ( errorHandler ( require ( '../lib/command/definitions' ) ) ) ;
87+ . action ( errorHandler ( require ( '../lib/command/definitions' ) ) )
8188
82- program . command ( 'gherkin:init [path]' )
89+ program
90+ . command ( 'gherkin:init [path]' )
8391 . alias ( 'bdd:init' )
8492 . description ( 'Prepare CodeceptJS to run feature files.' )
8593 . option ( commandFlags . config . flag , commandFlags . config . description )
86- . action ( errorHandler ( require ( '../lib/command/gherkin/init' ) ) ) ;
94+ . action ( errorHandler ( require ( '../lib/command/gherkin/init' ) ) )
8795
88- program . command ( 'gherkin:steps [path]' )
96+ program
97+ . command ( 'gherkin:steps [path]' )
8998 . alias ( 'bdd:steps' )
9099 . description ( 'Prints all defined gherkin steps.' )
91100 . option ( commandFlags . config . flag , commandFlags . config . description )
92- . action ( errorHandler ( require ( '../lib/command/gherkin/steps' ) ) ) ;
101+ . action ( errorHandler ( require ( '../lib/command/gherkin/steps' ) ) )
93102
94- program . command ( 'gherkin:snippets [path]' )
103+ program
104+ . command ( 'gherkin:snippets [path]' )
95105 . alias ( 'bdd:snippets' )
96106 . description ( 'Generate step definitions from steps.' )
97107 . option ( '--dry-run' , "don't save snippets to file" )
98108 . option ( commandFlags . config . flag , commandFlags . config . description )
99109 . option ( '--feature [file]' , 'feature files(s) to scan' )
100110 . option ( '--path [file]' , 'file in which to place the new snippets' )
101- . action ( errorHandler ( require ( '../lib/command/gherkin/snippets' ) ) ) ;
111+ . action ( errorHandler ( require ( '../lib/command/gherkin/snippets' ) ) )
102112
103- program . command ( 'generate:test [path]' )
113+ program
114+ . command ( 'generate:test [path]' )
104115 . alias ( 'gt' )
105116 . description ( 'Generates an empty test' )
106- . action ( errorHandler ( require ( '../lib/command/generate' ) . test ) ) ;
117+ . action ( errorHandler ( require ( '../lib/command/generate' ) . test ) )
107118
108- program . command ( 'generate:pageobject [path]' )
119+ program
120+ . command ( 'generate:pageobject [path]' )
109121 . alias ( 'gpo' )
110122 . description ( 'Generates an empty page object' )
111- . action ( errorHandler ( require ( '../lib/command/generate' ) . pageObject ) ) ;
123+ . action ( errorHandler ( require ( '../lib/command/generate' ) . pageObject ) )
112124
113- program . command ( 'generate:object [path]' )
125+ program
126+ . command ( 'generate:object [path]' )
114127 . alias ( 'go' )
115128 . option ( '--type, -t [kind]' , 'type of object to be created' )
116129 . description ( 'Generates an empty support object (page/step/fragment)' )
117- . action ( errorHandler ( require ( '../lib/command/generate' ) . pageObject ) ) ;
130+ . action ( errorHandler ( require ( '../lib/command/generate' ) . pageObject ) )
118131
119- program . command ( 'generate:helper [path]' )
132+ program
133+ . command ( 'generate:helper [path]' )
120134 . alias ( 'gh' )
121135 . description ( 'Generates a new helper' )
122- . action ( errorHandler ( require ( '../lib/command/generate' ) . helper ) ) ;
136+ . action ( errorHandler ( require ( '../lib/command/generate' ) . helper ) )
123137
124- program . command ( 'generate:heal [path]' )
138+ program
139+ . command ( 'generate:heal [path]' )
125140 . alias ( 'gr' )
126141 . description ( 'Generates basic heal recipes' )
127- . action ( errorHandler ( require ( '../lib/command/generate' ) . heal ) ) ;
142+ . action ( errorHandler ( require ( '../lib/command/generate' ) . heal ) )
128143
129- program . command ( 'run [test]' )
144+ program
145+ . command ( 'run [test]' )
130146 . description ( 'Executes tests' )
131147
132148 // codecept-only options
@@ -162,9 +178,10 @@ program.command('run [test]')
162178 . option ( '--recursive' , 'include sub directories' )
163179 . option ( '--trace' , 'trace function calls' )
164180 . option ( '--child <string>' , 'option for child processes' )
165- . action ( errorHandler ( require ( '../lib/command/run' ) ) ) ;
181+ . action ( errorHandler ( require ( '../lib/command/run' ) ) )
166182
167- program . command ( 'run-workers <workers> [selectedRuns...]' )
183+ program
184+ . command ( 'run-workers <workers> [selectedRuns...]' )
168185 . description ( 'Executes tests in workers' )
169186 . option ( commandFlags . config . flag , commandFlags . config . description )
170187 . option ( '-g, --grep <pattern>' , 'only run tests matching <pattern>' )
@@ -180,9 +197,10 @@ program.command('run-workers <workers> [selectedRuns...]')
180197 . option ( '-p, --plugins <k=v,k2=v2,...>' , 'enable plugins, comma-separated' )
181198 . option ( '-O, --reporter-options <k=v,k2=v2,...>' , 'reporter-specific options' )
182199 . option ( '-R, --reporter <name>' , 'specify the reporter to use' )
183- . action ( errorHandler ( require ( '../lib/command/run-workers' ) ) ) ;
200+ . action ( errorHandler ( require ( '../lib/command/run-workers' ) ) )
184201
185- program . command ( 'run-multiple [suites...]' )
202+ program
203+ . command ( 'run-multiple [suites...]' )
186204 . description ( 'Executes tests multiple' )
187205 . option ( commandFlags . config . flag , commandFlags . config . description )
188206 . option ( commandFlags . profile . flag , commandFlags . profile . description )
@@ -205,14 +223,16 @@ program.command('run-multiple [suites...]')
205223 // mocha options
206224 . option ( '--colors' , 'force enabling of colors' )
207225
208- . action ( errorHandler ( require ( '../lib/command/run-multiple' ) ) ) ;
226+ . action ( errorHandler ( require ( '../lib/command/run-multiple' ) ) )
209227
210- program . command ( 'info [path]' )
228+ program
229+ . command ( 'info [path]' )
211230 . description ( 'Print debugging information concerning the local environment' )
212231 . option ( '-c, --config' , 'your config file path' )
213- . action ( errorHandler ( require ( '../lib/command/info' ) ) ) ;
232+ . action ( errorHandler ( require ( '../lib/command/info' ) ) )
214233
215- program . command ( 'dry-run [test]' )
234+ program
235+ . command ( 'dry-run [test]' )
216236 . description ( 'Prints step-by-step scenario for a test without actually running it' )
217237 . option ( '-p, --plugins <k=v,k2=v2,...>' , 'enable plugins, comma-separated' )
218238 . option ( '--bootstrap' , 'enable bootstrap & teardown scripts for dry-run' )
@@ -226,9 +246,10 @@ program.command('dry-run [test]')
226246 . option ( commandFlags . steps . flag , commandFlags . steps . description )
227247 . option ( commandFlags . verbose . flag , commandFlags . verbose . description )
228248 . option ( commandFlags . debug . flag , commandFlags . debug . description )
229- . action ( errorHandler ( require ( '../lib/command/dryRun' ) ) ) ;
249+ . action ( errorHandler ( require ( '../lib/command/dryRun' ) ) )
230250
231- program . command ( 'run-rerun [test]' )
251+ program
252+ . command ( 'run-rerun [test]' )
232253 . description ( 'Executes tests in more than one test suite run' )
233254
234255 // codecept-only options
@@ -263,15 +284,15 @@ program.command('run-rerun [test]')
263284 . option ( '--trace' , 'trace function calls' )
264285 . option ( '--child <string>' , 'option for child processes' )
265286
266- . action ( require ( '../lib/command/run-rerun' ) ) ;
287+ . action ( require ( '../lib/command/run-rerun' ) )
267288
268289program . on ( 'command:*' , ( cmd ) => {
269- console . log ( `\nUnknown command ${ cmd } \n` ) ;
270- program . outputHelp ( ) ;
271- } ) ;
290+ console . log ( `\nUnknown command ${ cmd } \n` )
291+ program . outputHelp ( )
292+ } )
272293
273294if ( process . argv . length <= 2 ) {
274- program . outputHelp ( ) ;
295+ program . outputHelp ( )
275296} else {
276- program . parse ( process . argv ) ;
297+ program . parse ( process . argv )
277298}
0 commit comments