Skip to content

Commit 1e8c451

Browse files
author
Jyri Kytömäki
committed
Wait until streams are completed before exiting
to prevent output cropping when jasmine is called form another process
1 parent 0825d32 commit 1e8c451

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

lib/jasmine.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,22 @@ Jasmine.prototype.stopOnSpecFailure = function(value) {
197197
};
198198

199199
Jasmine.prototype.exitCodeCompletion = function(passed) {
200-
if(passed) {
201-
this.exit(0);
202-
}
203-
else {
204-
this.exit(1);
200+
var jasmineRunner = this;
201+
var streams = [process.stdout, process.stderr];
202+
var writesToWait = streams.length;
203+
streams.forEach(function(stream) {
204+
stream.write('', exitIfAllStreamsCompleted);
205+
});
206+
function exitIfAllStreamsCompleted() {
207+
writesToWait--;
208+
if (writesToWait === 0) {
209+
if(passed) {
210+
jasmineRunner.exit(0);
211+
}
212+
else {
213+
jasmineRunner.exit(1);
214+
}
215+
}
205216
}
206217
};
207218

spec/jasmine_spec.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,16 +444,26 @@ describe('Jasmine', function() {
444444
this.testJasmine.exit = exitSpy;
445445

446446
this.testJasmine.exitCodeCompletion(true);
447-
expect(exitSpy).toHaveBeenCalledWith(0);
447+
sleep(10).then(function() {
448+
expect(exitSpy).toHaveBeenCalledWith(0);
449+
});
448450
});
449451

450452
it('exits with a failure when anything in the suite is not green', function() {
451453
var exitSpy = jasmine.createSpy('exit');
452454
this.testJasmine.exit = exitSpy;
453455

454456
this.testJasmine.exitCodeCompletion(false);
455-
expect(exitSpy).toHaveBeenCalledWith(1);
457+
sleep(10).then(function() {
458+
expect(exitSpy).toHaveBeenCalledWith(1);
459+
});
456460
});
461+
462+
function sleep(ms) {
463+
return new Promise(function(resolve) {
464+
setTimeout(resolve, ms);
465+
});
466+
}
457467
});
458468
});
459469
});

0 commit comments

Comments
 (0)