From 74ea0479938e890fde04bf4073d0ade8dfb12bae Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <76155456+pulkit-30@users.noreply.github.com> Date: Fri, 6 Jan 2023 18:05:35 +0530 Subject: [PATCH] test: fix tap parser fails if a test logs a number --- lib/internal/test_runner/tap_parser.js | 10 ++++++++- .../parallel/test-runner-tap-parser-stream.js | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/internal/test_runner/tap_parser.js b/lib/internal/test_runner/tap_parser.js index abb581cda103a2..69fee4aaba0fba 100644 --- a/lib/internal/test_runner/tap_parser.js +++ b/lib/internal/test_runner/tap_parser.js @@ -644,8 +644,16 @@ class TapParser extends Transform { } const planEnd = this.#next(); - if (planEnd?.kind !== TokenKind.NUMERIC) { + if (!planEnd || planEnd.kind !== TokenKind.NUMERIC) { this.#error('Expected a plan end count'); + const node = { + kind: TokenKind.UNKNOWN, + node: { + value: this.#currentChunkAsString, + }, + }; + + return node; } const plan = { diff --git a/test/parallel/test-runner-tap-parser-stream.js b/test/parallel/test-runner-tap-parser-stream.js index bd10af29d88279..f07f88c46cb5c5 100644 --- a/test/parallel/test-runner-tap-parser-stream.js +++ b/test/parallel/test-runner-tap-parser-stream.js @@ -17,6 +17,28 @@ const cases = [ }, ], }, + { + input: '123', + expected: [ + { + kind: 'Unknown', + node: { value: '123' }, + nesting: 0, + lexeme: '123', + }, + ], + }, + { + input: '# 123', + expected: [ + { + kind: 'Comment', + node: { comment: '123' }, + nesting: 0, + lexeme: '# 123', + }, + ], + }, { input: 'invalid tap', expected: [