-
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): add ability to use nx libraries in jest global setup/teardown #9145
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/nrwl/nx-dev/3u6VBbYbvMJrtDHaAKzM8Bmb8EJW [Deployment for 9e3596d canceled] |
972d989
to
133f423
Compare
auto register tsconfig paths in jest preset to allow for global setup/teardown files to reference other libs as needed ISSUES CLOSED: #8709
133f423
to
9e3596d
Compare
// allow tspaths to work within jest global files like setup/teardown | ||
process.env.TS_NODE_PROJECT = | ||
process.env.TS_NODE_PROJECT || 'tsconfig.base.json'; | ||
require('tsconfig-paths/register'); |
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.
We have a util function for this now: https://github.com/nrwl/nx/blob/master/packages/nx/src/utils/register.ts
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.
running into some strange behaviors when this util with the cleanup logic.
since we have this util now. I think this might make more sense to do in userland before running the global scripts and cleaning up after the setup/teardown logic is run.
i.e.
//userland-setup.ts
import { registerTsProject } from 'nx/src/utils/register';
const cleanup = registerTsProject('.', 'tsconfig.base.json');
import {teardown} from '@global-fun/globals';
export default async function() {teardown();}
cleanup();
vs nx trying to run this logic. mainly the issues I'm seeing when trying to run this via the resolver/preset/config is it will not resolve the path alias but still pass the tests and then subsequent runs will pass. I think this has to do with the ts path registration not being cleaned up properly. but it can't be cleaned up until the setup/teardown has taken place. which can only be specified in userland setup/teardown files.
We could do this in the jest executor, but I'm hesitant because that will break editors running tests via jest
command and those manually running the jest
command.
This looks like I should just update Jest docs to show how to register tspaths for the global setup/teardown vs trying doing the path registration.
Closing in favor of explaining how to set up via jest docs in PR #9483 |
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. |
auto register tsconfig paths in jest resolver to allow for global setup/teardown files to reference other libs as needed
This removed 1 less configuration that developers need to do when using jest with nx.
Current Behavior
unable to use nx libraries within a global setup/teardown file for jest
Expected Behavior
I am able to use nx libraries within a global setup/teardown file provided to jest
Related Issue(s)
Fixes #8709