Skip to content

Commit b74c4fd

Browse files
committed
Partial revert of #403: fbe4b95 and 367b010
Fixes #459. Reopens #222.
1 parent 34b1832 commit b74c4fd

File tree

5 files changed

+35
-159
lines changed

5 files changed

+35
-159
lines changed

lib/test.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,6 @@ var getTestArgs = function (name_, opts_, cb_) {
3939
return { name: name, opts: opts, cb: cb };
4040
};
4141

42-
var runProgeny = function () {
43-
var self = this;
44-
if (this._progeny.length) {
45-
var t = this._progeny.shift();
46-
t.on('end', function () { runProgeny.call(self) });
47-
nextTick(function () {
48-
t.run();
49-
});
50-
return;
51-
}
52-
if (this.calledEnd || this._plan) {
53-
this._end();
54-
}
55-
};
56-
5742
function Test (name_, opts_, cb_) {
5843
if (! (this instanceof Test)) {
5944
return new Test(name_, opts_, cb_);
@@ -120,11 +105,19 @@ Test.prototype.test = function (name, opts, cb) {
120105
this.emit('test', t);
121106
t.on('prerun', function () {
122107
self.assertCount++;
123-
});
108+
})
124109

125-
if (!this._pendingAsserts()) {
126-
runProgeny.call(this);
110+
if (!self._pendingAsserts()) {
111+
nextTick(function () {
112+
self._end();
113+
});
127114
}
115+
116+
nextTick(function() {
117+
if (!self._plan && self.pendingCount == self._progeny.length) {
118+
self._end();
119+
}
120+
});
128121
};
129122

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

142-
Test.prototype.timeoutAfter = function (ms) {
135+
Test.prototype.timeoutAfter = function(ms) {
143136
if (!ms) throw new Error('timeoutAfter requires a timespan');
144137
var self = this;
145-
var timeout = safeSetTimeout(function () {
138+
var timeout = safeSetTimeout(function() {
146139
self.fail('test timed out after ' + ms + 'ms');
147140
self.end();
148141
}, ms);
149-
this.once('end', function () {
142+
this.once('end', function() {
150143
safeClearTimeout(timeout);
151144
});
152145
}
153146

154147
Test.prototype.end = function (err) {
148+
var self = this;
155149
if (arguments.length >= 1 && !!err) {
156150
this.ifError(err);
157151
}
@@ -160,10 +154,18 @@ Test.prototype.end = function (err) {
160154
this.fail('.end() called twice');
161155
}
162156
this.calledEnd = true;
163-
runProgeny.call(this);
157+
this._end();
164158
};
165159

166160
Test.prototype._end = function (err) {
161+
var self = this;
162+
if (this._progeny.length) {
163+
var t = this._progeny.shift();
164+
t.on('end', function () { self._end() });
165+
t.run();
166+
return;
167+
}
168+
167169
if (!this.ended) this.emit('end');
168170
var pendingAsserts = this._pendingAsserts();
169171
if (!this._planError && this._plan !== undefined && pendingAsserts) {
@@ -298,7 +300,9 @@ Test.prototype._assert = function assert (ok, opts) {
298300
if (extra.exiting) {
299301
self._end();
300302
} else {
301-
runProgeny.call(self);
303+
nextTick(function () {
304+
self._end();
305+
});
302306
}
303307
}
304308

test/add-subtest-async.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ test('parent', function (t) {
77
st.pass('child');
88
st.end();
99
});
10-
t.end();
1110
}, 100);
1211
})

test/async_end.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/nested-sync-noplan-noend.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
var tape = require('../');
22
var tap = require('tap');
33
var concat = require('concat-stream');
4-
var stripFullStack = require('./common').stripFullStack;
54

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

98
var test = tape.createHarness();
109
var tc = function (rows) {
11-
tt.same(stripFullStack(rows.toString('utf8')), [
10+
tt.same(rows.toString('utf8'), [
1211
'TAP version 13',
1312
'# nested without plan or end',
14-
'not ok 1 test timed out after 100ms',
15-
' ---',
16-
' operator: fail',
17-
' stack: |-',
18-
' Error: test timed out after 100ms',
19-
' [... stack stripped ...]',
20-
' ...',
2113
'# first',
22-
'ok 2 should be truthy',
14+
'ok 1 should be truthy',
2315
'# second',
24-
'ok 3 should be truthy',
16+
'ok 2 should be truthy',
2517
'',
26-
'1..3',
27-
'# tests 3',
18+
'1..2',
19+
'# tests 2',
2820
'# pass 2',
29-
'# fail 1',
21+
'',
22+
'# ok'
3023
].join('\n') + '\n');
3124
};
3225

@@ -45,7 +38,6 @@ tap.test('nested sync test without plan or end', function (tt) {
4538
q.end()
4639
}, 10);
4740
});
48-
49-
t.timeoutAfter(100);
5041
});
42+
5143
});

test/nested_test_ordering.js

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)