@@ -16,6 +16,9 @@ import argsUtils from './util/args'
16
16
import { telemetry } from '@packages/telemetry'
17
17
import { getCtx , hasCtx } from '@packages/data-context'
18
18
import { warning as errorsWarning } from './errors'
19
+ import pkg from '@packages/root'
20
+ import { info } from './modes/info'
21
+ import { toNumber } from 'lodash'
19
22
20
23
const debug = Debug ( 'cypress:server:cypress' )
21
24
@@ -206,74 +209,88 @@ export = {
206
209
} )
207
210
} ,
208
211
209
- startInMode ( mode : Mode , options : any ) {
212
+ async startInMode ( mode : Mode , options : any ) {
210
213
debug ( 'starting in mode %s with options %o' , mode , options )
211
214
212
215
switch ( mode ) {
213
216
case 'version' :
214
- return require ( './modes/pkg' ) ( options )
215
- . get ( ' version' )
216
- . then ( ( version : any ) => {
217
- return console . log ( version ) // eslint-disable-line no-console
218
- } ) . then ( exit0 )
219
- . catch ( exitErr )
220
-
217
+ try {
218
+ console . log ( pkg . version ) // eslint-disable-line no-console
219
+ exit0 ( )
220
+ } catch ( err ) {
221
+ exitErr ( err )
222
+ }
223
+ break
221
224
case 'info' :
222
- return require ( './modes/info' ) ( options )
223
- . then ( exit0 )
224
- . catch ( exitErr )
225
-
225
+ try {
226
+ await info ( )
227
+ exit0 ( )
228
+ } catch ( err ) {
229
+ exitErr ( err )
230
+ }
231
+ break
226
232
case 'smokeTest' :
227
- return this . runElectron ( mode , options )
228
- . then ( ( pong : any ) => {
233
+ try {
234
+ const pong = await this . runElectron ( mode , options )
235
+
229
236
if ( ! this . isCurrentlyRunningElectron ( ) ) {
230
- return pong
237
+ return exit ( pong )
231
238
}
232
239
233
240
if ( pong === options . ping ) {
234
- return 0
241
+ return exit ( 0 )
235
242
}
236
243
237
- return 1
238
- } ) . then ( exit )
239
- . catch ( exitErr )
244
+ return exit ( 1 )
245
+ } catch ( err ) {
246
+ exitErr ( err )
247
+ }
248
+ break
240
249
241
250
case 'returnPkg' :
242
- return require ( './modes/pkg' ) ( options )
243
- . then ( ( pkg : any ) => {
244
- return console . log ( JSON . stringify ( pkg ) ) // eslint-disable-line no-console
245
- } ) . then ( exit0 )
246
- . catch ( exitErr )
251
+ try {
252
+ console . log ( JSON . stringify ( pkg ) ) // eslint-disable-line no-console
253
+ exit0 ( )
254
+ } catch ( err ) {
255
+ exitErr ( err )
256
+ }
257
+ break
247
258
248
259
case 'exitWithCode' :
249
- return require ( './modes/exit' ) ( options )
250
- . then ( exit )
251
- . catch ( exitErr )
260
+ try {
261
+ const exitCode = toNumber ( options . exitWithCode )
252
262
263
+ exit ( exitCode )
264
+ } catch ( err ) {
265
+ exitErr ( err )
266
+ }
267
+ break
253
268
case 'run' :
254
269
// run headlessly and exit
255
270
// with num of totalFailed
256
- return this . runElectron ( mode , options )
257
- . then ( ( results : any ) => {
271
+ try {
272
+ const results = await this . runElectron ( mode , options )
273
+
258
274
if ( results . runs ) {
259
275
const isCanceled = results . runs . filter ( ( run ) => run . skippedSpec ) . length
260
276
261
277
if ( isCanceled ) {
262
278
// eslint-disable-next-line no-console
263
279
console . log ( require ( 'chalk' ) . magenta ( '\n Exiting with non-zero exit code because the run was canceled.' ) )
264
280
265
- return 1
281
+ return exit ( 1 )
266
282
}
267
283
}
268
284
269
285
if ( options . posixExitCodes ) {
270
- return results . totalFailed ? 1 : 0
286
+ return exit ( results . totalFailed ? 1 : 0 )
271
287
}
272
288
273
- return results . totalFailed
274
- } )
275
- . then ( exit )
276
- . catch ( exitErr )
289
+ return exit ( results . totalFailed )
290
+ } catch ( err ) {
291
+ exitErr ( err )
292
+ }
293
+ break
277
294
278
295
case 'interactive' :
279
296
return this . runElectron ( mode , options )
0 commit comments