diff --git a/lib/internal/test_runner/tap_parser.js b/lib/internal/test_runner/tap_parser.js index 54fdbe4..94b06c0 100644 --- a/lib/internal/test_runner/tap_parser.js +++ b/lib/internal/test_runner/tap_parser.js @@ -1,4 +1,4 @@ -// https://github.com/nodejs/node/blob/931f035bac8326a11f42fc05463d5b21d9bec502/lib/internal/test_runner/tap_parser.js +// https://github.com/nodejs/node/blob/4c08c20e575a0954fe3977a20e9f52b4980a2e48/lib/internal/test_runner/tap_parser.js 'use strict' const { @@ -271,8 +271,19 @@ class TapParser extends Transform { this.#yamlCurrentIndentationLevel = this.#subTestNestingLevel } + let node + // Parse current chunk - const node = this.#TAPDocument(chunk) + try { + node = this.#TAPDocument(chunk) + } catch { + node = { + kind: TokenKind.UNKNOWN, + node: { + value: this.#currentChunkAsString + } + } + } // Emit the parsed node to both the stream and the AST this.#emitOrBufferCurrentNode(node) @@ -283,12 +294,6 @@ class TapParser extends Transform { } #error (message) { - if (!this.#isSyncParsingEnabled) { - // When async parsing is enabled, don't throw. - // Unrecognized tokens would be ignored. - return - } - const token = this.#currentToken || { value: '', kind: '' } // Escape NewLine characters if (token.value === '\n') { diff --git a/test/parallel/test-runner-tap-parser-stream.js b/test/parallel/test-runner-tap-parser-stream.js index ad92866..6a91d00 100644 --- a/test/parallel/test-runner-tap-parser-stream.js +++ b/test/parallel/test-runner-tap-parser-stream.js @@ -1,4 +1,4 @@ -// https://github.com/nodejs/node/blob/f8ce9117b19702487eb600493d941f7876e00e01/test/parallel/test-runner-tap-parser-stream.js +// https://github.com/nodejs/node/blob/4c08c20e575a0954fe3977a20e9f52b4980a2e48/test/parallel/test-runner-tap-parser-stream.js // Flags: --expose-internals 'use strict' const common = require('../common') @@ -19,6 +19,193 @@ 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: '1..', + expected: [ + { + kind: 'Unknown', + node: { value: '1..' }, + nesting: 0, + lexeme: '1..' + } + ] + }, + { + input: '1..abc', + expected: [ + { + kind: 'Unknown', + node: { value: '1..abc' }, + nesting: 0, + lexeme: '1..abc' + } + ] + }, + { + input: '1..-1', + expected: [ + { + kind: 'Unknown', + node: { value: '1..-1' }, + nesting: 0, + lexeme: '1..-1' + } + ] + }, + { + input: '1.1', + expected: [ + { + kind: 'Unknown', + node: { value: '1.1' }, + nesting: 0, + lexeme: '1.1' + } + ] + }, + { + input: '1.....4', + expected: [ + { + kind: 'Unknown', + node: { value: '1.....4' }, + nesting: 0, + lexeme: '1.....4' + } + ] + }, + { + input: 'TAP 12', + expected: [ + { + kind: 'Unknown', + node: { value: 'TAP 12' }, + nesting: 0, + lexeme: 'TAP 12' + } + ] + }, + { + input: 'TAP version', + expected: [ + { + kind: 'Unknown', + node: { value: 'TAP version' }, + nesting: 0, + lexeme: 'TAP version' + } + ] + }, + { + input: 'TAP version v14', + expected: [ + { + kind: 'Unknown', + node: { value: 'TAP version v14' }, + nesting: 0, + lexeme: 'TAP version v14' + } + ] + }, + { + input: 'TAP TAP TAP', + expected: [ + { + kind: 'Unknown', + node: { value: 'TAP TAP TAP' }, + nesting: 0, + lexeme: 'TAP TAP TAP' + } + ] + }, + { + input: '--- yaml', + expected: [ + { + kind: 'Unknown', + node: { value: '--- yaml' }, + nesting: 0, + lexeme: '--- yaml' + } + ] + }, + { + input: '... ... yaml', + expected: [ + { + kind: 'Unknown', + node: { value: '... ... yaml' }, + nesting: 0, + lexeme: '... ... yaml' + } + ] + }, + { + input: 'ook 1', + expected: [ + { + kind: 'Unknown', + node: { value: 'ook 1' }, + nesting: 0, + lexeme: 'ook 1' + } + ] + }, + { + input: ' ok 98', + expected: [ + { + kind: 'Unknown', + node: { value: ' ok 98' }, + nesting: 0, + lexeme: ' ok 98' + } + ] + }, + { + input: 'pragma ++++++', + expected: [ + { + kind: 'Unknown', + node: { value: 'pragma ++++++' }, + nesting: 0, + lexeme: 'pragma ++++++' + } + ] + }, + { + input: 'Bailout!', + expected: [ + { + kind: 'Unknown', + node: { value: 'Bailout!' }, + nesting: 0, + lexeme: 'Bailout!' + } + ] + }, { input: 'invalid tap', expected: [ diff --git a/test/parallel/test-runner-tap-parser.js b/test/parallel/test-runner-tap-parser.js index aa6fbb4..90babc9 100644 --- a/test/parallel/test-runner-tap-parser.js +++ b/test/parallel/test-runner-tap-parser.js @@ -1,4 +1,4 @@ -// https://github.com/nodejs/node/blob/f8ce9117b19702487eb600493d941f7876e00e01/test/parallel/test-runner-tap-parser.js +// https://github.com/nodejs/node/blob/4c08c20e575a0954fe3977a20e9f52b4980a2e48/test/parallel/test-runner-tap-parser.js 'use strict' // Flags: --expose-internals @@ -76,24 +76,6 @@ function TAPParser (input) { ]) } -{ - assert.throws(() => TAPParser('TAP version'), { - name: 'SyntaxError', - code: 'ERR_TAP_PARSER_ERROR', - message: - 'Expected a version number, received "version" (VersionKeyword) at line 1, column 5 (start 4, end 10)' - }) -} - -{ - assert.throws(() => TAPParser('TAP'), { - name: 'SyntaxError', - code: 'ERR_TAP_PARSER_ERROR', - message: - 'Expected "version" keyword, received "TAP" (TAPKeyword) at line 1, column 1 (start 0, end 2)' - }) -} - // Test plan { @@ -126,42 +108,6 @@ function TAPParser (input) { ]) } -{ - assert.throws(() => TAPParser('1..'), { - name: 'SyntaxError', - code: 'ERR_TAP_PARSER_ERROR', - message: - 'Expected a plan end count, received "" (EOL) at line 1, column 4 (start 3, end 3)' - }) -} - -{ - assert.throws(() => TAPParser('1..abc'), { - name: 'SyntaxError', - code: 'ERR_TAP_PARSER_ERROR', - message: - 'Expected ".." symbol, received "..abc" (Literal) at line 1, column 2 (start 1, end 5)' - }) -} - -{ - assert.throws(() => TAPParser('1..-1'), { - name: 'SyntaxError', - code: 'ERR_TAP_PARSER_ERROR', - message: - 'Expected a plan end count, received "-" (Dash) at line 1, column 4 (start 3, end 3)' - }) -} - -{ - assert.throws(() => TAPParser('1.1'), { - name: 'SyntaxError', - code: 'ERR_TAP_PARSER_ERROR', - message: - 'Expected ".." symbol, received "." (Literal) at line 1, column 2 (start 1, end 1)' - }) -} - // Test point { @@ -917,24 +863,6 @@ ok 6 - nested1 ]) } -{ - assert.throws( - () => - TAPParser( - ` - message: 'description' - property: 'value' - ...` - ), - { - name: 'SyntaxError', - code: 'ERR_TAP_PARSER_ERROR', - message: - 'Unexpected YAML end marker, received "..." (YamlEndKeyword) at line 4, column 3 (start 48, end 50)' - } - ) -} - { assert.throws( () => @@ -953,26 +881,6 @@ ok 6 - nested1 ) } -{ - assert.throws( - () => - // Note the leading 3 spaces before --- - TAPParser( - ` - --- - message: 'description' - property: 'value' - ...` - ), - { - name: 'SyntaxError', - code: 'ERR_TAP_PARSER_ERROR', - message: - 'Expected valid YAML indentation (2 spaces), received " " (Whitespace) at line 2, column 3 (start 3, end 3)' - } - ) -} - { assert.throws( () => @@ -998,27 +906,6 @@ ok 6 - nested1 ) } -{ - assert.throws( - () => - // Note the leading 4 spaces before --- - TAPParser( - ` - --- - message: 'description' - property: 'value' - ... - ` - ), - { - name: 'SyntaxError', - code: 'ERR_TAP_PARSER_ERROR', - message: - 'Expected a valid token, received "---" (YamlStartKeyword) at line 2, column 5 (start 5, end 7)' - } - ) -} - { assert.throws( () => @@ -1070,26 +957,6 @@ ok 6 - nested1 ]) } -// Non-recognized - -{ - assert.throws(() => TAPParser('abc'), { - name: 'SyntaxError', - code: 'ERR_TAP_PARSER_ERROR', - message: - 'Expected a valid token, received "abc" (Literal) at line 1, column 1 (start 0, end 2)' - }) -} - -{ - assert.throws(() => TAPParser(' abc'), { - name: 'SyntaxError', - code: 'ERR_TAP_PARSER_ERROR', - message: - 'Expected a valid token, received "abc" (Literal) at line 1, column 5 (start 4, end 6)' - }) -} - // TAP document (with diagnostics) {