3

I am attempting to update an Angular 5 project to Angular 6, all of the sources are available online (Commit #1, Commit #2) but I will try to highlight the relevant snippets here. Everything works fine using Angular 5 and the changes that were made for the migration initially didn't touch the test-setup at all.

I haven't managed to turn my problem into a minimal reproduction case, but if anyone is willing to try to run my exact code on their own machine I have included instructions at the bottom of this question. You can also see the exact output in the bitbucket-Pipeline log.

The basic symptom I am having is the following "Executed 0 of 0"-error when running ng test:

marcus@marcus-pc:~/p/s/client >>> node_modules/.bin/ng test                                                           
 10% building modules 1/1 modules 0 active(node:6192) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
 10% building modules 3/3 modules 0 active10 05 2018 10:55:59.897:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
10 05 2018 10:55:59.898:INFO [launcher]: Launching browsers ChromeHeadless, FirefoxHeadless with unlimited concurrency
 10% building modules 3/4 modules 1 active …ratch-sql/client/src sync /\.spec\.ts$/10 05 2018 10:55:59.902:INFO [launcher]: Starting browser Chrome
10 05 2018 10:55:59.912:INFO [launcher]: Starting browser Firefox
10 05 2018 10:56:06.064:INFO [HeadlessChrome 0.0.0 (Linux 0.0.0)]: Connected on socket inKwlXEJ84kIUYzUAAAA with id 55152332
10 05 2018 10:56:06.082:INFO [Firefox 59.0.0 (Linux 0.0.0)]: Connected on socket LmNu7uNvlTgbKPKoAAAB with id 83729562
HeadlessChrome 0.0.0 (Linux 0.0.0): Executed 0 of 0 ERROR (0.017 secs / 0 secs)
Firefox 59.0.0 (Linux 0.0.0): Executed 0 of 0 ERROR (0.004 secs / 0 secs)

I initially suspected this to be a path issue, but when looking at the loaded sources in the karma debug runner all of my .spec.ts files seem to be properly compiled and present: Firefox Debugger showing the loaded specs

So there is probably something wrong with my general configuration. I therefore checked my angular.json to see which files seem to be involved in the testing target:

    "test": {
      "builder": "@angular-devkit/build-angular:karma",
      "options": {
        "main": "src/test.ts",
        "karmaConfig": "./karma.conf.js",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "src/tsconfig.test.json",
      }
    },

My src/test.ts file seems to be slightly outdated (at least the angular documentation page uses a different file) and looks like this. Using the mentioned file from the aio-project yields identical results:

import './polyfills.ts';

import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
declare var __karma__: any;
declare var require: any;

// Prevent Karma from running prematurely.
__karma__.loaded = function() { };

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
// Finally, start Karma to run the tests.
__karma__.start();

Lastly my karma.conf differs slightly from my "aio reference file" (mine includes a JUnit reporter), but again using the "original" file doesn't change anything about the "0 specs found" error.

// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-firefox-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('karma-junit-reporter'),
      require('@angular-devkit/build-angular/plugins/karma'),
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, 'coverage'),
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    junitReporter: {
      outputDir: 'test-results'
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: ['junit', 'progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    customLaunchers: {
      ChromeHeadless: {
        base: 'Chrome',
        flags: [
          '--headless',
          '--disable-gpu',
          // Without a remote debugging port, Google Chrome exits immediately.
          '--remote-debugging-port=9222',
          '--no-sandbox'
        ],
      },
      FirefoxHeadless: {
        base: 'Firefox',
        flags: [
          '--headless'
        ]
      }
    },
    browsers: ['ChromeHeadless', 'FirefoxHeadless'],
    singleRun: true
  });
};

If you are still reading this and are willing to run my code on your machine you may do the following:

  • Clone the angular-6 branch of my repository (git clone "https://bitbucket.org/marcusriemer/esqulino.git" -b angular-6).
  • Change into the client folder (cd client)
  • Run either my Makefile shortcuts (make install-deps client-test) or the "normal" npm and ng combo (npm install && node_modules/.bin/ng test).
Marcus Riemer
  • 7,244
  • 8
  • 51
  • 76
  • There's just too much code here and no clear hints of what might be wrong. Also, I don't think many of us will pull down some random code from a repo to test for ourselves. Paranoia I guess but probably the truth and with no intention to be rude! Try to get more error messages and minimize the question a bit and I'm sure we can help you out! :) – Daniel B May 10 '18 at 09:52
  • Yeah, I am quite aware of that. I have a sort of vague hope that somebody jumps in and says something like "this is a known issue, see over here" ... I attempted to turn this into a minimal reproducible testcase but simply couldn't "re-introduce" the error when migrating a "toy project" from Angular 5 to 6 :( – Marcus Riemer May 10 '18 at 09:58
  • @MarcusRiemer do you use angularfire in your project? – Yevgen May 11 '18 at 12:59
  • @Yevgen No, and also no "fancy" UI frameworks. – Marcus Riemer May 11 '18 at 13:12
  • 1
    I encountered a similar problem outlined here: https://github.com/karma-runner/karma-chrome-launcher/issues/137. Sadly, no solutions yet. – Knight Jul 05 '18 at 18:53
  • same here, see also https://github.com/karma-runner/karma/issues/2652 – Yvonne Aburrow Aug 29 '18 at 20:28
  • I tried changing the browser to Chrome in my `karma.conf.js` and got the following: > Incomplete: No specs found, , randomized with seed 88496 So I googled that and found this: https://stackoverflow.com/questions/49995731/jasmine-library-no-specs-found-when-running-same-test-twice which might help – Yvonne Aburrow Aug 29 '18 at 20:36

0 Answers0