angular-cli: ng test not working after upgrade to 6.0.0

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! myproj-web@0.0.1 test: `ng test`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the myproj-web@0.0.1 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 myproj-web@0.0.1~test: Args: [ '/d /s /c', 'ng test' ]
11 silly lifecycle myproj-web@0.0.1~test: Returned: code: 1  signal: null
12 info lifecycle myproj-web@0.0.1~test: Failed to exec test script
13 verbose stack Error: myproj-web@0.0.1 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 myproj-web@0.0.1
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 myproj-web@0.0.1 test: `ng test`
22 error Exit status 1
23 error Failed at the myproj-web@0.0.1 test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 16
  • Comments: 42 (4 by maintainers)

Commits related to this issue

Most upvoted comments

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.

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.

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

It looks like test.ts is not loaded

Hey all, thanks for the reports. I think I know what was happening. It was two things together:

  • AngularFire2 was importing zone directly (https://github.com/angular/angularfire2/issues/1597). This caused the “Zone already loaded.” message.
  • the Angular CLI build system was splitting the common parts of polyfills and test but not loading the common bits. This resulted in no error messages and no tests ran.

The first problem was fixed in https://github.com/angular/angularfire2/pull/1599 and released in angularfire2@5.0.0-rc.8. The second problem has a fix incoming in https://github.com/angular/devkit/pull/993.

@herkulano I got your repro to work by manually applying the changes in my PR and updating to angularfire2@5.0.0-rc.8.

If you want to try this yourself, open node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/test.js and replace

chunks: buildOptions.commonChunk ? 'all' : 'initial',`

with

chunks: (chunk) => chunk.name !== "polyfills",

@Ristaaf your repro seems to work fine if I add import 'zone.js/dist/zone-patch-rxjs'; after import 'zone.js/dist/zone'; .

In my situation I had one spec file that silently failed the whole test run. After commenting out this spec, I was able to run tests again.

To find the specific test, I ran ls src/**/*.spec.ts | grep -o ".........$" | cut -d. -f1 | sort | uniq to get the previous letter before “.spec.ts” part. Then I added these letters. one by one, to regular expression in test.ts file, like a\.spec\.ts, then (a|b)\.spec\.ts etc. At the beginning, I run more and more tests successfully, until the regex included corrupted test. For me, the last letter added was ‘e’, so it was either service or pipe specification.

Subsequently, I was able to find autogenerated service test, that caused the error. I am pretty sure, that the error was in beforeEach part, however I can’t figure out the exact reason.

Hope my comment helps someone.

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

@herkulano it gave you no pointers because of the problem I am fixing in angular/devkit#993.

the Angular CLI build system was splitting the common parts of polyfills and test but not loading the common bits. This resulted in no error messages and no tests ran.

@WilliamChelman this method did expose an issue with my paths which are defined in tsconfig.json but were not being defined in the tsconfig.spec.json, this was not an issue in Angular 5.x. I have updated tsconfig.spec.json with those now as well:

 "paths": {
      "rxjs-compat": ["rxjs-compat.mock.ts"],
      "@app/*": ["app/*"],
      "@env/*": ["environments/*"]
    }

The only change seems to be an addition of a SUCCESS entry in the output:

Chrome 66.0.3359 (Mac OS X 10.13.4): Executed 0 of 0 SUCCESS (0 secs / 0 secs)
Chrome 66.0.3359 (Mac OS X 10.13.4): Executed 0 of 0 ERROR (0.02 secs / 0 secs)

I am surprised no one from the team have weighed in on this as yet, not even to merely label the issue 😐

If that might help, for our configuration it was the presence of rxjs-compat while testing that made everything fail (well, 0 of 0 executed), so in tsconfig.spec.json we added

"compilerOptions": {
        "paths": {
            "rxjs-compat": ["rxjs-compat.mock.ts"],
         }
}

where rxjs-compat.mock.ts is just

console.warn('False rxjs-compat loaded for testing, you should remove this whenever possible');

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.

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

I’ve checked code generated by jasmine.

All specs are present but none of them are loaded.

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

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.