From b21781d4a9f11831b294cb15ee6c16c5c89f6522 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 14 Jun 2024 15:42:38 -0700 Subject: [PATCH] [Tests] add failing test for #550 --- test/plan_failure.js | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 test/plan_failure.js diff --git a/test/plan_failure.js b/test/plan_failure.js new file mode 100644 index 00000000..7835188e --- /dev/null +++ b/test/plan_failure.js @@ -0,0 +1,96 @@ +'use strict'; + +var tape = require('../'); +var tap = require('tap'); +var concat = require('concat-stream'); + +var stripFullStack = require('./common').stripFullStack; + +tap.test('one plan with end fails, next plan succeeds', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + var count = 0; + test.createStream().pipe(concat(function (body) { + tt.same(stripFullStack(body.toString('utf8')), [].concat( + 'TAP version 13', + '# failed plan', + 'not ok ' + ++count + ' plan != count', + ' ---', + ' operator: fail', + ' expected: 1', + ' actual: 0', + ' at: Test. ($TEST/plan_failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: plan != count', + ' [... stack stripped ...]', + ' at Test. ($TEST/plan_failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '# still called', + '# ------------ called?', + 'ok ' + ++count + ' passes!', + '', + '1..' + count, + '# tests ' + count, + '# pass 1', + '# fail 1', + '' + )); + })); + + test('failed plan', function (t) { + t.plan(1); + t.end(); + }); + + test('still called', function (t) { + t.comment('------------ called?'); + t.plan(1); + t.pass('passes!'); + }); +}); + +tap.test('one plan without end fails, next plan succeeds', function (tt) { + tt.plan(1); + + var test = tape.createHarness(); + var count = 0; + test.createStream().pipe(concat(function (body) { + tt.same(stripFullStack(body.toString('utf8')), [].concat( + 'TAP version 13', + '# failed plan', + 'not ok ' + ++count + ' plan != count', + ' ---', + ' operator: fail', + ' expected: 1', + ' actual: 0', + ' at: Test. ($TEST/plan_failure.js:$LINE:$COL)', + ' stack: |-', + ' Error: plan != count', + ' [... stack stripped ...]', + ' at Test. ($TEST/plan_failure.js:$LINE:$COL)', + ' [... stack stripped ...]', + ' ...', + '# still called', + '# ------------ called?', + 'ok ' + ++count + ' passes!', + '', + '1..' + count, + '# tests ' + count, + '# pass 1', + '# fail 1', + '' + )); + })); + + test('failed plan', function (t) { + t.plan(1); + }); + + test('still called', function (t) { + t.comment('------------ called?'); + t.plan(1); + t.pass('passes!'); + }); +});