ng test fails in angular universal Error "Incomplete: No specs found, , randomized with seed 48751"
Asked Answered
R

7

10

convert angular 7 project into angular universal while running "ng test" command giving error as "Incomplete: No specs found, , randomized with seed 48751". Tried different ways mention over stackoverflow but nothing work for me.

ERROR in ./src/polyfills.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: ../src/polyfills.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (../node_modules/@ngtools/webpack/src/packages/ngtools/webpack/src/angular_compiler_plugin.ts:1024:15)
    at plugin.done.then (../node_modules/@ngtools/webpack/src/packages/ngtools/webpack/src/loader.ts:49:29)
    at process._tickCallback (internal/process/next_tick.js:68:7)
 @ multi ./src/polyfills.ts ./node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/jit-polyfills.js polyfills[0]

Expected output to be ng test command run properly without giving any issue so that my unit test-cases gonna execute.

Rains answered 17/9, 2019 at 9:31 Comment(0)
R
10

Finally after lot of experiments got the solution. just add

`"include": [
    "**/*.spec.ts",
    "**/*.d.ts",
    "**/*.ts"
  ]`

in "tsconfig.spec.json" Hope this helpful :)

Rains answered 17/9, 2019 at 12:18 Comment(0)
A
10

This error may happen if there is some compile error in some of the unit test files, if this happens, the compilation error will be seen in the command prompt where "ng test" has been run.

For example, the built-in "app.component.spec.ts" contains a test expecting the title variable to have the App title. If you have deleted this variable from "app.component.ts" the fact that the test still contains it will not cause the build to fail but an error will happing when running the tests.

Atmolysis answered 1/8, 2021 at 18:20 Comment(0)
W
2

For me, it was actually a compile error that was causing it. I was also receiving:

error TS2591: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.

Fixed it by adding "types": ["node"] and "typeRoots": ["node_modules/@types"] to the compilerOptions in the tsconfig.spec.json, so that it looks something like this in the end:

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "outDir": "./out-tsc/spec",
    "types": [
      "jasmine",
      "node"
    ],
    "typeRoots": ["node_modules/@types"]
  },
  "files": [
    "src/test.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.spec.ts",
    "src/**/*.d.ts"
  ]
}
Wamsley answered 21/8, 2020 at 12:28 Comment(0)
R
2

Spec files shouldn't contain compiler errors. Create new project, then remove import { AppComponent } from './app.component'; in app.component.ts and run ng test. You'll see Incomplete: No specs found, , randomized with seed. Try to fix compiler errors in your spec files.

Rectify answered 30/10, 2023 at 10:34 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Olympe
H
1

You just have to have the correct paths.

I got a lot of errors with the following in the tsconfig.spec.json file:

          "files": [
            "test.ts",
            "polyfills.ts"
          ],
          "include": [
            "**/*.spec.ts",
            "**/*.d.ts"
          ]

Then I got everything right after I changed the paths to the following:

          "files": [
            "src/test.ts",
            "src/polyfills.ts"
          ],
          "include": [
            "src/**/*.spec.ts",
            "src/**/*.d.ts"
          ]
Hawkweed answered 31/7, 2020 at 13:46 Comment(0)
N
0

Check your angular.json file. You may have the wrong configuration. Either the script files are in styles or the styles are in scripts.

I had few .js files included inside the style tag causing the issue.

Narrative answered 20/2, 2021 at 10:9 Comment(1)
Please don' t post images when you can post text - see How to Answer.Liqueur
A
0

Hope this works for you.

"include": [
"**/*.spec.ts",
"**/*.d.ts",
"**/*.]

Add this above lines of code into "tsconfig.spec.json" file.

Anoa answered 27/5, 2022 at 11:2 Comment(1)
The syntax is invalidTurnbow

© 2022 - 2024 — McMap. All rights reserved.