Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test runner breaks with ERR_TAP_LEXER_ERROR while trying a console.dir with colors flag set ( {colors: true} ) #46959

Closed
nickmilon opened this issue Mar 5, 2023 · 3 comments · Fixed by #47050
Labels
confirmed-bug Issues with confirmed bugs. test_runner Issues and PRs related to the test runner subsystem.

Comments

@nickmilon
Copy link

Version

v19.7.0

Platform

Linux lnv 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

test_runner

What steps will reproduce the bug?

// test-console_colors.js

import { it } from 'node:test'
const obj = { a: 1, b: 2}
it('test-console-no-colors', () => {
    console.dir(obj, { colors: false })
}); 

it('test-console-with-colors', () => {
    console.dir(obj, { colors: true })
}); 

node --test test-console_colors.js

How often does it reproduce? Is there a required condition?

always

What is the expected behavior?

should be same as when I run: node del/test-console_colours.js

{ a: 1, b: 2 }
{ a: 1, b: 2 }
TAP version 13
# Subtest: test-console-no-colours
ok 1 - test-console-no-colours
  ---
  duration_ms: 5.98973
  ...
# Subtest: test-console-with-colours
ok 2 - test-console-with-colours
  ---
  duration_ms: 0.511385
  ...
1..2
# tests 2
# pass 2
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 13.586095

What do you see instead?

TAP version 13
# Subtest: /_nm/prgs/node/acropolis-ch/del/test-console_colours.js
    # { a: 1, b: 2 }
not ok 1 - /_nm/prgs/node/acropolis-ch/del/test-console_colours.js
  ---
  duration_ms: 52.299434
  failureType: 'uncaughtException'
  error: 'Unexpected character: \x1B at line 1, column 0'
  code: 'ERR_TAP_LEXER_ERROR'
  stack: |-
    Socket.emit (node:events:512:28)
    Socket.read (node:net:742:39)
    async Promise.all (index 1)
  ...
1..1
# tests 1
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 66.556183

Additional information

  1. Looks like similar/related to this issue 45706
  2. same error happens even if I run console.dir outside subtest (it)
@MoLow MoLow added test_runner Issues and PRs related to the test runner subsystem. confirmed-bug Issues with confirmed bugs. labels Mar 5, 2023
@debadree25
Copy link
Member

It seems this could be solved by adding the ansi escape symbol \x1B to the #isEscapeSymbol(char) function? something like

diff --git a/lib/internal/test_runner/tap_lexer.js b/lib/internal/test_runner/tap_lexer.js
index a27e6ab35e..8af5453b28 100644
--- a/lib/internal/test_runner/tap_lexer.js
+++ b/lib/internal/test_runner/tap_lexer.js
@@ -525,7 +525,7 @@ class TapLexer {
   }
 
   #isEscapeSymbol(char) {
-    return char === '\\';
+    return char === '\\' || char === '\x1b';
   }
 
   #isYamlStartSymbol(char) {

@MoLow
Copy link
Member

MoLow commented Mar 12, 2023

@debadree25 do you want to open a PR?

@debadree25
Copy link
Member

Doing so!

debadree25 added a commit to debadree25/node that referenced this issue Mar 12, 2023
nodejs-github-bot pushed a commit that referenced this issue Mar 16, 2023
Fixes: #46959
PR-URL: #47050
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos pushed a commit that referenced this issue Mar 18, 2023
Fixes: #46959
PR-URL: #47050
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
danielleadams pushed a commit that referenced this issue Jul 6, 2023
Fixes: #46959
PR-URL: #47050
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants