Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
012acb0
feat: verbous error when entire test tree is canceled
MoLow Aug 2, 2022
d885ee2
feat: support programmatically running `--test`
MoLow Aug 15, 2022
27241c3
fix: fix `duration_ms` to be milliseconds
MoLow Sep 4, 2022
6755536
feat: support using `--inspect` with `--test`
MoLow Sep 10, 2022
c50f844
fix: include stack of uncaught exceptions
MoLow Sep 14, 2022
1950b38
test: fix test-runner-inspect
MoLow Sep 14, 2022
c5fd64c
feat: add --test-name-pattern CLI flag
cjihrig Sep 1, 2022
46dce07
feat: add extra fields in AssertionError YAML
bengl Oct 26, 2022
0bfdb77
fix: call {before,after}Each() on suites
cjihrig Oct 27, 2022
08269c5
fix: report tap subtest in order
MoLow Oct 28, 2022
f2815af
fix: fix afterEach not running on test failures
MrJithil Nov 7, 2022
cff397a
fix: avoid swallowing of asynchronously thrown errors
fossamagna Nov 7, 2022
2e499ee
feat: support function mocking
cjihrig Apr 4, 2022
5f8ce61
feat: add initial TAP parser
manekinekko Nov 21, 2022
5ba2500
fix: remove stdout and stderr from error
cjihrig Nov 25, 2022
b942f93
feat: add getter and setter to MockTracker
fossamagna Nov 18, 2022
b3b384e
fix: don't use a symbol for runHook()
cjihrig Dec 6, 2022
71b659e
feat: add t.after() hook
cjihrig Dec 8, 2022
c0854ac
test: fix invalid output TAP if there newline in test name
pulkit-30 Dec 11, 2022
9b49978
chore: refactor `tap_parser` to use more primordials
aduh95 Dec 11, 2022
4e778bc
chore: refactor `tap_lexer` to use more primordials
aduh95 Dec 12, 2022
d1343a7
feat: parse yaml
MoLow Dec 13, 2022
c80e426
fix: run t.after() if test body throws
cjihrig Dec 17, 2022
9fa496b
test: fix mock.method to support class instances
ErickWendel Dec 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: refactor tap_lexer to use more primordials
PR-URL: nodejs/node#45744
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
(cherry picked from commit 2483da743cbb48f31c6b3f8cb186d89f31d73611)
  • Loading branch information
aduh95 authored and MoLow committed Feb 2, 2023
commit 4e778bc4995cd1b6a250557c4651fd53eabf1aaf
38 changes: 22 additions & 16 deletions lib/internal/test_runner/tap_lexer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// https://github.com/nodejs/node/blob/f8ce9117b19702487eb600493d941f7876e00e01/lib/internal/test_runner/tap_lexer.js
// https://github.com/nodejs/node/blob/2483da743cbb48f31c6b3f8cb186d89f31d73611/lib/internal/test_runner/tap_lexer.js
'use strict'

const { SafeSet, MathMax, StringPrototypeIncludes } = require('#internal/per_context/primordials')
const {
ArrayPrototypePop,
ArrayPrototypePush,
MathMax,
SafeSet,
StringPrototypeIncludes,
StringPrototypeTrim
} = require('#internal/per_context/primordials')
const {
codes: { ERR_TAP_LEXER_ERROR }
} = require('#internal/errors')
Expand Down Expand Up @@ -137,21 +144,21 @@ class TapLexer {
this.#lastScannedToken = token
}

ArrayPrototypePush(chunk, token)
if (token.kind === TokenKind.NEWLINE) {
// Store the current chunk + NEWLINE token
tokens.push([...chunk, token])
ArrayPrototypePush(tokens, chunk)
chunk = []
} else {
chunk.push(token)
}
}

if (chunk.length > 0) {
tokens.push([...chunk, this.#scanEOL()])
ArrayPrototypePush(chunk, this.#scanEOL())
ArrayPrototypePush(tokens, chunk)
}

// send EOF as a separate chunk
tokens.push([this.#scanEOF()])
ArrayPrototypePush(tokens, [this.#scanEOF()])

return tokens
}
Expand Down Expand Up @@ -239,7 +246,7 @@ class TapLexer {
this.#hasTheCurrentCharacterBeenEscaped() ||
this.#source.peek(1) === TokenKind.WHITESPACE
) {
this.#escapeStack.pop()
ArrayPrototypePop(this.#escapeStack)
return new Token({
kind: TokenKind.LITERAL,
value: char,
Expand All @@ -250,7 +257,7 @@ class TapLexer {
// Otherwise, consume the escape symbol as an escape symbol that should be ignored by the parser
// we also need to push the escape symbol to the escape stack
// and consume the next character as a literal (done in the next turn)
this.#escapeStack.push(char)
ArrayPrototypePush(this.#escapeStack, char)
return new Token({
kind: TokenKind.ESCAPE,
value: char,
Expand Down Expand Up @@ -327,7 +334,7 @@ class TapLexer {
const charHasBeenEscaped = this.#hasTheCurrentCharacterBeenEscaped()
if (this.#isComment || charHasBeenEscaped) {
if (charHasBeenEscaped) {
this.#escapeStack.pop()
ArrayPrototypePop(this.#escapeStack)
}

return new Token({
Expand Down Expand Up @@ -356,7 +363,7 @@ class TapLexer {
}
}

word = word.trim()
word = StringPrototypeTrim(word)

if (TapLexer.Keywords.has(word)) {
const token = this.#scanTAPKeyword(word)
Expand All @@ -381,10 +388,9 @@ class TapLexer {
}

#scanTAPKeyword (word) {
const isLastScannedTokenEOLorNewLine = StringPrototypeIncludes(
[TokenKind.EOL, TokenKind.NEWLINE],
this.#lastScannedToken.kind
)
const isLastScannedTokenEOLorNewLine =
TokenKind.EOL === this.#lastScannedToken.kind ||
TokenKind.NEWLINE === this.#lastScannedToken.kind

if (word === 'TAP' && isLastScannedTokenEOLorNewLine) {
return new Token({
Expand Down Expand Up @@ -480,7 +486,7 @@ class TapLexer {
// We deliberately do not include "# \ + -"" in this list
// these are used for comments/reasons explanations, pragma and escape characters
// whitespace is not included because it is handled separately
return '!"$%&\'()*,./:;<=>?@[]^_`{|}~'.indexOf(char) > -1
return StringPrototypeIncludes('!"$%&\'()*,./:;<=>?@[]^_`{|}~', char)
}

#isWhitespaceSymbol (char) {
Expand Down