Skip to content
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

Mono repo e2e testing issue #1257

Closed
SergiiVlasiuk opened this issue Jul 29, 2021 · 1 comment
Closed

Mono repo e2e testing issue #1257

SergiiVlasiuk opened this issue Jul 29, 2021 · 1 comment

Comments

@SergiiVlasiuk
Copy link

I've got some topics where this question rised but no correct answer or fix.

If I try e2e tests in monorepo application they are failed because not resolved imports in main application.

I'm submitting a...


[ ] Regression 
[x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

  • Use project example by link
  • execute build npm i (it should be successful)
  • start e2e tests npm run test:e2e
npm run test:e2e

> 04-monorepo-apps-libs@0.0.1 test:e2e
> jest --config ./apps/04-monorepo-apps-libs/test/jest-e2e.json

 FAIL  apps/04-monorepo-apps-libs/test/app.e2e-spec.ts
  ● Test suite failed to run

    Cannot find module '@app/database' from 'app.module.ts'

      2 | import { AppController } from './app.controller';
      3 | import { AppService } from './app.service';
    > 4 | import { DatabaseModule } from '@app/database';
        | ^
      5 |
      6 | @Module({
      7 |   imports: [DatabaseModule],

      at Resolver.resolveModule (../../../node_modules/jest-resolve/build/index.js:259:17)
      at Object.<anonymous> (../src/app.module.ts:4:1)

Test Suites: 1 failed, 1 total

Expected behavior

My expectation is that test should not be failed because unresolved module dependency

import { DatabaseModule } from '@app/database';

because it was resolved at build time.

Minimal reproduction of the problem with instructions

  • Use project example by link
    • it was generated by nest-cli
    • i faced with similar situation on different OS (mac windows10, ubuntu18) trying migrate my application to monorepo configuration
    • the project example is not mine but it was generated using nest-cli and perfectly demonstrates my issues also;
  • execute build npm i (it should be successful)
  • start e2e tests npm run test:e2e
    P.S.
    I tried reconfigure test/jest-e2e.json to fix the issue but unsuccessfully.

What is the motivation / use case for changing the behavior?

nest g lib SHARED_LIB

or

nest g app OTHER_APP_NAME

Environment

nest info

 _   _             _      ___  _____  _____  _     _____
| \ | |           | |    |_  |/  ___|/  __ \| |   |_   _|
|  \| |  ___  ___ | |_     | |\ `--. | /  \/| |     | |
| . ` | / _ \/ __|| __|    | | `--. \| |    | |     | |
| |\  ||  __/\__ \| |_ /\__/ //\__/ /| \__/\| |_____| |_
\_| \_/ \___||___/ \__|\____/ \____/  \____/\_____/\___/


[System Information]
OS Version     : macOS Catalina
NodeJS Version : v15.8.0
NPM Version    : 7.5.1

[Nest CLI]
Nest CLI Version : 6.14.0

[Nest Platform Information]
platform-express version : 6.7.2
common version           : 6.7.2
core version             : 6.7.2
@kamilmysliwiec
Copy link
Member

kamilmysliwiec commented Jul 29, 2021

You have to manually update your Jest configuration (for e2e tests) by updating the moduleNameMapper configuration. This may change in the future if we decide to merge this PR nestjs/schematics#532

Please, use our Discord channel (support) for further questions. We are using GitHub to track bugs, feature requests, and potential improvements.

@nestjs nestjs locked and limited conversation to collaborators Jul 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants