Skip to content

Commit 0cee8c5

Browse files
Raynosljharb
authored andcommitted
[patch] Print name of test that didnt end
A stack trace should be actionable.
1 parent 1ab6bdb commit 0cee8c5

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

lib/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Test.prototype._exit = function () {
214214
exiting: true
215215
});
216216
} else if (!this.ended) {
217-
this.fail('test exited without ending', {
217+
this.fail('test exited without ending: ' + this.name, {
218218
exiting: true
219219
});
220220
}

test/exit.js

+33
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,36 @@ tap.test('todo failing', function (t) {
204204
t.equal(code, 0);
205205
});
206206
});
207+
208+
tap.test('forgot to call t.end()', function (t) {
209+
t.plan(2);
210+
211+
var tc = function (rows) {
212+
t.same(stripFullStack(rows.toString('utf8')), [
213+
'TAP version 13',
214+
'# first',
215+
'ok 1 should be truthy',
216+
'# oops forgot end',
217+
'ok 2 should be truthy',
218+
'not ok 3 test exited without ending: oops forgot end',
219+
' ---',
220+
' operator: fail',
221+
' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
222+
' stack: |-',
223+
' Error: test exited without ending: oops forgot end',
224+
' [... stack stripped ...]',
225+
' ...',
226+
'',
227+
'1..3',
228+
'# tests 3',
229+
'# pass 2',
230+
'# fail 1'
231+
].join('\n') + '\n\n');
232+
};
233+
234+
var ps = spawn(process.execPath, [path.join(__dirname, '/exit/missing_end.js')]);
235+
ps.stdout.pipe(concat(tc));
236+
ps.on('exit', function (code) {
237+
t.notEqual(code, 0);
238+
});
239+
});

test/exit/missing_end.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
var test = require('../../');
4+
5+
test('first', function (t) {
6+
t.ok(true);
7+
t.end();
8+
});
9+
10+
test('oops forgot end', function (t) {
11+
t.ok(true);
12+
});

0 commit comments

Comments
 (0)