@@ -11,54 +11,33 @@ const path = require('path');
1111const selenium = require ( '../' ) ;
1212const defaultConfig = require ( '../lib/default-config' ) ( ) ;
1313
14+ if ( ! process . listeners ( 'unhandledRejection' ) . length === 0 ) {
15+ process . on ( 'unhandledRejection' , ( reason ) => {
16+ console . error ( reason ) ;
17+ } ) ;
18+ }
19+
1420const actions = {
15- start : function ( options ) {
21+ start : async function ( options ) {
1622 const killEvents = [ 'exit' , 'SIGTERM' , 'SIGINT' ] ;
23+ const cp = await selenium . start ( options ) ;
1724
18- selenium . start ( options , started ) ;
19-
20- function started ( err , cp ) {
21- if ( err ) {
22- if ( cp ) {
23- cp . kill ( 'SIGINT' ) ;
24- }
25- throw err ;
26- }
27-
28- console . log ( 'Selenium started' ) ;
29-
30- killEvents . forEach ( register ) ;
31-
32- function register ( evName ) {
33- process . on ( evName , kill ) ;
34- }
25+ console . log ( 'Selenium started' ) ;
3526
36- function unregister ( evName ) {
37- process . removeListener ( evName , kill ) ;
38- }
27+ killEvents . forEach ( ( evName ) => {
28+ process . once ( evName , ( ) => cp . kill ( 'SIGTERM' ) ) ;
29+ } ) ;
3930
40- function kill ( ) {
41- killEvents . forEach ( unregister ) ;
42- cp . kill ( 'SIGTERM' ) ;
43- }
44- }
31+ return cp ;
4532 } ,
46- install : function ( options ) {
33+ install : async function ( options ) {
4734 const ProgressBar = require ( 'progress' ) ;
4835 let bar ;
4936 let firstProgress = true ;
5037
5138 // eslint-disable-next-line no-param-reassign
5239 options . progressCb = options . silent ? null : progressCb ;
5340
54- selenium . install ( options , installed ) ;
55-
56- function installed ( err ) {
57- if ( err ) {
58- throw err ;
59- }
60- }
61-
6241 function progressCb ( total , progress , chunk , url , reset ) {
6342 if ( firstProgress ) {
6443 console . log ( '' ) ;
@@ -77,6 +56,8 @@ const actions = {
7756
7857 bar . tick ( chunk ) ;
7958 }
59+
60+ await selenium . install ( options ) ;
8061 } ,
8162} ;
8263
0 commit comments