@@ -15,19 +15,18 @@ module.exports = function coreSteps () {
1515 var cleansingNeeded = true
1616 var additionalArgs = [ ]
1717
18- var cleanseIfNeeded = ( function ( _this ) {
19- return function ( ) {
20- if ( cleansingNeeded ) {
21- try {
22- rimraf . sync ( tmpDir )
23- } catch ( e ) { }
18+ var cleanseIfNeeded = function ( ) {
19+ if ( cleansingNeeded ) {
20+ try {
21+ rimraf . sync ( tmpDir )
22+ } catch ( e ) {
23+ }
2424
25- cleansingNeeded = false
25+ cleansingNeeded = false
2626
27- return cleansingNeeded
28- }
27+ return cleansingNeeded
2928 }
30- } ) ( this )
29+ }
3130
3231 this . Given ( / ^ a c o n f i g u r a t i o n w i t h : $ / , function ( fileContent , callback ) {
3332 cleanseIfNeeded ( )
@@ -40,17 +39,39 @@ module.exports = function coreSteps () {
4039 return callback ( )
4140 } )
4241
43- this . When ( / ^ I ( r u n | r u n O u t | s t a r t | i n i t ) K a r m a $ / , function ( command , callback ) {
42+ this . When ( / ^ I s t a r t a s e r v e r i n b a c k g r o u n d / , function ( callback ) {
4443 this . writeConfigFile ( tmpDir , tmpConfigFile , ( function ( _this ) {
4544 return function ( err , hash ) {
4645 if ( err ) {
4746 return callback . fail ( new Error ( err ) )
4847 }
4948
49+ var configFile = path . join ( tmpDir , hash + '.' + tmpConfigFile )
50+ var runtimePath = path . join ( baseDir , 'bin' , 'karma' )
51+ _this . child = spawn ( '' + runtimePath , [ 'start' , '--log-level' , 'debug' , configFile ] )
52+ _this . child . stdout . on ( 'data' , function ( ) {
53+ callback ( )
54+ callback = function ( ) {
55+ }
56+ } )
57+ _this . child . on ( 'exit' , function ( exitCode ) {
58+ _this . childExitCode = exitCode
59+ } )
60+ }
61+ } ) ( this ) )
62+ } )
63+
64+ this . When ( / ^ I ( r u n | r u n O u t | s t a r t | i n i t | s t o p ) K a r m a ( w i t h l o g - l e v e l ( [ a - z ] + ) ) ? $ / , function ( command , withLogLevel , level , callback ) {
65+ this . writeConfigFile ( tmpDir , tmpConfigFile , ( function ( _this ) {
66+ return function ( err , hash ) {
67+ if ( err ) {
68+ return callback . fail ( new Error ( err ) )
69+ }
70+ level = withLogLevel === undefined ? 'warn' : level
5071 var configFile = path . join ( tmpDir , hash + '.' + tmpConfigFile )
5172 var runtimePath = path . join ( baseDir , 'bin' , 'karma' )
5273 var execKarma = function ( done ) {
53- var cmd = runtimePath + ' ' + command + ' --log-level warn ' + configFile + ' ' + additionalArgs
74+ var cmd = runtimePath + ' ' + command + ' --log-level ' + level + ' ' + configFile + ' ' + additionalArgs
5475
5576 return exec ( cmd , {
5677 cwd : baseDir
@@ -107,11 +128,10 @@ module.exports = function coreSteps () {
107128 } ) ( this ) )
108129 } )
109130
110- this . Then ( / ^ i t p a s s e s w i t h ( n o d e b u g ) ? : $ / , { timeout : 10 * 1000 } , function ( noDebug , expectedOutput , callback ) {
111- noDebug = noDebug === ' no debug'
131+ this . Then ( / ^ i t p a s s e s w i t h ( n o d e b u g | l i k e ) ? : $ / , { timeout : 10 * 1000 } , function ( mode , expectedOutput , callback ) {
132+ var noDebug = mode === ' no debug'
133+ var like = mode === ' like'
112134 var actualOutput = this . lastRun . stdout . toString ( )
113- var actualError = this . lastRun . error
114- var actualStderr = this . lastRun . stderr . toString ( )
115135 var lines
116136
117137 if ( noDebug ) {
@@ -120,12 +140,15 @@ module.exports = function coreSteps () {
120140 } )
121141 actualOutput = lines . join ( '\n' )
122142 }
143+ if ( like && actualOutput . indexOf ( expectedOutput ) >= 0 ) {
144+ return callback ( )
145+ }
123146
124147 if ( actualOutput . indexOf ( expectedOutput ) === 0 ) {
125148 return callback ( )
126149 }
127150
128- if ( actualError || actualStderr ) {
151+ if ( actualOutput ) {
129152 return callback ( new Error ( 'Expected output to match the following:\n ' + expectedOutput + '\nGot:\n ' + actualOutput ) )
130153 }
131154
@@ -159,4 +182,12 @@ module.exports = function coreSteps () {
159182 callback ( new Error ( 'Expected output to match the following:\n ' + expectedOutput + '\nGot:\n ' + actualOutput ) )
160183 }
161184 } )
185+
186+ this . Then ( / ^ T h e s e r v e r i s d e a d ( w i t h e x i t c o d e ( [ 0 - 9 ] + ) ) ? $ / , function ( withExitCode , code , callback ) {
187+ setTimeout ( ( function ( _this ) {
188+ if ( _this . childExitCode === undefined ) return callback ( new Error ( 'Server has not exited.' ) )
189+ if ( code === undefined || parseInt ( code , 10 ) === _this . childExitCode ) return callback ( )
190+ callback ( new Error ( 'Exit-code mismatch' ) )
191+ } ) ( this ) , 1000 )
192+ } )
162193}
0 commit comments