angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng test not working after upgrade to 6.0.0

Open DominicBoettger opened this issue 8 years ago • 42 comments

After upgrading the cli the unit tests doesn't start anymore. Previous behaviour was that the unit tests were found and executed. Now it does not find the unit tests and says 0 of 0 executed.

Versions

Angular CLI: 6.0.0-rc.6
Node: 9.7.1
OS: win32 x64
Angular: 5.2.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

Repro steps

  1. Upgrade to latest cli
  2. ng test

Observed behavior

27 04 2018 14:59:35.185:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
27 04 2018 14:59:35.191:INFO [launcher]: Launching browser Chrome with unlimited concurrency
27 04 2018 14:59:35.201:INFO [launcher]: Starting browser Chrome                                                                                                                                                                                                                      27 04 2018 15:00:26.221:INFO [Chrome 66.0.3359 (Windows 10 0.0.0)]: Connected on socket _q17vZKEaK6MoqgCAAAA with id 70169079
Chrome 66.0.3359 (Windows 10 0.0.0): Executed 0 of 0 ERROR (0.016 secs / 0 secs)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `ng test`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\myuser\AppData\Roaming\npm-cache\_logs\2018-04-27T13_00_28_789Z-debug.log
10 silly lifecycle [email protected]~test: Args: [ '/d /s /c', 'ng test' ]
11 silly lifecycle [email protected]~test: Returned: code: 1  signal: null
12 info lifecycle [email protected]~test: Failed to exec test script
13 verbose stack Error: [email protected] test: `ng test`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:285:16)
13 verbose stack     at EventEmitter.emit (events.js:127:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:127:13)
13 verbose stack     at maybeClose (internal/child_process.js:936:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
14 verbose pkgid [email protected]
15 verbose cwd C:\Users\myuser\myproj\myproj-web
16 verbose Windows_NT 10.0.16299
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
18 verbose node v9.7.1
19 verbose npm  v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] test: `ng test`
22 error Exit status 1
23 error Failed at the [email protected] test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

DominicBoettger avatar Apr 27 '18 14:04 DominicBoettger

.angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "myproj-web": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              {
                "glob": "**/*",
                "input": "src/assets",
                "output": "/assets"
              },
              {
                "glob": "**/*",
                "input": "src/favicon.ico",
                "output": "/favicon.ico"
              }
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "localdev": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.localdev.ts"
                }
              ]
            },
            "localdev-other": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.localdev-other.ts"
                }
              ]
            },
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "serviceWorker": false,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            },
            "demo": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.demo.ts"
                }
              ]
            },
            "demo-other": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.demo-six.ts"
                }
              ]
            },
            "e2e-tests": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.e2e-tests.ts"
                }
              ]
            },
            "preview": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "serviceWorker": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.preview.ts"
                }
              ]
            },
            "dev-other": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.dev-other.ts"
                }
              ]
            },
            "prod-other": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "serviceWorker": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod-other.ts"
                }
              ]
            },
            "preview-other": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.preview-other.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "myproj-web:build"
          },
          "configurations": {
            "localdev": {
              "browserTarget": "myproj-web:build:localdev"
            },
            "localdev-other": {
              "browserTarget": "myproj-web:build:localdev-other"
            },
            "production": {
              "browserTarget": "myproj-web:build:production"
            },
            "demo": {
              "browserTarget": "myproj-web:build:demo"
            },
            "demo-other": {
              "browserTarget": "myproj-web:build:demo-other"
            },
            "e2e-tests": {
              "browserTarget": "myproj-web:build:e2e-tests"
            },
            "preview": {
              "browserTarget": "myproj-web:build:preview"
            },
            "dev-other": {
              "browserTarget": "myproj-web:build:dev-other"
            },
            "prod-other": {
              "browserTarget": "myproj-web:build:prod-other"
            },
            "preview-other": {
              "browserTarget": "myproj-web:build:preview-other"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "myproj-web:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "src/karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [],
            "styles": [
              "src/styles.scss"
            ],
            "assets": [
              {
                "glob": "**/*",
                "input": "src/assets",
                "output": "/assets"
              },
              {
                "glob": "**/*",
                "input": "src/favicon.ico",
                "output": "/favicon.ico"
              }
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "myproj-web-e2e": {
      "root": "",
      "projectType": "application",
      "cli": {},
      "schematics": {},
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "myproj-web:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "cli": {},
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "styleext": "scss"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  }
}

DominicBoettger avatar May 01 '18 13:05 DominicBoettger

fixed after rc.8, but ng new still not work.

sandangel avatar May 01 '18 13:05 sandangel

Also tried

Angular CLI: 6.0.0-rc.8
Node: 9.11.1
OS: win32 x64
Angular: 6.0.0-rc.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.5.11
@angular-devkit/build-angular     0.5.11
@angular-devkit/build-optimizer   0.5.11
@angular-devkit/core              0.5.11
@angular-devkit/schematics        0.5.11
@angular/cdk                      5.2.5
@angular/cli                      6.0.0-rc.8
@angular/material                 5.2.5
@ngtools/webpack                  6.0.0-rc.9
@schematics/angular               0.5.11
@schematics/update                0.5.11
rxjs                              6.0.0
typescript                        2.7.2
webpack                           4.6.0

DominicBoettger avatar May 01 '18 13:05 DominicBoettger

I also tried to replace, karma, tsconfigs, edited angular.json, replaced angular.json with one from a new project........

DominicBoettger avatar May 01 '18 13:05 DominicBoettger

I'm running into a similar issue on @angular/cli 6.0.0. For me, the error line looks like Chrome 66.0.3359 (Linux 0.0.0): Executed 0 of 0 ERROR (0.009 secs / 0 secs). Similar to @DominicBoettger, the previous behavior for my project was that the tests were found and executed successfully. I'm having trouble troubleshooting this; no errors appear in my Chrome console when running the tests, and changing the Karma log level to DEBUG doesn't show any obvious issues. I tried futzing around with the dependency versions of Karma and Jasmine, thinking maybe I had upgraded them to incompatible versions, but that did not yield any solutions either. I've looked at the source changes made to my files as part of upgrading to Angular v6, but haven't been able to identify any leads. Also, I'm not even seeing the npm ERR! messages that @DominicBoettger posted. The Executed 0 of 0 ERROR (0.009 secs / 0 secs) is the last line of the output for me before ng test finishes.

pshields avatar May 04 '18 16:05 pshields

I've done some more investigation. My Karma entrypoint file (which I had renamed from src/test.ts to ui/main.karma.ts; all of my .ts files live in ui rather than src) does not seem to be getting executed in the way I'd expect: none of the console.error statements I place in that file ever show up in the console or terminal output (they do show up in the terminal output if I do the same thing in a clean ng new project.)

I confirmed that my main.karma.ts file is correctly referenced from the angular.json test/main option, and I confirmed that compilation fails if I change the "main" attribute to point to a nonexistent filename.

I confirmed that my *.spec.ts files are detected and included by Karma. The generated _karma_webpack_/main.js file available when running Karma contains a var map = {...} line section which maps my spec files to their workspace-relative paths, and the tests themselves show up in that file.

My suspicion is still that something is going wrong with the execution of my Karma main entrypoint file, since like I mentioned, any console.error or other logging statements I add to that file are not showing up in my terminal output. However, that file is very simple and is identical to the test.ts provided out-of-the-box by Angular CLI, so I'm still not sure what the issue is.

pshields avatar May 04 '18 19:05 pshields

I got this same issue when using ng upgrade when upgrading to angular 6 on a cli project.

crh225 avatar May 06 '18 00:05 crh225

I have the same issue. I've managed to get it to work simply by removing and adding the tests again. It worked without changing any configuration. In my case, I've pinpointed the tests down to 3, as soon as I turn any of them on again it throws the dreaded Executed 0 of 0 ERROR.

My guess is that there's some problem in the CLI that it doesn't surface errors and fails silently.

herkulano avatar May 06 '18 14:05 herkulano

I've got the same problem. Karma is running but no tests are executed.

It looks like test.ts is not loaded

kucharzyk avatar May 07 '18 05:05 kucharzyk

I've managed to reproduce the bug with a clean ng new project.

Steps:

Create a new project

ng new test

Add the modules

npm install firebase angularfire2 rxjs-compat --save

Add this code to the app.component.spec.ts

import { AngularFireAuth } from 'angularfire2/auth';
const af = AngularFireAuth;

Note:

If I run Jest instead of Karma I get the following error:

Zone already loaded.

Version:

Angular CLI: 6.0.0
Node: 10.0.0
OS: darwin x64
Angular: 6.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.0
@angular-devkit/build-angular     0.6.0
@angular-devkit/build-optimizer   0.6.0
@angular-devkit/core              0.6.0
@angular-devkit/schematics        0.6.0
@ngtools/webpack                  6.0.0
@schematics/angular               0.6.0
@schematics/update                0.6.0
rxjs                              6.1.0
typescript                        2.7.2
webpack                           4.6.0

herkulano avatar May 07 '18 08:05 herkulano

Could be related to https://github.com/angular/angularfire2/issues/1597

Downgrading firebase and angularfire2 fixes it:

"angularfire2": "5.0.0-rc.6",
"firebase": "~4.12",

herkulano avatar May 07 '18 08:05 herkulano

In my project all specs which tests components with jquery are affected. When deleting them it works. With angular 5.2 and cli 1.7 they worked. JQuery is defined in polyfills.ts. Still need to find out how to fix them.

The specs not working cause of JQuery could be fixed by not using an import for JQuery:

//import * as $ from 'jquery/dist/jquery';
declare let jQuery: any;

my polyfills.ts looks like this:

import * as $ from 'jquery/dist/jquery';
window['jQuery'] = $;

Only one test left which fails because the component I use seems not to be Angular 6 ready.

mszalbach avatar May 07 '18 09:05 mszalbach

I just ran into this as well (Executed 0 of 0 ERROR) after upgrading to Angular 6 on a project where tests previously ran successfully. I compared the test.ts file in my project versus a new project generated with the Angular 6 CLI, and noticed a lot of additional imports (import 'core-js/es7/reflect', import 'zone.js/dist/jasmine-patch'), etc in my project. I replaced these with:

import 'zone.js/dist/zone-testing';

and my tests started executing again. It definitely seems like an error message is getting swallowed somewhere.

kirstenOtting avatar May 07 '18 20:05 kirstenOtting

I've checked code generated by jasmine.

All specs are present but none of them are loaded.

kucharzyk avatar May 08 '18 05:05 kucharzyk

I'm facing the same issue mentioned above. It seems test.ts file is never executed

bruiztorres avatar May 09 '18 07:05 bruiztorres

I am experiencing the same issue, and I am ground completely to a halt for the time being :(

grantbowering avatar May 09 '18 23:05 grantbowering

Thanks to @herkulano for the mention that Jest ran and gave a real error message; as a workaround I dropped in Jest using a couple of the steps from here, and was able to execute my tests and see one failing and fix it...

Except now all my tests pass with jest, yet are still all "0 of 0 ERROR" with ng test.

¯\(ツ)/¯

grantbowering avatar May 10 '18 00:05 grantbowering

After upgrading to jest I realized the issue was my version of angular fire 2. I downgraded angular fire to 5.0.0-rc.5-next and it started working again. The main issue is that the error is not being shown to the user.

BrandonCravener avatar May 12 '18 15:05 BrandonCravener

Same here, it seems after upgrading some tests were broken so I fixed them with Jest. However, karma is still failing. FYI: I'm not using firebase in my project.

bruiztorres avatar May 16 '18 07:05 bruiztorres

In my case problem was caused by rxjs. In polyfills.ts I had imports like 'rxjs/add/operator/map' I could build and run app without any problem but test won't work.

After removing old operators (and some refactoring to made it work) tests started to work again

kucharzyk avatar May 16 '18 07:05 kucharzyk