Skip to content

Commit

Permalink
[Breaking] fail any assertion after .end() is called
Browse files Browse the repository at this point in the history
Fixes #264.
  • Loading branch information
ljharb committed Dec 30, 2019
1 parent 8e8af01 commit e925bb1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,18 @@ Test.prototype._assert = function assert(ok, opts) {

ok = !!ok || !!extra.skip;

var name = defined(extra.message, opts.message, '(unnamed assert)');
if (this.calledEnd && opts.operator !== 'fail') {
this.fail('.end() already called: ' + name);
return;
}

var res = {
id: self.assertCount++,
ok: ok,
skip: defined(extra.skip, opts.skip),
todo: defined(extra.todo, opts.todo, self._todo),
name: defined(extra.message, opts.message, '(unnamed assert)'),
name: name,
operator: defined(extra.operator, opts.operator),
objectPrintDepth: self._objectPrintDepth
};
Expand Down
26 changes: 22 additions & 4 deletions test/async-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,26 @@ tap.test('async5', function (t) {
'ok 3 before request',
'ok 4 after request',
'ok 5 res.statusCode is 200',
'ok 6 mockDb.state is new',
'ok 7 error on close',
'not ok 6 .end() already called: mockDb.state is new',
' ---',
' operator: fail',
' at: Timeout._onTimeout ($TEST/async-await/async5.js:$LINE:$COL)',
' stack: |-',
' Error: .end() already called: mockDb.state is new',
' [... stack stripped ...]',
' at Timeout._onTimeout ($TEST/async-await/async5.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 7 .end() already called: error on close',
' ---',
' operator: fail',
' at: Server.<anonymous> ($TEST/async-await/async5.js:$LINE:$COL)',
' stack: |-',
' Error: .end() already called: error on close',
' [... stack stripped ...]',
' at Server.<anonymous> ($TEST/async-await/async5.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 8 .end() already called',
' ---',
' operator: fail',
Expand All @@ -138,8 +156,8 @@ tap.test('async5', function (t) {
'',
'1..8',
'# tests 8',
'# pass 7',
'# fail 1'
'# pass 5',
'# fail 3'
].join('\n') + '\n\n');
t.same(r.exitCode, 1);
t.same(r.stderr.toString('utf8'), '');
Expand Down

0 comments on commit e925bb1

Please sign in to comment.