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:
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
andng
combo (npm install && node_modules/.bin/ng test
).