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

fix: jest.config.ut.js not processing array in tsconfig paths correctly #2605

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

divdavem
Copy link
Member

Proposed change

This PR fixes an issue when running tests if tsconfig.json contains more than one item in one of the paths arrays (which is the case when using otter generator for a library).

Related issue

To reproduce the issue (I did it with Otter 11.5.3):

npm create @o3r myproject
# (press enter each time a question is asked)
cd myproject
npm exec ng g library
#? Name of the package of the new module? mylib
#? Which preset to use to start your application? BASIC - Minimum plugin list to install for a basic Otter application. (details on https://www.npmjs.com/package/@o3r/core#preset-basic)
npm exec ng g application
#? Name of the new application? myapp
#? Which preset to use to start your application? BASIC - Minimum plugin list to install for a basic Otter application. (details on https://www.npmjs.com/package/@o3r/core#preset-basic)
# You are currently using jasmine. Do you want to setup Jest test framework? You will have to remove jasmine yourself. yes
# Do you want to setup Playwright test framework for E2E? yes

Then add a reference to MyLibComponent from app.component.ts:

import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { MylibComponent } from 'mylib'; // add this line

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [RouterOutlet, MylibComponent], // add MylibComponent here
  templateUrl: './app.component.html',
  styleUrl: './app.component.scss'
})
export class AppComponent {
  title = 'myapp';
}

Then run tests:

npm test

Tests fail with the following error:


> [email protected] test
> lerna run test

(node:58794) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
lerna notice cli v8.1.9

> myapp:test


> [email protected] test
> jest

 FAIL   myapp  src/app/app.component.spec.ts
  ● Test suite failed to run

    Configuration error:
    
    Could not locate module mylib mapped as:
    /home/user/myproject/libs/mylib/dist,libs/mylib/src/public-api.
    
    Please check your configuration for these entries:
    {
      "moduleNameMapper": {
        "/^mylib$/": "/home/user/myproject/libs/mylib/dist,libs/mylib/src/public-api"
      },
      "resolver": undefined
    }

      1 | import { Component } from '@angular/core';
      2 | import { RouterOutlet } from '@angular/router';
    > 3 | import { MylibComponent } from 'mylib';
        | ^
      4 |
      5 | @Component({
      6 |   selector: 'app-root',

      at createNoMappedModuleFoundError (../../node_modules/jest-resolve/build/resolver.js:759:17)
      at Object.<anonymous> (src/app/app.component.ts:3:1)
      at Object.<anonymous> (src/app/app.component.spec.ts:2:1)

(node:59208) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        3.072 s
Ran all test suites.
npm error Lifecycle script `test` failed with error:
npm error code 1
npm error path /home/user/myproject/apps/myapp
npm error workspace [email protected]
npm error location /home/user/myproject/apps/myapp
npm error command failed
npm error command sh -c jest

——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 Lerna (powered by Nx)   Ran target test for project myapp (4s)

   ✖  1/1 failed
   ✔  0/1 succeeded [0 read from cache]

Note that tsconfig.json contains:

{
  // ...
  "compilerOptions": {
    // ...
    "paths": {
      "mylib": [
        "libs/mylib/dist",
        "libs/mylib/src/public-api"
      ]
    },
    // ...
  }
  //...
}

@divdavem divdavem requested a review from a team as a code owner December 17, 2024 10:00
@kpanot kpanot enabled auto-merge December 17, 2024 10:11
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.27%. Comparing base (2125b51) to head (a72ba7a).
Report is 2 commits behind head on main.

Additional details and impacted files

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@divdavem
Copy link
Member Author

@kpanot @matthieu-crouzet Thank you for reviewing and merging my PR !

@kpanot kpanot added this pull request to the merge queue Dec 17, 2024
Merged via the queue into AmadeusITGroup:main with commit 6a9e0da Dec 17, 2024
37 checks passed
@divdavem divdavem deleted the fixJestConfigPaths branch December 18, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants