From 0cee8c5cd86d9193e2f32b31fafcc54edc825731 Mon Sep 17 00:00:00 2001 From: Raynos Date: Mon, 2 Mar 2020 14:36:27 +0100 Subject: [PATCH] [patch] Print name of test that didnt end A stack trace should be actionable. --- lib/test.js | 2 +- test/exit.js | 33 +++++++++++++++++++++++++++++++++ test/exit/missing_end.js | 12 ++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/exit/missing_end.js diff --git a/lib/test.js b/lib/test.js index 42e16bd9..c72b65b7 100644 --- a/lib/test.js +++ b/lib/test.js @@ -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 }); } diff --git a/test/exit.js b/test/exit.js index 326520f3..4e61ab74 100644 --- a/test/exit.js +++ b/test/exit.js @@ -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. ($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); + }); +}); diff --git a/test/exit/missing_end.js b/test/exit/missing_end.js new file mode 100644 index 00000000..7616fec1 --- /dev/null +++ b/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); +});