1
1
#!/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' )
6
6
7
7
const commandFlags = {
8
8
ai : {
@@ -29,104 +29,120 @@ const commandFlags = {
29
29
flag : '--steps' ,
30
30
description : 'show step-by-step execution' ,
31
31
} ,
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
+ }
40
43
}
41
- } ;
42
44
43
45
if ( 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 )
49
51
}
50
52
51
- program . usage ( '<command> [options]' ) ;
52
- program . version ( Codecept . version ( ) ) ;
53
+ program . usage ( '<command> [options]' )
54
+ program . version ( Codecept . version ( ) )
53
55
54
- program . command ( 'init [path]' )
56
+ program
57
+ . command ( 'init [path]' )
55
58
. description ( 'Creates dummy config in current dir or [path]' )
56
- . action ( errorHandler ( require ( '../lib/command/init' ) ) ) ;
59
+ . action ( errorHandler ( require ( '../lib/command/init' ) ) )
57
60
58
- program . command ( 'migrate [path]' )
61
+ program
62
+ . command ( 'migrate [path]' )
59
63
. 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' ) ) )
61
65
62
- program . command ( 'shell [path]' )
66
+ program
67
+ . command ( 'shell [path]' )
63
68
. alias ( 'sh' )
64
69
. description ( 'Interactive shell' )
65
70
. option ( commandFlags . verbose . flag , commandFlags . verbose . description )
66
71
. option ( commandFlags . profile . flag , commandFlags . profile . description )
67
72
. option ( commandFlags . ai . flag , commandFlags . ai . description )
68
73
. option ( commandFlags . config . flag , commandFlags . config . description )
69
- . action ( errorHandler ( require ( '../lib/command/interactive' ) ) ) ;
74
+ . action ( errorHandler ( require ( '../lib/command/interactive' ) ) )
70
75
71
- program . command ( 'list [path]' )
76
+ program
77
+ . command ( 'list [path]' )
72
78
. alias ( 'l' )
73
79
. description ( 'List all actions for I.' )
74
- . action ( errorHandler ( require ( '../lib/command/list' ) ) ) ;
80
+ . action ( errorHandler ( require ( '../lib/command/list' ) ) )
75
81
76
- program . command ( 'def [path]' )
82
+ program
83
+ . command ( 'def [path]' )
77
84
. description ( 'Generates TypeScript definitions for all I actions.' )
78
85
. option ( commandFlags . config . flag , commandFlags . config . description )
79
86
. option ( '-o, --output [folder]' , 'target folder to paste definitions' )
80
- . action ( errorHandler ( require ( '../lib/command/definitions' ) ) ) ;
87
+ . action ( errorHandler ( require ( '../lib/command/definitions' ) ) )
81
88
82
- program . command ( 'gherkin:init [path]' )
89
+ program
90
+ . command ( 'gherkin:init [path]' )
83
91
. alias ( 'bdd:init' )
84
92
. description ( 'Prepare CodeceptJS to run feature files.' )
85
93
. option ( commandFlags . config . flag , commandFlags . config . description )
86
- . action ( errorHandler ( require ( '../lib/command/gherkin/init' ) ) ) ;
94
+ . action ( errorHandler ( require ( '../lib/command/gherkin/init' ) ) )
87
95
88
- program . command ( 'gherkin:steps [path]' )
96
+ program
97
+ . command ( 'gherkin:steps [path]' )
89
98
. alias ( 'bdd:steps' )
90
99
. description ( 'Prints all defined gherkin steps.' )
91
100
. option ( commandFlags . config . flag , commandFlags . config . description )
92
- . action ( errorHandler ( require ( '../lib/command/gherkin/steps' ) ) ) ;
101
+ . action ( errorHandler ( require ( '../lib/command/gherkin/steps' ) ) )
93
102
94
- program . command ( 'gherkin:snippets [path]' )
103
+ program
104
+ . command ( 'gherkin:snippets [path]' )
95
105
. alias ( 'bdd:snippets' )
96
106
. description ( 'Generate step definitions from steps.' )
97
107
. option ( '--dry-run' , "don't save snippets to file" )
98
108
. option ( commandFlags . config . flag , commandFlags . config . description )
99
109
. option ( '--feature [file]' , 'feature files(s) to scan' )
100
110
. 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' ) ) )
102
112
103
- program . command ( 'generate:test [path]' )
113
+ program
114
+ . command ( 'generate:test [path]' )
104
115
. alias ( 'gt' )
105
116
. description ( 'Generates an empty test' )
106
- . action ( errorHandler ( require ( '../lib/command/generate' ) . test ) ) ;
117
+ . action ( errorHandler ( require ( '../lib/command/generate' ) . test ) )
107
118
108
- program . command ( 'generate:pageobject [path]' )
119
+ program
120
+ . command ( 'generate:pageobject [path]' )
109
121
. alias ( 'gpo' )
110
122
. description ( 'Generates an empty page object' )
111
- . action ( errorHandler ( require ( '../lib/command/generate' ) . pageObject ) ) ;
123
+ . action ( errorHandler ( require ( '../lib/command/generate' ) . pageObject ) )
112
124
113
- program . command ( 'generate:object [path]' )
125
+ program
126
+ . command ( 'generate:object [path]' )
114
127
. alias ( 'go' )
115
128
. option ( '--type, -t [kind]' , 'type of object to be created' )
116
129
. 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 ) )
118
131
119
- program . command ( 'generate:helper [path]' )
132
+ program
133
+ . command ( 'generate:helper [path]' )
120
134
. alias ( 'gh' )
121
135
. description ( 'Generates a new helper' )
122
- . action ( errorHandler ( require ( '../lib/command/generate' ) . helper ) ) ;
136
+ . action ( errorHandler ( require ( '../lib/command/generate' ) . helper ) )
123
137
124
- program . command ( 'generate:heal [path]' )
138
+ program
139
+ . command ( 'generate:heal [path]' )
125
140
. alias ( 'gr' )
126
141
. description ( 'Generates basic heal recipes' )
127
- . action ( errorHandler ( require ( '../lib/command/generate' ) . heal ) ) ;
142
+ . action ( errorHandler ( require ( '../lib/command/generate' ) . heal ) )
128
143
129
- program . command ( 'run [test]' )
144
+ program
145
+ . command ( 'run [test]' )
130
146
. description ( 'Executes tests' )
131
147
132
148
// codecept-only options
@@ -162,9 +178,10 @@ program.command('run [test]')
162
178
. option ( '--recursive' , 'include sub directories' )
163
179
. option ( '--trace' , 'trace function calls' )
164
180
. option ( '--child <string>' , 'option for child processes' )
165
- . action ( errorHandler ( require ( '../lib/command/run' ) ) ) ;
181
+ . action ( errorHandler ( require ( '../lib/command/run' ) ) )
166
182
167
- program . command ( 'run-workers <workers> [selectedRuns...]' )
183
+ program
184
+ . command ( 'run-workers <workers> [selectedRuns...]' )
168
185
. description ( 'Executes tests in workers' )
169
186
. option ( commandFlags . config . flag , commandFlags . config . description )
170
187
. option ( '-g, --grep <pattern>' , 'only run tests matching <pattern>' )
@@ -180,9 +197,10 @@ program.command('run-workers <workers> [selectedRuns...]')
180
197
. option ( '-p, --plugins <k=v,k2=v2,...>' , 'enable plugins, comma-separated' )
181
198
. option ( '-O, --reporter-options <k=v,k2=v2,...>' , 'reporter-specific options' )
182
199
. 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' ) ) )
184
201
185
- program . command ( 'run-multiple [suites...]' )
202
+ program
203
+ . command ( 'run-multiple [suites...]' )
186
204
. description ( 'Executes tests multiple' )
187
205
. option ( commandFlags . config . flag , commandFlags . config . description )
188
206
. option ( commandFlags . profile . flag , commandFlags . profile . description )
@@ -205,14 +223,16 @@ program.command('run-multiple [suites...]')
205
223
// mocha options
206
224
. option ( '--colors' , 'force enabling of colors' )
207
225
208
- . action ( errorHandler ( require ( '../lib/command/run-multiple' ) ) ) ;
226
+ . action ( errorHandler ( require ( '../lib/command/run-multiple' ) ) )
209
227
210
- program . command ( 'info [path]' )
228
+ program
229
+ . command ( 'info [path]' )
211
230
. description ( 'Print debugging information concerning the local environment' )
212
231
. option ( '-c, --config' , 'your config file path' )
213
- . action ( errorHandler ( require ( '../lib/command/info' ) ) ) ;
232
+ . action ( errorHandler ( require ( '../lib/command/info' ) ) )
214
233
215
- program . command ( 'dry-run [test]' )
234
+ program
235
+ . command ( 'dry-run [test]' )
216
236
. description ( 'Prints step-by-step scenario for a test without actually running it' )
217
237
. option ( '-p, --plugins <k=v,k2=v2,...>' , 'enable plugins, comma-separated' )
218
238
. option ( '--bootstrap' , 'enable bootstrap & teardown scripts for dry-run' )
@@ -226,9 +246,10 @@ program.command('dry-run [test]')
226
246
. option ( commandFlags . steps . flag , commandFlags . steps . description )
227
247
. option ( commandFlags . verbose . flag , commandFlags . verbose . description )
228
248
. option ( commandFlags . debug . flag , commandFlags . debug . description )
229
- . action ( errorHandler ( require ( '../lib/command/dryRun' ) ) ) ;
249
+ . action ( errorHandler ( require ( '../lib/command/dryRun' ) ) )
230
250
231
- program . command ( 'run-rerun [test]' )
251
+ program
252
+ . command ( 'run-rerun [test]' )
232
253
. description ( 'Executes tests in more than one test suite run' )
233
254
234
255
// codecept-only options
@@ -263,15 +284,15 @@ program.command('run-rerun [test]')
263
284
. option ( '--trace' , 'trace function calls' )
264
285
. option ( '--child <string>' , 'option for child processes' )
265
286
266
- . action ( require ( '../lib/command/run-rerun' ) ) ;
287
+ . action ( require ( '../lib/command/run-rerun' ) )
267
288
268
289
program . 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
+ } )
272
293
273
294
if ( process . argv . length <= 2 ) {
274
- program . outputHelp ( ) ;
295
+ program . outputHelp ( )
275
296
} else {
276
- program . parse ( process . argv ) ;
297
+ program . parse ( process . argv )
277
298
}
0 commit comments