ng test fails in angular universal Error “Incomplete: No specs found, , randomized with seed 48751”

故事扮演 提交于 2021-02-08 15:00:36

问题


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.


回答1:


Finally after lot of experiments got the solution. just add

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

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




回答2:


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"
          ]



回答3:


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"
  ]
}


来源:https://stackoverflow.com/questions/57971347/ng-test-fails-in-angular-universal-error-incomplete-no-specs-found-randomiz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!