Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 1bdfc97

Browse files
author
Gabriel Schulhof
committed
Runner: Clean up processes after each test
1 parent 3faa36f commit 1bdfc97

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

index.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function spawnOne( assert, options ) {
6363
}
6464

6565
theChild = options.spawn( options.interpreter, commandLine );
66+
theChild.path = options.path;
6667

6768
runningProcesses.push( theChild );
6869

@@ -169,32 +170,50 @@ var actualOptions = {
169170
_.map( options.tests, function( item ) {
170171
return path.join( __dirname, "tests", item );
171172
} ) :
172-
( glob.sync( path.join( __dirname, "tests", "*" ) ) ) )
173+
( glob.sync( path.join( __dirname, "tests", "*" ) ) ) ).map( path.normalize )
173174
};
174175

175176
if ( actualOptions.tests.length === 0 ) {
176177
console.log( "*** No tests were requested ***" );
177178
}
178179

180+
getQUnit().module( "OCF tests", {
181+
beforeEach: function() {
182+
this.children = [];
183+
},
184+
afterEach: function() {
185+
this.children.forEach( function( childProcess ) {
186+
console.log( "Killing child process " + childProcess.path );
187+
childProcess.removeAllListeners();
188+
childProcess.kill( "SIGKILL" );
189+
} );
190+
}
191+
} );
192+
179193
_.each( actualOptions.tests, function( item ) {
180194
var clientPathIndex,
181-
clientPaths = glob.sync( path.join( item, "client*.js" ) ),
195+
clientPaths = glob.sync( path.join( item, "client*.js" ) ).map( path.normalize ),
182196
serverPath = path.join( item, "server.js" );
183197

184198
if ( fs.lstatSync( item ).isFile() && !actualOptions.single.skip ) {
185199
getQUnit()
186200
.test( path.basename( item ).replace( /\.js$/, "" ), function( assert ) {
187-
spawnOne( assert,
201+
var done = assert.async();
202+
var children = this.children;
203+
children.push( spawnOne( assert,
188204
_.extend( {}, actualOptions.single, {
189205
uuid: uuid.v4(),
190206
name: "Test",
191207
path: item,
192208
teardown: function( error, sourceProcess ) {
193209
sourceProcess.kill( "SIGINT" );
194210
},
195-
maybeQuit: assert.async(),
211+
maybeQuit: function() {
212+
children.pop();
213+
done();
214+
},
196215
reportAssertions: _.bind( assert.expect, assert )
197-
} ) );
216+
} ) ) );
198217
} );
199218
return;
200219
}
@@ -217,7 +236,7 @@ _.each( actualOptions.tests, function( item ) {
217236
var totalChildren = clientPaths.length + 1,
218237

219238
// Track the child processes involved in this test in this array
220-
children = [],
239+
children = this.children,
221240

222241
// Turn this test async
223242
done = assert.async(),

0 commit comments

Comments
 (0)