Skip to content

Karma unit tests do not work if library has no .spec.ts files - Error: Specified patterns: "**/*.spec.ts" did not match any spec files. #24644

@lukapif

Description

@lukapif

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

14

Description

We are using NX CLI in our project. I upgraded my angular with the help of NX from 13->14 and run nx run-many --all --target=test and everything works fine. Unit tests are all successfully run. Even in the Angular libraries where there are zero unit tests.

Later I updated angular from 14-15 and unit tests are failing in the libraries where there is no .spec.ts file present.

What I have managed to figure out from debugging is the problem is when updating "@angular-devkit/build-angular": "14.2.10",
to "@angular-devkit/build-angular": "15.1.3", If I revert this dependency and run unit tests then it works.

Problem occurs in file find-tests-plugin.js from node_modules/@angular-devkit/build-angular/src/builders/karma/. Below is the part of the code that returns the error. If I comment out this part of the code then it is ok.
const specFiles = await findTests(include, exclude, workspaceRoot, projectSourceRoot); if (!specFiles.length) { (0, assert_1.default)(this.compilation, 'Compilation cannot be undefined.'); (0, webpack_diagnostics_1.addError)(this.compilation,Specified patterns: "${include.join(', ')}" did not match any spec files.); }

This part of code returns
Error: Specified patterns: "**/*.spec.ts" did not match any spec files.

I have flag failOnEmptyTestSuite set to false in the karma.conf.js.

Minimal Reproduction

nx g lib shared/api/test
Which generator would you like to use? · @nrwl/angular:library

UPDATE package.json
UPDATE libs/shared/api/registers/project.json
UPDATE angular.json
CREATE libs/shared/api/test/README.md
CREATE libs/shared/api/test/tsconfig.lib.json
CREATE libs/shared/api/test/tsconfig.spec.json
CREATE libs/shared/api/test/src/index.ts
CREATE libs/shared/api/test/src/lib/shared-api-test.module.ts
CREATE libs/shared/api/test/project.json
CREATE libs/shared/api/test/karma.conf.js
UPDATE tsconfig.base.json
CREATE libs/shared/api/test/tsconfig.json
CREATE libs/shared/api/test/.eslintrc.json

nx run shared-api-test:test

Exception or Error

✔ Browser application bundle generation complete.

Error: Specified patterns: "**/*.spec.ts" did not match any spec files.


01 02 2023 22:43:39.121:INFO [karma-server]: Karma v6.4.1 server started at http://localhost:9876/
01 02 2023 22:43:39.132:INFO [launcher]: Launching browsers ChromeHeadlessNoSandbox with concurrency unlimited
01 02 2023 22:43:39.137:ERROR [karma-server]: Error: Found 1 load error
    at Server.<anonymous> (D:\workspace\WS_ANGULAR\nlb-retail-web\node_modules\karma\lib\server.js:244:26)
    at Object.onceWrapper (node:events:627:28)
    at Server.emit (node:events:525:35)
    at Server.emit (node:domain:489:12)
    at emitListeningNT (node:net:1497:10)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)

 >  NX   Ran target test for project shared-api-test(18s)

    ×    1/1 failed
    √    0/1 succeeded [0 read from cache]

Your Environment

"dependencies": {
    "@angular/animations": "15.1.2",
    "@angular/cdk": "15.1.2",
    "@angular/common": "15.1.2",
    "@angular/compiler": "15.1.2",
    "@angular/core": "15.1.2",
    "@angular/forms": "15.1.2",
    "@angular/localize": "15.1.2",
    "@angular/platform-browser": "15.1.2",
    "@angular/platform-browser-dynamic": "15.1.2",
    "@angular/router": "15.1.2",
    "@backbase/ui-ang": "~8.2.0-pr.5",
    "@material/animation": "^3.0.0",
    "@ng-bootstrap/ng-bootstrap": "~11.0.0",
    "@ng-select/ng-select": "~8.0.0",
    "@ngrx/effects": "15.0.0",
    "@ngrx/store": "15.0.0",
    "@nrwl/angular": "15.6.3",
    "@storybook/core-server": "6.5.15",
    "@swimlane/ngx-charts": "^20.1.0",
    "@tailwindcss/line-clamp": "^0.4.0",
    "angular-oauth2-oidc": "13.0.1",
    "bignumber.js": "~9.0.1",
    "bootstrap": "^4.5.2",
    "i18n-iso-countries": "^7.5.0",
    "moment": "^2.29.3",
    "ngx-cookie-service": "~12.0.3",
    "ngx-mask": "~13.0.0",
    "ngx-quill": "~16.0.0",
    "quill": "~1.3.7",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "twilio": "~3.81.0",
    "uuid": "^9.0.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "15.1.3",
    "@angular-devkit/core": "15.1.3",
    "@angular-eslint/eslint-plugin": "15.0.0",
    "@angular-eslint/eslint-plugin-template": "15.0.0",
    "@angular-eslint/template-parser": "15.0.0",
    "@angular/cli": "~15.1.0",
    "@angular/compiler-cli": "15.1.2",
    "@angular/language-service": "15.1.2",
    "@ng-apimock/core": "~3.5.0",
    "@ng-apimock/dev-interface": "~3.1.1",
    "@nrwl/cli": "15.6.3",
    "@nrwl/cypress": "15.6.3",
    "@nrwl/devkit": "15.6.3",
    "@nrwl/eslint-plugin-nx": "15.6.3",
    "@nrwl/jest": "15.6.3",
    "@nrwl/linter": "15.6.3",
    "@nrwl/node": "15.6.3",
    "@nrwl/nx-cloud": "15.0.3",
    "@nrwl/storybook": "15.6.3",
    "@nrwl/tao": "15.6.3",
    "@nrwl/workspace": "15.6.3",
    "@playwright/test": "~1.22.2",
    "@storybook/addon-essentials": "6.5.15",
    "@storybook/angular": "6.5.15",
    "@storybook/builder-webpack5": "6.5.15",
    "@storybook/manager-webpack5": "6.5.15",
    "@storybook/testing-angular": "^0.0.12",
    "@types/jasmine": "4.0.3",
    "@types/jest": "28.1.8",
    "@types/node": "18.7.1",
    "@typescript-eslint/eslint-plugin": "5.36.1",
    "@typescript-eslint/parser": "5.36.1",
    "cypress": "^12.2.0",
    "eslint": "8.15.0",
    "eslint-config-prettier": "8.1.0",
    "eslint-plugin-cypress": "^2.10.3",
    "eslint-plugin-import": "~2.26.0",
    "husky": "^8.0.1",
    "jasmine-core": "4.2.0",
    "jasmine-spec-reporter": "7.0.0",
    "jest": "28.1.3",
    "karma": "6.4.1",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "2.1.0",
    "karma-jasmine": "5.1.0",
    "karma-jasmine-html-reporter": "2.0.0",
    "ngx-i18nsupport": "~0.17.1",
    "prettier": "2.6.2",
    "pretty-quick": "^3.1.3",
    "protractor": "~7.0.0",
    "tailwindcss": "^3.0.24",
    "ts-jest": "28.0.8",
    "ts-node": "10.9.1",
    "typescript": "4.8.4"
  }

Anything else relevant?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions