Vscode-jest: ansi code escape from jest output

Created on 6 Mar 2018  ·  6Comments  ·  Source: jest-community/vscode-jest

Using standard vue-cli init webpack

upon test errors, I got problems and inline error messages corrupted with ansi codes:

image

I can hack them out using this in workspace config:

"jest.pathToJest": "node_modules/.bin/jest --no-color",

but in that case the 'debug' button will fail saying it is not able to find jest.js:
image

bug needs information

Most helpful comment

Curious if this was published? I'm still seeing it with vscode-jest 2.7.2.

image

All 6 comments

That's a bit strange. Would you have time to debug the extension and see where we've got the bonus ANSI? The output is coming from Jest as JSON using the --json argument. If you run Jest from the command line with that, are the ANSI codes in there as well?

PR #271 is in the works and should help with the debugger finding jest.js.

@seanpoulter
Sorry for delay.
I ran jest with --json and it includes ansi codes

I'm seeing this as well with the latest plugin on VS Code 1.21.0. Running manually with --json includes ANSI escape codes in the output.

screenshot 2018-03-20 11 43 25

JSON output:

{
    "numFailedTestSuites": 1,
    "numFailedTests": 1,
    "numPassedTestSuites": 0,
    "numPassedTests": 1,
    "numPendingTestSuites": 0,
    "numPendingTests": 0,
    "numRuntimeErrorTestSuites": 0,
    "numTotalTestSuites": 1,
    "numTotalTests": 2,
    "snapshot": {
        "added": 0,
        "didUpdate": false,
        "failure": false,
        "filesAdded": 0,
        "filesRemoved": 0,
        "filesUnmatched": 0,
        "filesUpdated": 0,
        "matched": 0,
        "total": 0,
        "unchecked": 0,
        "uncheckedKeys": [],
        "unmatched": 0,
        "updated": 0
    },
    "startTime": 1521571392982,
    "success": false,
    "testResults": [{
        "assertionResults": [{
            "ancestorTitles": [],
            "failureMessages": [],
            "fullName": "adds 1 + 2 to equal 3",
            "location": null,
            "status": "passed",
            "title": "adds 1 + 2 to equal 3"
        }, {
            "ancestorTitles": [],
            "failureMessages": ["Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).toBe(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected value to be:\n  \u001b[32m6\u001b[39m\nReceived:\n  \u001b[31m3\u001b[39m\n    at Object.<anonymous>.test (/private/tmp/test/sum.test.js:8:21)\n    at Object.asyncFn (/private/tmp/test/node_modules/jest-jasmine2/build/jasmine_async.js:82:37)\n    at resolve (/private/tmp/test/node_modules/jest-jasmine2/build/queue_runner.js:52:12)\n    at new Promise (<anonymous>)\n    at mapper (/private/tmp/test/node_modules/jest-jasmine2/build/queue_runner.js:39:19)\n    at promise.then (/private/tmp/test/node_modules/jest-jasmine2/build/queue_runner.js:73:82)\n    at <anonymous>\n    at process._tickCallback (internal/process/next_tick.js:188:7)"],
            "fullName": "should fail",
            "location": null,
            "status": "failed",
            "title": "should fail"
        }],
        "endTime": 1521571393850,
        "message": "\u001b[1m\u001b[31m  \u001b[1m● \u001b[1mshould fail\u001b[39m\u001b[22m\n\n    \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).toBe(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n    \n    Expected value to be:\n      \u001b[32m6\u001b[39m\n    Received:\n      \u001b[31m3\u001b[39m\n\u001b[2m\u001b[22m\n\u001b[2m    \u001b[0m \u001b[90m  6 | \u001b[39m\u001b[0m\u001b[22m\n\u001b[2m    \u001b[0m \u001b[90m  7 | \u001b[39mtest(\u001b[32m'should fail'\u001b[39m\u001b[33m,\u001b[39m () \u001b[33m=>\u001b[39m {\u001b[0m\u001b[22m\n\u001b[2m    \u001b[0m\u001b[31m\u001b[1m>\u001b[2m\u001b[39m\u001b[90m  8| \u001b[39m  expect(sum(\u001b[35m1\u001b[39m\u001b[33m,\u001b[39m \u001b[35m2\u001b[39m))\u001b[33m.\u001b[39mtoBe(\u001b[35m6\u001b[39m)\u001b[33m;\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m    \u001b[0m \u001b[90m  9 | \u001b[39m})\u001b[33m;\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m    \u001b[0m \u001b[90m 10 | \u001b[39m\u001b[0m\u001b[22m\n\u001b[2m      \u001b[22m\n\u001b[2m      \u001b[2mat Object.<anonymous>.test (\u001b[2m\u001b[0m\u001b[36msum.test.js\u001b[39m\u001b[0m\u001b[2m:8:21)\u001b[2m\u001b[22m\n",
        "name": "/private/tmp/test/sum.test.js",
        "startTime": 1521571393636,
        "status": "failed",
        "summary": ""
    }],
    "wasInterrupted": false
}

Same issue, --no-color does fix this. If that is a workaround for people who aren't using debug, perhaps it's worth documenting?

Windows 10
VSCode
Version 1.21.1
Commit 79b44aa704ce542d8ca4a3cc44cfca566e7720f1
Date 2018-03-14T14:46:47.128Z
Shell 1.7.9
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64

npm -v 5.6.0
node -v v9.6.1

It seems like this has been happening since Jest 22.0 and on. I'll add an option to jest-editor-support so we can pass the --no-color option to the test runner.

Curious if this was published? I'm still seeing it with vscode-jest 2.7.2.

image

Was this page helpful?
0 / 5 - 0 ratings