Skip to content

Commit

Permalink
[patch] Print name of test that didnt end (#498)
Browse files Browse the repository at this point in the history
A stack trace should be actionable.
  • Loading branch information
Raynos authored and ljharb committed Mar 2, 2020
1 parent 98b2695 commit c4119c2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/test.js
Expand Up @@ -188,7 +188,7 @@ Test.prototype._exit = function () {
exiting: true
});
} else if (!this.ended) {
this.fail('test exited without ending', {
this.fail('test exited without ending: ' + this.name, {
exiting: true
});
}
Expand Down
33 changes: 33 additions & 0 deletions test/exit.js
Expand Up @@ -202,3 +202,36 @@ tap.test('todo failing', function (t) {
t.equal(code, 0);
});
});

tap.test('forgot to call t.end()', function (t) {
t.plan(2);

var tc = function (rows) {
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# first',
'ok 1 should be truthy',
'# oops forgot end',
'ok 2 should be truthy',
'not ok 3 test exited without ending: oops forgot end',
' ---',
' operator: fail',
' at: process.<anonymous> ($TAPE/index.js:$LINE:$COL)',
' stack: |-',
' Error: test exited without ending: oops forgot end',
' [... stack stripped ...]',
' ...',
'',
'1..3',
'# tests 3',
'# pass 2',
'# fail 1'
].join('\n') + '\n\n');
};

var ps = spawn(process.execPath, [path.join(__dirname, '/exit/missing_end.js')]);
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.notEqual(code, 0);
});
});
12 changes: 12 additions & 0 deletions test/exit/missing_end.js
@@ -0,0 +1,12 @@
'use strict';

var test = require('../../');

test('first', function (t) {
t.ok(true);
t.end();
});

test('oops forgot end', function (t) {
t.ok(true);
});

0 comments on commit c4119c2

Please sign in to comment.