@@ -29,7 +29,7 @@ class Codecept {
2929 this . testFiles = [ ] ;
3030 }
3131
32- init ( dir , callback ) {
32+ init ( dir , callback ) {
3333 // preparing globals
3434 global . codecept_dir = dir ;
3535 global . output_dir = fsPath . resolve ( dir , this . config . output ) ;
@@ -50,7 +50,7 @@ class Codecept {
5050
5151 // loading bootstrap
5252 bootstrap ( callback ) {
53- if ( typeof this . config . bootstrap === 'string' && fileExists ( fsPath . join ( codecept_dir , this . config . bootstrap ) ) ) {
53+ if ( typeof this . config . bootstrap === 'string' && fileExists ( fsPath . join ( codecept_dir , this . config . bootstrap ) ) ) {
5454 var bootstrap = require ( fsPath . join ( codecept_dir , this . config . bootstrap ) ) ;
5555 if ( typeof bootstrap === 'function' ) {
5656 bootstrap ( callback ) ;
@@ -64,15 +64,18 @@ class Codecept {
6464 }
6565
6666 // loading teardown
67- teardown ( ) {
67+ teardown ( callback ) {
6868 if ( typeof this . config . teardown === 'string' && fileExists ( fsPath . join ( codecept_dir , this . config . teardown ) ) ) {
69- var teardown = require ( fsPath . join ( codecept_dir , this . config . teardown ) ) ;
70- if ( typeof teardown === 'function' ) {
71- teardown ( ) ;
72- }
69+ var teardown = require ( fsPath . join ( codecept_dir , this . config . teardown ) ) ;
70+ if ( typeof teardown === 'function' ) {
71+ teardown ( callback ) ;
72+ return ;
73+ }
7374 } else if ( typeof this . config . teardown === 'function' ) {
74- this . config . teardown ( ) ;
75+ this . config . teardown ( callback ) ;
76+ return ;
7577 }
78+ callback ( ) ;
7679 }
7780
7881 loadTests ( pattern ) {
@@ -85,16 +88,16 @@ class Codecept {
8588 reporterOptions ( ) {
8689 var reporterOptions = Object . assign ( this . config . mocha . reporterOptions || { } ) ;
8790 if ( this . opts . reporterOptions !== undefined ) {
88- this . opts . reporterOptions . split ( "," ) . forEach ( function ( opt ) {
89- var L = opt . split ( "=" ) ;
90- if ( L . length > 2 || L . length === 0 ) {
91- throw new Error ( "invalid reporter option '" + opt + "'" ) ;
92- } else if ( L . length === 2 ) {
93- reporterOptions [ L [ 0 ] ] = L [ 1 ] ;
94- } else {
95- reporterOptions [ L [ 0 ] ] = true ;
96- }
97- } ) ;
91+ this . opts . reporterOptions . split ( "," ) . forEach ( function ( opt ) {
92+ var L = opt . split ( "=" ) ;
93+ if ( L . length > 2 || L . length === 0 ) {
94+ throw new Error ( "invalid reporter option '" + opt + "'" ) ;
95+ } else if ( L . length === 2 ) {
96+ reporterOptions [ L [ 0 ] ] = L [ 1 ] ;
97+ } else {
98+ reporterOptions [ L [ 0 ] ] = true ;
99+ }
100+ } ) ;
98101 }
99102 return reporterOptions ;
100103
@@ -105,10 +108,11 @@ class Codecept {
105108 if ( test ) {
106109 this . mocha . files = this . mocha . files . filter ( ( t ) => fsPath . basename ( t , '_test.js' ) === test || fsPath . basename ( t , '.js' ) === test || fsPath . basename ( t ) === test ) ;
107110 }
108- this . mocha . run ( ( ) => {
109- event . emit ( event . all . result , this ) ;
110- } ) . on ( 'end' , ( ) => {
111- this . teardown ( ) ;
111+ this . mocha . run ( ) . on ( 'end' , ( ) => {
112+ let done = ( ) => {
113+ event . emit ( event . all . result , this ) ;
114+ } ;
115+ this . teardown ( done ) ;
112116 } ) ;
113117 }
114118
0 commit comments