jest resolver resolves to wrong file #15312
Labels
outdated
scope: testing tools
Issues related to Cypress / Jest / Playwright / Vitest support in Nx
type: bug
Current Behavior
When resolving path './foo.js', if './foo.js' does not exist but '../foo.js' exists, the resolver will incorrectly resolve to '../foo.js'.
Expected Behavior
resolver should be unable to resolve the file
GitHub Repo
https://github.com/nrwl/nx
Steps to Reproduce
npx create-nx-workspace@latest
to create an angular standalone app calledfoo
. Accept all defaults.src/app/app.component.spec.ts
, add a mock as followsjest.mock('./main', () => undefined);
npx nx test foo
Expected result: test suite should fail to run, with an error
Cannot find module './main' from 'src/app/app.component.spec.ts'
Actual result: The tests will pass. Tracing the code, the file found by '@nrwl/jest/plugins/resolver' is the existing file
src/main.ts
, i.e.../main.ts
.Nx Report
Failure Logs
No response
Additional Information
This line in the jest resolver seems suspicious to me
options.basedir
has the valuesrc/app
which is a directory, but the receiving parameter ints.resolveModuleName
is namedcontainingFile
. Ifsrc/app
is considered as a file, thensrc/main.ts
would be a good resolution for./main.ts
.Changing this line to
gives the expected behaviour, `./main' cannot be resolved anymore.
The text was updated successfully, but these errors were encountered: