-
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
Workspace configured for Jest conflicts with IDE settings #747
Comments
Hi @evtk I am using VS Code and the extension Here is what I did:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc/global-custom-jest-integration",
"module": "commonjs",
"types": ["jest", "node"]
},
"files": ["./test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
globals: {
'ts-jest': {
tsConfigFile: 'tsconfig.spec.json'
},
__TRANSFORM_HTML__: true
} Doing this I am able to run Jest globally for the whole workspace + I am able to run Maybe customizing the How exactly does your IDE conflict with your Jest setup? Do you also have a custom global Jest integration? I don't think that implementing a naming convention is a good idea, the IDE and the generated setup should match by default in my opinion ... |
Hi @skydever, Thanks for your very detailed post with jest setup. I have followed your setup, but I get stuck on the fact that I'm using a modulename mapper, which contains a path to a barrel. It seems like the modulenamemapper's path is always interpreted against the current working folder of the test. Meaning it will never be the same. The rootDir is constant changing (it is the working folder of the test), but if I remove the rootDir, the path cannot be found (since it is relative to the working folder).
yagh :) anyways, bottomline is that in order to use jest through your IDE and through the CLI, you have to do a lot of configuration. It just doesn't work out of the box. This is also the case for your custom setup. And in my opinion that isn't the right solution. |
Hi @evtk I am new to Jest but it happened to be that I configured my nx workspace before the custom builder was done, based on #623, if you haven't seen the issue before. After I got that running the migration to the builder setup was very smooth, and not having a lib/app specific Maybe adding an option like About the And about IDE, maybe the Jest plugin should also be able to handle the lib specific setups too? What are you using? Using the nearest |
@FrozenPandaz Do you have any feedback to add to this approach? |
thx for this 👍 I needed to set the path to jest set in my "Workspace Settings" because I am not opening vscode with the nx workspace as root folder (in such a case the extension is requiring to set the paths manually), and I also have set the path to config pointing to my modified global I did not think about the possibility to set Testing my-lib
This command can only be run inside of a CLI project.
(node:9952) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'd:\some-path-where-the-nx-workspace-is-a-subfolder\dist\.nx-results'
at Object.fs.openSync (fs.js:646:18)
at Object.fs.writeFileSync (fs.js:1299:33)
at writeToFile (d:\some-path-where-the-nx-workspace-is-a-subfolder\other-directory\my-nx-workspace\node_modules\@nrwl\schematics\src\utils\fileutils.js:7:8)
at Object.writeJsonFile (d:\some-path-where-the-nx-workspace-is-a-subfolder\other-directory\my-nx-workspace\\node_modules\@nrwl\schematics\src\utils\fileutils.js:61:5)
at WorkspaceResults.saveResults (d:\some-path-where-the-nx-workspace-is-a-subfolder\other-directory\my-nx-workspace\node_modules\@nrwl\schematics\src\command-line\workspace-results.js:64:25)
at d:\some-path-where-the-nx-workspace-is-a-subfolder\other-directory\my-nx-workspace\node_modules\@nrwl\schematics\src\command-line\affected.js:274:38
at step (d:\some-path-where-the-nx-workspace-is-a-subfolder\other-directory\my-nx-workspace\node_modules\@nrwl\schematics\src\command-line\affected.js:40:23)
at Object.next (d:\some-path-where-the-nx-workspace-is-a-subfolder\other-directory\my-nx-workspace\node_modules\@nrwl\schematics\src\command-line\affected.js:21:53)
at d:\some-path-where-the-nx-workspace-is-a-subfolder\other-directory\my-nx-workspace\node_modules\@nrwl\schematics\src\command-line\affected.js:15:71
at new Promise (<anonymous>)
(node:9952) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:9952) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. |
Hi @skydever I tried to run the tests using the resolver instead of the modulename mapper. But that didn't work. I guess due to the fact @FrozenPandaz has addressed: the jest.config.js is relying on the builder. Also: configuring workspace settings to point to the affected:test command also feels a bit uncomfortable. We should not have to set these kind of options, to have the IDE to succesfully run jest. For me the scenario in which I seperate jest-config for IDE from jest-config for NX, still works best. |
Hi @evtk Are you sure you added this to the global globals: {
'ts-jest': {
tsConfigFile: 'tsconfig.spec.json'
},
__TRANSFORM_HTML__: true
} ... the solution should basically work, with just little adoptions to the original jest setup without relying on the builder (most of my changes where because of the global |
@FrozenPandaz about the size of a project that has a global jest solution - I totally agree. what my current solution does concerning ide is executing all tests initially, then after a change only affected ones will be executed. this will get much slower over time, fast. I dont know how the jest |
it has been a while, but I have taken the effort again to stay as close as possible to the out of the box jest configuration from NX. I finally managed it, thanks to the suggestions made by @skydever. On top of the default NX jest configuration (ng g jest + create apps/libs with --unit-test-runner jest), I have added in the root the test-setup.ts file and tsconfig.spec.json file as suggested here:
and I have adjusted the default jest.config.ts file by adding this part:
this scenario works for me. I can now run all tests with affected:test command and by running them manually using the vs code jest plugin by Orta. I do not have any issues anymore with the module mapping. I have no clue why, but hey it works :) For anyone, wondering, this is how my vs code launch settings:
|
I've followed @evtk's advice, and my error disappeared but was replaced by other errors. This is for a standard setup, just by following the docs. Given that many (/most /majority ?) of node/angular devs are using vscode, surely this problem should be addressed, or at the very least, the docs should explain a workaround. As they currently stand, the official docs and cli generators don't work for setting up a project and using it with vscode. My issue shows that. |
Folks. Is the issue still present when using the latest version of Nx? |
I believe this is the same thing that's experienced with webstorm, and if that is infact the case.... yes the problem still exists. I just created a new workspace with 9.x, and getting loads of errors with not being able to find zone.js, after fiddling with other settings, I've gotten it to the point where it gives an error about not being able to load html for the component |
In VSCode I see the "problem"
|
Hi, sorry about this. This was mislabeled as stale. We are testing ways to mark not reproducible issues as stale so that we can focus on actionable items but our initial experiment was too broad and unintentionally labeled this issue as stale. |
Hey folks, we recently released 10.0.0-beta.2 which contains a migration for Jest configs (basically puts all configurations in the jest.config.js, and leaves the cli options for the builder to pass along). Because of this, we can now run Jest directly in the terminal (i.e Now, from what I saw from some VSCode extensions is that they don't play nicely with a monorepo style environment. They essentially just look at the root So I'm asking folks here, how do you expect this to work?
Personally, I'd rather have an extension that just "works". Without having to do workspaces. |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
@FrozenPandaz wow, many thanks for this latest fix for jest workspace. This seems to fix all my jest related issues! Awesome works! |
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. |
Running the 'ng g jest' command will generate a jest.config.js file in the root of the project. This will override the settings for jest used by the IDE (tested so far with VS Code & WebStorm). I have currently configured jest settings in the package.json, but this of course would also be the case for any already existing config 'jest.config.js' in the root.
To fix this, I have implemented the jest builder, by using a naming convention for all jest config for NX to have a prefix of 'nx-'. In this way IDE's don't automatically pick-up the jest config generated by NX.
Can such a convention be implemented?
The text was updated successfully, but these errors were encountered: