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

[Bug]: failureMessage is coloured when syntax errors #14998

Open
aecepogluARUP opened this issue Apr 2, 2024 · 4 comments
Open

[Bug]: failureMessage is coloured when syntax errors #14998

aecepogluARUP opened this issue Apr 2, 2024 · 4 comments

Comments

@aecepogluARUP
Copy link

Version

29.7.0

Steps to reproduce

  1. Create a simple test in a typescript file with a syntax error: test('sum', () => { expec(1+2).toEqual(3) }); $$
  2. jest --json or jest | cat

Expected behavior

I expect failureMessage or testExecError to not have colour codes

Actual behavior

failureMessage and testExecError has colour codes

Additional context

This isn't about writing to stdout, as these properties will have colours in them if you're writing custom reporters as well.

I haven't dug who introduces those codes, but --colors or FORCE_COLORS config does not impact them.

Environment

Need to install the following packages:
envinfo@7.11.1
Ok to proceed? (y) 
  System:
    OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
  Binaries:
    Node: 18.18.0 - ~/.config/nvm/18.18.0/bin/node
    npm: 9.8.1 - ~/.config/nvm/18.18.0/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
@mrazauskas
Copy link
Contributor

Did you try:

npx jest --json --no-color

or:

FORCE_COLOR=false npx jest --json

For me these work as expected, i.e. there no no ansi escape codes in the output. Although I don’t see failureMessage or testExecError in the output too. Might be there are issues with reproduction steps.

@aecepogluARUP
Copy link
Author

I see it regularly. My test files are in typescript and I use ts-jest

// hello.test.ts
test('sum', () => { expec(1+2).toEqual(3) }) $$
// jest.config.ts
import type {Config} from 'jest';
const config: Config = { preset: 'ts-jest' };
export default config;

node_modules/.bin/jest ./hello.test.ts --json

{"numFailedTestSuites":1,"numFailedTests":0,"numPassedTestSuites":0,"numPassedTests":0,"numPendingTestSuites":0,"numPendingTests":0,"numRuntimeErrorTestSuites":1,"numTodoTests":0,"numTotalTestSuites":1,"numTotalTests":0,"openHandles":[],"snapshot":{"added":0,"didUpdate":false,"failure":false,"filesAdded":0,"filesRemoved":0,"filesRemovedList":[],"filesUnmatched":0,"filesUpdated":0,"matched":0,"total":0,"unchecked":0,"uncheckedKeysByFile":[],"unmatched":0,"updated":0},"startTime":1712138134523,"success":false,"testResults":[{"assertionResults":[],"coverage":{},"endTime":1712138135196,"message":"  ● Test suite failed to run\n\n    \u001b[96mhello.test.ts\u001b[0m:\u001b[93m1\u001b[0m:\u001b[93m21\u001b[0m - \u001b[91merror\u001b[0m\u001b[90m TS2552: \u001b[0mCannot find name 'expec'. Did you mean 'expect'?\n\n    \u001b[7m1\u001b[0m test('sum', () => { expec(1+2).toEqual(3) })\n    \u001b[7m \u001b[0m \u001b[91m                    ~~~~~\u001b[0m\n\n      \u001b[96mnode_modules/@types/jest/index.d.ts\u001b[0m:\u001b[93m14\u001b[0m:\u001b[93m15\u001b[0m\n        \u001b[7m14\u001b[0m declare const expect: jest.Expect;\n        \u001b[7m  \u001b[0m \u001b[96m              ~~~~~~\u001b[0m\n        'expect' is declared here.\n    \u001b[96mhello.test.ts\u001b[0m:\u001b[93m2\u001b[0m:\u001b[93m1\u001b[0m - \u001b[91merror\u001b[0m\u001b[90m TS2304: \u001b[0mCannot find name '$$'.\n\n    \u001b[7m2\u001b[0m $$\n    \u001b[7m \u001b[0m \u001b[91m~~\u001b[0m\n","name":"/home/path/to/hello.test.ts","startTime":1712138135196,"status":"failed","summary":""}],"wasInterrupted":false}

@mrazauskas
Copy link
Contributor

ts-jest is managed in its own repo. Any issues with it must be reported there.

As already mentioned, FORCE_COLOR=false does what you want.

Copy link

github-actions bot commented May 3, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants