Skip to content

Commit

Permalink
src: Print name of test that didnt end
Browse files Browse the repository at this point in the history
A stacktrace should be actionable.
  • Loading branch information
Raynos committed Mar 2, 2020
1 parent 1ab6bdb commit e542c3d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

# Only apps should have lockfiles
yarn.lock
.vscode/
package-lock.json
2 changes: 1 addition & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,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
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,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
Original file line number Diff line number Diff line change
@@ -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 e542c3d

Please sign in to comment.