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

vanillia nx angular project does not run tests in VSCode #3507

Closed
d4046949 opened this issue Aug 12, 2020 · 7 comments · Fixed by #3766
Closed

vanillia nx angular project does not run tests in VSCode #3507

d4046949 opened this issue Aug 12, 2020 · 7 comments · Fixed by #3766
Assignees
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: question / discussion

Comments

@d4046949
Copy link

d4046949 commented Aug 12, 2020

Current Behavior

I've created a standard nx project and then installed Jest extensions for visual studio code. I've then clicked Debug on one of the tests that were created as part of the project. These fail to run.

entering 'nx test' at the command line shows that the test pass.

Expected Behavior

I want to be able to debug a test

Steps to Reproduce

create a new project using the NX CLI
install the Jest extension for VSCode
Attempt to debug the test.
Note that the component creation fails

Additional information

I've tried following various posts found on the web. Even changed the launch.json to look like this

    {
        "name": "vscode-jest-tests",
        "type": "node",
        "request": "launch",
        "program": "${workspaceFolder}/node_modules/@angular/cli/bin/ng",
        "args": ["test", "--pass-with-no-tests", "--run-in-band", "--no-code-coverage", "--test-file"],
        "cwd": "${fileDirname}",
        "console": "integratedTerminal",
        "internalConsoleOptions": "neverOpen",
        "trace": "all"
        }
@vsavkin vsavkin added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Aug 13, 2020
@vsavkin
Copy link
Member

vsavkin commented Aug 13, 2020

@Cammisuli can you reply?

@Lonli-Lokli
Copy link

You can try this launch.json, just change path to appropriate config files
{
"type": "node",
"request": "launch",
"name": "[E2E] Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"--runTestsByPath",
"${relativeFile}",
"--c",
"${workspaceFolder}/apps/cv-e2e/jest.config.e2e.js",
"--runInBand",
"--no-cache"
],
"console": "internalConsole",
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/.bin/jest",
}
}

@Cammisuli
Copy link
Member

By default, Jest extensions run Jest at the root of the workspace. They don't know about the multiple Jest configs in each project, unless you specify it in the settings for the extension. And even then, you can only have one config at a time.

I'm planning on fixing this so that if you run Jest in the root, it'll know about all the projects. But that's currently a WIP.

In the meantime since you're using VScode, you can debug tests easily by just running the nx test <project> command in a JavaScript Debug Terminal:
image

Then add debug points as you normally would.

@Lonli-Lokli
Copy link

@FrozenPandaz is there any possibility now to have common code coverage calculated?
It's pretty useful to have single code coverage for the monorepo, like a sum of all project and lib reports.

@Cammisuli
Copy link
Member

@Lonli-Lokli You should be able to just run jest in the root of the repo and Jest will run all projects. Hopefully that calculates all coverage reports together.

@Lonli-Lokli
Copy link

@Cammisuli It cannot find references to customized via paths libraries, I believe due to this in root jest.config.js
resolver: '@nrwl/jest/plugins/resolver',

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: question / discussion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants