jest-community / vscode-jest

The optimal flow for Jest based testing in VS Code
MIT License
2.84k stars 293 forks source link

Results are not shown in vscode if jest config includes jest-runner-eslint #581

Open KnisterPeter opened 4 years ago

KnisterPeter commented 4 years ago

Environment

  1. node -v: v13.12.0

  2. npm -v: 6.14.4

  3. npm ls jest or npm ls react-scripts (if you haven’t ejected): jest@24.9.0

  4. your vscode-jest settings if customized:

    • jest.pathToJest? [fill]
    • jest.pathToConfig? jest.config.js
    • anything else that you think might be relevant? I use jest with multi-projects. Our project is yarn monorepo and we have defined each package in the monorepo as separate jest project.
  5. Operating system: Linux and MacOS

Prerequisite

Steps to Reproduce

https://github.com/KnisterPeter/vscode-jest-projects-problem

Relevant Debug Info

/var/lib/snapd/snap/code/31/usr/share/code/resources/app/out/vs/workbench/workbench.desktop.main.js:3983 TypeError: Cannot read property 'replace' of null
    at Object.t.cleanAnsi (/home/markusw/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:44)
    at /home/markusw/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:129
    at Array.map (<anonymous>)
    at /home/markusw/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:129
    at Array.map (<anonymous>)
    at /home/markusw/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:129
    at Array.map (<anonymous>)
    at Object.t.resultsWithoutAnsiEscapeSequence (/home/markusw/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:129)
    at t.JestExt.updateWithData (/home/markusw/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:385)
    at t.<anonymous> (/home/markusw/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:385)
    at t.emit (/var/lib/snapd/snap/code/31/usr/share/code/resources/app/out/vs/code/electron-browser/workbench/events.js:203)
    at /home/markusw/.vscode/extensions/orta.vscode-jest-3.2.0/out/extension.js:129
    at FSReqCallback.readFileAfterClose [as oncomplete] (/var/lib/snapd/snap/code/31/usr/share/code/resources/app/out/vs/code/electron-browser/workbench/internal/fs/read_file_context.js:61)

Expected Behavior

Have the tests run (works) and indicated in vscode (fails).

Actual Behavior

The test results could not be mapped back into vscode.


The fastest (and the most fun) way to resolve the issue is to submit a pull-request yourself. If you are interested, feel free to check out the contribution guide, we look forward to seeing your PR...

connectdotz commented 4 years ago

looks like it is a bug, maybe in jest, the failureMessages is supposed to be a [string] (see here), but the actual output contains

      "assertionResults": [
        {
          "ancestorTitles": [],
          "failureMessages": [
            null
          ],
          "status": "passed",
          "title": "ESLint"
        }
      ],

you might want to file an issue at jest to address the root cause. Mean while I think we can make this extension a bit more fault tolerant...

connectdotz commented 4 years ago

hmmm... another problem when a file being reported multiple times due to jest's projects config, the result is undetermined, often the last reported result overrides the earlier one, in your example the lint result overrides the actual jest test result.

It is not clear which one we should be reporting... try to avoid parsing the test result to "guess" as it is not reliable and certainly won't cover all runners out there... maybe a more robust way is to let the user tell us? The displayName looked promising, but that info is not currently included in the jest json output file...