-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
feat(testing): support for vscode-jest integration. #1118
Conversation
If you suggest different option names, e.g. --test-file & --test-dir, I might as well do that. |
With new options the launch.json config is this: |
Hi can we approach this in a different way? Can we keep the options we currently have but then have a way to pass additional options to jest? We are open to any new options you want but let's do them 1 at a time so we can consider each one. Something like |
Hi Jason, thanks for the suggestion. |
@FrozenPandaz Done. |
Is there a separate issue for adding other options? My company uses subversion instead of git which means watch does not work for us. I would still like to keep the session live which is why I would need watchAll. Was not sure if we should open a new issue for each option needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making the changes @Domratchev. This PR is looking much better.
@@ -4,11 +4,17 @@ jest.mock('jest'); | |||
const { runCLI } = require('jest'); | |||
import * as path from 'path'; | |||
|
|||
class TestJestBuilder extends JestBuilder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this so you can spy? Can you cast to any
instead please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
testNamePattern?: string; | ||
updateSnapshot?: boolean; | ||
useStderr?: boolean; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was initially wrong about the minimum scope of changes required for integration.
All the added properties are used by vscode-jest in different scenarios (some - in debug mode, some - in the background).
const project = this.getProjectForFile(filePath); | ||
|
||
if (project && project.root !== builderConfig.root) { | ||
return of({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary? and If the specified file is not in the project, should it be a failure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fist-file has to be tested in a context of its own project. This is the only way I could come up with to find out what project it is.
jestConfig: string; | ||
testDirectory?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vscode-jest passes in the file name only, without the full path.
To find out which file exactly that is, and to which project it belongs we need to know the directory.
@jasedwards That is unfortunate, can you please create a separate issue? |
@FrozenPandaz It appears after looking at last commit that watchAll will be available. can you confirm? if I am mistaken then I will create a separate issue |
@jasedwards It was my private initiative, hope @FrozenPandaz doesn't mind. |
Also it is very tempting to add passWithNoTests=true by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your persistence here as we work out the best solution. I am sorry it is taking so long.
Re: watchAll
I am completely open to adding new options which will improve the tool. However, please do not try to "sneak" changes in. I would have preferred it have it's own issue and it's own PR. It also shows up nicer in the Changelog so other users have a better idea of what changed.
|
||
if (filePath && !this._isInFolder(builderConfig.root, filePath)) { | ||
return of({ | ||
success: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an error to me. If we look at this out of the context of vscode-jest
then running the following as a command will pass without errors.
> ng test app1 --test-file apps/app2/src/app/app.component.spec.ts
Tests Passed?
For VSCode-Jest debugging, it's hard to get the project which is being tested, thus you are testing all of them with your config. Let's remove this check and consider the following solutions:
- Compute which project needs to be tested (i don't think VSCode debugging has support for this :()
- Pass the
testFile
to all projects like you are doing now but also passpassWithNoTests
so when it doesn't match any files, it will still pass 🤷♀️. This solves your use case semantically without causing a false positive for others. - Prompt the user for the Project via https://code.visualstudio.com/docs/editor/variables-reference#_input-variables
- Add configuration to https://github.com/jest-community/vscode-jest to adjust it's logic if the user is using
@nrwl/builders:jest
similar to how it has a specific treatment forcreate-react-app
projects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FrozenPandaz Jason, my intent for --test-file was rather specific to vscode-jest integration (or a similar scenario). I did not want to start testing other projects than the one holding the test-file. This way the terminal output is clear. I have also added --pass-with-no-tests to launch.json (see my edited comment above).
Using ng test with --test-file and non-matching project name is not a supported scenario and produces no results (as expected). The whole --test-directory affair is also very much VSCode specific, being the easiest way to provide full path to the file when needed and ignore it when --test-file is empty.
@FrozenPandaz I do not really like the removal of the project skipping logic. Even with --test-file specified and cwd set it still attempts to find the file in every single project in the workspace. And if the file name is not unique it would find it. I think that logic needs to be there. See my Terminal window output: Test Suites: 1 passed, 1 total |
@FrozenPandaz By the way, there is a bug in Jest. Its message about "No tests found, exiting with code 1 Created a new issue there: jestjs/jest#8187 |
Can you fix the commits? Maybe squash them all into a single commit 🤷♂️
Good Catch 👍
This is the nature of using |
458ae09
to
3cdb8e6
Compare
Done. Have a look, please. |
@Domratchev Can you fix the failing tests please? |
This dose not work on windows:
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Testing in VSCode is possible using vscode-jest extension with the following configuration in launch.json:
{
"name": "vscode-jest-tests",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/@angular/cli/bin/ng",
"args": ["test", "--run-in-band", "--no-code-coverage", "--path-to-file-to-test='${fileDirname}'", "--file-to-test"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"trace": "all"
}
Might as well run individual tests from the command line using
ng test
command with--file-to-test
and--path-to-file-to-test
.The
--path-to-file-to-test
might appear redundant, but it's really helpful with vscode-jest integration, as that extension passes in only file name, without the path.Fixes #1190