Skip to content

Commit

Permalink
Partial revert of #403: fbe4b95 and 367b010
Browse files Browse the repository at this point in the history
Fixes #459. Reopens #222.
  • Loading branch information
ljharb committed Feb 13, 2019
1 parent 34b1832 commit b74c4fd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 159 deletions.
50 changes: 27 additions & 23 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,6 @@ var getTestArgs = function (name_, opts_, cb_) {
return { name: name, opts: opts, cb: cb };
};

var runProgeny = function () {
var self = this;
if (this._progeny.length) {
var t = this._progeny.shift();
t.on('end', function () { runProgeny.call(self) });
nextTick(function () {
t.run();
});
return;
}
if (this.calledEnd || this._plan) {
this._end();
}
};

function Test (name_, opts_, cb_) {
if (! (this instanceof Test)) {
return new Test(name_, opts_, cb_);
Expand Down Expand Up @@ -120,11 +105,19 @@ Test.prototype.test = function (name, opts, cb) {
this.emit('test', t);
t.on('prerun', function () {
self.assertCount++;
});
})

if (!this._pendingAsserts()) {
runProgeny.call(this);
if (!self._pendingAsserts()) {
nextTick(function () {
self._end();
});
}

nextTick(function() {
if (!self._plan && self.pendingCount == self._progeny.length) {
self._end();
}
});
};

Test.prototype.comment = function (msg) {
Expand All @@ -139,19 +132,20 @@ Test.prototype.plan = function (n) {
this.emit('plan', n);
};

Test.prototype.timeoutAfter = function (ms) {
Test.prototype.timeoutAfter = function(ms) {
if (!ms) throw new Error('timeoutAfter requires a timespan');
var self = this;
var timeout = safeSetTimeout(function () {
var timeout = safeSetTimeout(function() {
self.fail('test timed out after ' + ms + 'ms');
self.end();
}, ms);
this.once('end', function () {
this.once('end', function() {
safeClearTimeout(timeout);
});
}

Test.prototype.end = function (err) {
var self = this;
if (arguments.length >= 1 && !!err) {
this.ifError(err);
}
Expand All @@ -160,10 +154,18 @@ Test.prototype.end = function (err) {
this.fail('.end() called twice');
}
this.calledEnd = true;
runProgeny.call(this);
this._end();
};

Test.prototype._end = function (err) {
var self = this;
if (this._progeny.length) {
var t = this._progeny.shift();
t.on('end', function () { self._end() });
t.run();
return;
}

if (!this.ended) this.emit('end');
var pendingAsserts = this._pendingAsserts();
if (!this._planError && this._plan !== undefined && pendingAsserts) {
Expand Down Expand Up @@ -298,7 +300,9 @@ Test.prototype._assert = function assert (ok, opts) {
if (extra.exiting) {
self._end();
} else {
runProgeny.call(self);
nextTick(function () {
self._end();
});
}
}

Expand Down
1 change: 0 additions & 1 deletion test/add-subtest-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ test('parent', function (t) {
st.pass('child');
st.end();
});
t.end();
}, 100);
})
21 changes: 0 additions & 21 deletions test/async_end.js

This file was deleted.

24 changes: 8 additions & 16 deletions test/nested-sync-noplan-noend.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
var tape = require('../');
var tap = require('tap');
var concat = require('concat-stream');
var stripFullStack = require('./common').stripFullStack;

tap.test('nested sync test without plan or end', function (tt) {
tt.plan(1);

var test = tape.createHarness();
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
tt.same(rows.toString('utf8'), [
'TAP version 13',
'# nested without plan or end',
'not ok 1 test timed out after 100ms',
' ---',
' operator: fail',
' stack: |-',
' Error: test timed out after 100ms',
' [... stack stripped ...]',
' ...',
'# first',
'ok 2 should be truthy',
'ok 1 should be truthy',
'# second',
'ok 3 should be truthy',
'ok 2 should be truthy',
'',
'1..3',
'# tests 3',
'1..2',
'# tests 2',
'# pass 2',
'# fail 1',
'',
'# ok'
].join('\n') + '\n');
};

Expand All @@ -45,7 +38,6 @@ tap.test('nested sync test without plan or end', function (tt) {
q.end()
}, 10);
});

t.timeoutAfter(100);
});

});
98 changes: 0 additions & 98 deletions test/nested_test_ordering.js

This file was deleted.

0 comments on commit b74c4fd

Please sign in to comment.