angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.79k stars 11.98k forks source link

setup jest error #25188

Open Prabin1111 opened 1 year ago

Prabin1111 commented 1 year ago

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

Yes

Description

i have just update angular 15 to 16 and install "jest": "^29.5.0" and "@types/jest": "^29.5.1",

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

✘ [ERROR] Two output files share the same path but have different contents: layout.component.spec.mjs

✘ [ERROR] Two output files share the same path but have different contents: home.component.spec.mjs.map

✘ [ERROR] Two output files share the same path but have different contents: home.component.spec.mjs

● Validation Error:

  Module <rootDir>/jest-global.mjs in the setupFilesAfterEnv option was not found.
         <rootDir> is: /home/prabin/Desktop/technoFex/durapp/dist/test-out

  Configuration Documentation:
  https://jestjs.io/docs/configuration

Please provide the environment you discovered this bug in (run ng version)

"dependencies": {
    "@angular/animations": "^16.0.1",
    "@angular/cdk": "^16.0.0",
    "@angular/common": "^16.0.1",
    "@angular/compiler": "^16.0.1",
    "@angular/core": "^16.0.1",
    "@angular/forms": "^16.0.1",
    "@angular/material": "^16.0.0",
    "@angular/platform-browser": "^16.0.1",
    "@angular/platform-browser-dynamic": "^16.0.1",
    "@angular/router": "^16.0.1",
    "cropperjs": "^1.5.13",
    "eslint-plugin-jsdoc": "^44.2.2",
    "flowbite": "^1.6.5",
    "ng-tw": "^0.0.16",
    "ngx-owl-carousel-o": "^15.0.1",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "^0.13.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^16.0.1",
    "@angular-eslint/builder": "16.0.1",
    "@angular-eslint/eslint-plugin": "16.0.1",
    "@angular-eslint/eslint-plugin-template": "16.0.1",
    "@angular-eslint/schematics": "16.0.1",
    "@angular-eslint/template-parser": "16.0.1",
    "@angular/cli": "~16.0.1",
    "@angular/compiler-cli": "^16.0.1",
    "@types/jasmine": "~4.3.0",
    "@types/jest": "^29.5.1",
    "@typescript-eslint/eslint-plugin": "^5.59.2",
    "@typescript-eslint/parser": "^5.59.2",
    "autoprefixer": "^10.4.14",
    "eslint": "^8.40.0",
    "eslint-config-prettier": "^8.8.0",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-prefer-arrow": "^1.2.3",
    "eslint-plugin-prettier": "^4.2.1",
    "husky": "^8.0.3",
    "jasmine-core": "^4.6.0",
    "jest": "^29.5.0",
    "karma": "^6.4.2",
    "karma-chrome-launcher": "^3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "postcss": "^8.4.21",
    "prettier": "^2.8.8",
    "tailwindcss": "^3.2.2",
    "typescript": "^5.0.4"
  }

Anything else?

No response

dgp1130 commented 1 year ago

Looks like two issues here:

  1. ESBuild detected output file conflict with layout.component.spec.mjs, home.component.spec.mjs, and home.component.spec.mjs.map (are there others? text looks cut off). Do you have multiple source files with these names? Maybe home.component.spec.ts and home.component.spec.mts?
  2. Angular CLI ignored this error and tried to run Jest anyways. If ESBuild failed first, we should abort the Jest run altogether.
cplummer-linq commented 1 year ago

This can happen when you have two .spec.ts files that have the same names in different folders. The jest builder is not respecting the folder nesting, and is flattening all the output .mjs files into the same outputPath.

I've made a repo to demonstrate the issue: https://github.com/cplummer-linq/ng16-jest-output-path

  1. Run 'ng test'. It should show these errors: X [ERROR] Two output files share the same path but have different contents: same-name.spec.mjs.map
    X [ERROR] Two output files share the same path but have different contents: same-name.spec.mjs
  2. Rename one of the same-name-spec.ts files to a different name.
  3. Run 'ng test' again. It should run successfully.