nx
nx copied to clipboard
Jest resolves the whole tree structure of all exported elements in a index.ts file
Current Behavior
We have created a local module in nx libs folder, we import two elements from this lib in one of our test file. When we run the test, Jest is resolving the whole tree structure of all exported elements in the lib index.ts file.
Expected Behavior
Jest should not resolve the whole tree structure of all exported elements, but only resolve it for elements imported in the test file.
Steps to Reproduce
Here is a github repository which reproduces the bug if you run npm test command
Failure Logs
FAIL my-app apps/my-app/src/app/tests/test-app.spec.ts
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'child')
8 | imports: [
9 | TestModule.forRoot(
> 10 | EnvServiceProvider.useFactory().parent.child
| ^
11 | ? {
12 | id: 'test',
13 | }
at Object.<anonymous> (../../libs/features/src/app/shared/auth/auth.module.ts:10:45)
at Object.<anonymous> (../../libs/features/src/app/core/core.module.ts:4:1)
at Object.<anonymous> (../../libs/features/src/app/app.module.ts:6:1)
at Object.<anonymous> (../../libs/features/src/index.ts:6:1)
at Object.<anonymous> (src/app/tests/test-app.spec.ts:2:1)
Error comes from the metadata of an ngModule imported by an exported module in our lib.
Environment
Node : 16.15.0
OS : linux x64
yarn : 1.22.19
nx : 14.1.7
@nrwl/angular : 14.1.7
@nrwl/cypress : 14.1.7
@nrwl/detox : Not Found
@nrwl/devkit : 14.1.7
@nrwl/eslint-plugin-nx : 14.1.7
@nrwl/express : Not Found
@nrwl/jest : 14.1.7
@nrwl/js : Not Found
@nrwl/linter : 14.1.7
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/nx-cloud : Not Found
@nrwl/nx-plugin : Not Found
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : 14.1.7
@nrwl/web : Not Found
@nrwl/workspace : 14.1.7
typescript : 4.6.4
rxjs : 7.5.5
---------------------------------------
Community plugins: