-
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
Setup build
as a target dependency for test
and use compiled assets in tests
#6253
Comments
I would also be more than happy to help work on this if it is something Nrwl is interested in including. |
Here is a PoC: https://github.com/yharaskrik/jest-nx-build-dependencies Issues so far:
Solutions: Either have ng-packagr:lite emit the commonjs alongside the normal There is a performance trade off with this because we either need to compile the code to
Solutions: Either install an AST tranversal lib and use that to see if there is already a moduleNameMapper property and if so merge it or add one beside a key we always expect to be there ( #2 is not that big of a deal, #1 is where the decision will come in, I would think it would be more optimal to pre-process the lib and compile commonjs assets as well since then those can be reused between all tests, rather than jest-preset-angular (or just ts-jest in the case of non angular projects) having to compile the Would love some feedback on this. |
So in regards to # I will take a look at Nrwl's implementation of |
I now have a branch off of nx master that can conditionally compile dependencies to
|
Confirmed we can run jest on a project using a config in a tmp directory. |
This PR has the functionality for the jest executor to determine if all of the deps have been built and if so create all of the |
after converting our workspace to nx, our unit tests are running about 4 times as slow as before |
@gms1 really that is all it took to get it to work? So theoretically if I generate a fresh workspace and make those changes then tests will run with compile artifacts? |
after what I have now tested, yes |
@gms1 Do you happen to have a sample repo that show this? I am trying to get it working in a fresh repository but it cannot match the paths. Wondering if you have a minimal repo? If I copy my built assets into the node_modules folder it does work as you describe, just not in dist/libs. It does work if we put them in the |
unfortunately, I cannot share the repo that I am currently working on;; hm, in my case it is even in "dist/projects" folder; |
Amazing! I would love to see a minimal repo so I could recreate it and maybe expand on it in this PR! |
Ok it looks like I got it working, I do need to copy my lib artifacts into a separate folder though because they are expecting the repos path prefix |
aah, you are right in my dist/projects folder I have also the @scope folder |
@gms1 I cannot seem to get it to work reliability, make sure while you are testing you are clearing the jest cache prior to running the tests |
my problem was rather that I couldn't get the performance improvement I was expecting (it's now around 20% so not bad either), so I'm sure I cleared both the nx and jest caches. |
Ok I was able to get it working the solution is somewhere in between my implementation from months ago and you pointing me in the right direction. I will try and do up a PR to show it. |
There we go! PR open! |
closing as found in the PR that this doesn't provide as much benefit as expected, unfortunately. |
Agreed! (I am having deja vu with this conversation though, thought we already closed it haha) |
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. |
Description
With the new version of Nx we can now define
build
fordependencies
as a target that needs to be run prior to the originalbuild
command can be run using thetargetDependencies
innx.json
. It would be awesome to be able to use the compiled assets when running jests tests, rather than using jest-preset-angular with the*.ts
transformer on a per spec file.Essentially we would be able to put this in our
nx.json
and then when a spec file imports from TS such as
@scope/lib1
instead of pointing that alias to/libs/lib1/src/index.ts
we would point it to/dist/libs/lib1
, this is similar to how the Nrwl builder will work--with-deps
Motivation
Should greatly speed up test runs if TypeScript files do not need to be compiled on the fly and takes advantage of the buildable deps Nx already provides.
Suggested Implementation
@nrwl/jest
would need to look at thenx.json
in the same way that the builders do and determine if there aretargetDependencies
and then when the tests are run, thejest.config.js
that is used will need to be modified such that we can override the TS paths. Not exactly how this should work since I know jest-preset-angular is used to do the transforming with ts-jest underneath, maybe we can pass in a temporary tsconfig file to those libraries so that we can merge the roottsconfig.base.json
with the paths that were build.ts-jest
will look at themoduleNameMapper
(https://kulshekhar.github.io/ts-jest/docs/getting-started/paths-mapping/) for path matching,jest
supports passing inmoduleNameMapper
(althought the typings expect astring
in@types/jest
forrunCLI
so not sure how that would work) which should allow us to override where sources are mapped too (I am assuming that those would override paths in the tsconfig but I am not 100% sure on that)Alternate Implementations
The text was updated successfully, but these errors were encountered: