Skip to content

Commit

Permalink
Also set _forceStopped attribute to true when user uses ctrl+c to sto…
Browse files Browse the repository at this point in the history
…p the test runner.
  • Loading branch information
Kami committed May 4, 2011
1 parent 1117ef2 commit 64569f9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function TestRunner(tests, reporter, coverageReporter, coverage, verbosity) {
this._testFilesData = {};

this._completed = false;
this._forceStopped = false;
this._completedTests = [];
}

Expand Down Expand Up @@ -77,7 +78,7 @@ TestRunner.prototype.runTests = function(testInitFile, chdir,
async.forEachSeries(self._tests, function(filePath, callback) {
var cwd, child, timeoutId, testFileData;

if (self._completed) {
if (self._completed || self._forceStopped) {
callback(new Error('Runner has been stopped'));
return;
}
Expand Down Expand Up @@ -110,6 +111,7 @@ TestRunner.prototype.runTests = function(testInitFile, chdir,
child.on('exit', function() {
clearTimeout(timeoutId);
self._handleTestFileEnd(filePath);
delete self._testFilesData[filePath];
});
},

Expand Down Expand Up @@ -147,7 +149,7 @@ TestRunner.prototype._addCompletedTest = function(filePath) {
TestRunner.prototype._handleTestsCompleted = function() {
var statusCode;

if (!this._completed) {
if (!this._completed || this._forceStopped) {
this._completed = true;
this._stopServer();

Expand Down Expand Up @@ -186,7 +188,6 @@ TestRunner.prototype._handleTestFileEnd = function(filePath) {

if (testFile) {
testFile['callback']();
delete this._testFilesData[filePath];
}
};

Expand Down Expand Up @@ -235,6 +236,7 @@ TestRunner.prototype._startServer = function(socketPath, connectionHandler,
TestRunner.prototype.forceStop = function() {
var testFile, testFileData, child, timeoutId;

this._forceStopped = true;
for (testFile in this._testFilesData) {
if (this._testFilesData.hasOwnProperty(testFile)) {
testFileData = this._testFilesData[testFile];
Expand Down

0 comments on commit 64569f9

Please sign in to comment.