@@ -27,7 +27,11 @@ When('I stop a server programmatically', function (callback) {
2727} )
2828
2929When ( 'I start a server in background' , async function ( ) {
30- await this . runBackgroundProcess ( [ 'start' , '--log-level' , 'debug' , this . configFile ] )
30+ await this . runBackgroundProcess ( [ 'start' , this . configFile ] )
31+ } )
32+
33+ When ( 'I start a server in background with additional arguments: {string}' , async function ( args ) {
34+ await this . runBackgroundProcess ( [ 'start' , ...args . split ( ' ' ) , this . configFile ] )
3135} )
3236
3337When ( 'I wait until server output contains:' , async function ( expectedOutput ) {
@@ -50,6 +54,11 @@ When('I {command} Karma', async function (command) {
5054 await this . runForegroundProcess ( `${ command } ${ this . configFile } ` )
5155} )
5256
57+ When ( 'I touch file: {string}' , async function ( file ) {
58+ const now = new Date ( )
59+ await fs . promises . utimes ( path . join ( this . workDir , file ) , now , now )
60+ } )
61+
5362When ( 'I {command} Karma with additional arguments: {string}' , async function ( command , args ) {
5463 await this . runForegroundProcess ( `${ command } ${ this . configFile } ${ args } ` )
5564} )
@@ -149,3 +158,27 @@ Then(/^the file at ([a-zA-Z0-9/\\_.]+) contains:$/, function (filePath, expected
149158 throw new Error ( 'Expected output to match the following:\n ' + expectedOutput + '\nGot:\n ' + data )
150159 }
151160} )
161+
162+ Then ( / ^ t h e b a c k g r o u n d ( s t d o u t | s t d e r r ) ( i s e x a c t l y | c o n t a i n s | m a t c h e s R e g E x p ) : $ / , async function ( outputType , comparison , expectedOutput ) {
163+ const message = comparison === 'is exactly' ? 'Expected output to be exactly as above, but got:'
164+ : comparison === 'contains' ? 'Expected output to contain the above text, but got:'
165+ : 'Expected output to match the above RegExp, but got:'
166+
167+ await waitForCondition (
168+ ( ) => {
169+ const actualOutput = this . backgroundProcess [ outputType ] . trim ( )
170+ expectedOutput = expectedOutput . trim ( )
171+
172+ switch ( comparison ) {
173+ case 'is exactly' :
174+ return actualOutput === expectedOutput
175+ case 'contains' :
176+ return actualOutput . includes ( expectedOutput )
177+ case 'matches RegExp' :
178+ return new RegExp ( expectedOutput ) . test ( actualOutput )
179+ }
180+ } ,
181+ 5000 ,
182+ ( ) => new Error ( `${ message } \n\n${ this . backgroundProcess [ outputType ] } ` )
183+ )
184+ } )
0 commit comments