Angular-cli: angular 6 ng test --code-coverage --single-run is not working

Created on 7 May 2018  路  11Comments  路  Source: angular/angular-cli

I recently migrated project into angular 6 version. While running unit test , i m getting fallowing error
09 05 2018 11:32:31.983:DEBUG [plugin]: Loading inlined plugin (defining launcher:ChromeHeadless). 09 05 2018 11:32:31.984:ERROR [preprocess]: Can not load "@angular-devkit/build-angular", it is not registered! Perhaps you are missing some plugin? 09 05 2018 11:32:31.984:DEBUG [karma]: Registered a load error of type preprocessor with name @angular-devkit/build-angular 07 05 2018 17:19:38.336:DEBUG [config]: Loading config angular6\karma.conf.js 07 05 2018 17:19:38.336:DEBUG [config]: autoWatch set to false, because of singleRun 07 05 2018 17:19:38.336:DEBUG [plugin]: Loading inlined plugin (defining framework:jasmine). 07 05 2018 17:19:38.336:DEBUG [plugin]: Loading inlined plugin (defining launcher:Chrome, launcher:ChromeCanary, launcher:Chromium, launcher:Dartium, test). 07 05 2018 17:19:38.352:DEBUG [plugin]: Loading inlined plugin (defining reporter:kjhtml). 07 05 2018 17:19:38.352:DEBUG [plugin]: Loading inlined plugin (defining reporter:coverage-istanbul). 07 05 2018 17:19:38.352:DEBUG [plugin]: Loading inlined plugin (defining framework:@angular-devkit/build-angular, reporter:@angular-devkit/build-angular--sourcemap-reporter, reporter:@angular-devkit/build-angular--event-reporter, middleware:@angular-devkit/build-angular--blocker, middleware:@angular-devkit/build-angular--fallback). 07 05 2018 17:19:38.352:DEBUG [plugin]: Loading inlined plugin (defining launcher:ChromeHeadless). 07 05 2018 17:19:38.352:ERROR [preprocess]: Can not load "@angular-devkit/build-angular", it is not registered! Perhaps you are missing some plugin? 07 05 2018 17:19:38.352:DEBUG [karma]: Registered a load error of type preprocessor with name @angular-devkit/build-angular 10% building modules 1/1 modules 0 active07 05 2018 17:19:38.741:DEBUG [web-server]: Instantiating middleware 07 05 2018 17:19:38.741:DEBUG [reporter]: Trying to load reporter: @angular-devkit/build-angular--sourcemap-reporter 07 05 2018 17:19:38.741:DEBUG [reporter]: Trying to load color-version of reporter: @angular-devkit/build-angular--sourcemap-reporter (@angular-devkit/build-angular--sourcemap-reporter_color) 07 05 2018 17:19:38.741:DEBUG [reporter]: Couldn't load color-version. 07 05 2018 17:19:38.741:DEBUG [reporter]: Trying to load reporter: @angular-devkit/build-angular--event-reporter 07 05 2018 17:19:38.741:DEBUG [reporter]: Trying to load color-version of reporter: @angular-devkit/build-angular--event-reporter (@angular-devkit/build-angular--event-reporter_color) 07 05 2018 17:19:38.741:DEBUG [reporter]: Couldn't load color-version. 07 05 2018 17:19:38.845:DEBUG [reporter]: Trying to load reporter: kjhtml 07 05 2018 17:19:38.846:DEBUG [reporter]: Trying to load color-version of reporter: kjhtml (kjhtml_color) 07 05 2018 17:19:38.846:DEBUG [reporter]: Couldn't load color-version. 07 05 2018 17:19:38.847:DEBUG [reporter]: Trying to load reporter: coverage-istanbul 07 05 2018 17:19:38.848:DEBUG [reporter]: Trying to load color-version of reporter: coverage-istanbul (coverage-istanbul_color) 07 05 2018 17:19:38.848:DEBUG [reporter]: Couldn't load color-version. (node:18196) DeprecationWarning: Tapable.plugin is deprecated. Use new API on.hooksinstead 07 05 2018 17:19:51.177:INFO [karma]: Karma v2.0.2 server started at http://0.0.0.0:9876/ 07 05 2018 17:19:51.177:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency 07 05 2018 17:19:51.177:ERROR [karma]: Found 1 load error npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] test:watch:ng test --code-coverage`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test:watch 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:`

Versions

Output from: ng --version.
Angular CLI: 6.0.0
Node: 8.11.1
OS: win32 x64
Angular: 6.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router, service-worker

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

devkibuild-angular medium more info regression bufix

Most helpful comment

Hi, I had same problem, I found response here :

You can run tests a single time via --watch=false.

All 11 comments

Hi @Tataraovoleti ,

Do you have a project that we can clone and use? If not, could you paste your angular.json and your karma.conf.js files? Thanks!

HI thank you,
Here i pasted karma.conf.js and angular.json

`module.exports = function (config) {
// const ChromiumRevision = require('puppeteer/package.json').puppeteer.chromium_revision;
// const Downloader = require('puppeteer/utils/ChromiumDownloader');
// const revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), ChromiumRevision);
// console.log(revisionInfo.executablePath);

process.env.CHROME_BIN = require('puppeteer').executablePath();
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
files: [
{ pattern: './test.ts', watched: false }
],
preprocessors: {
'./test.ts': ['@angular-devkit/build-angular']
},
mime: {
'text/x-typescript': ['ts', 'tsx']
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'), reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
angularCli: {
config: './angular.json',
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: true,
browsers: ['ChromeHeadless'],
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: [
'--headless',
'--disable-gpu',
// Without a remote debugging port, Google Chrome exits immediately.
'--remote-debugging-port=9222',
'--max_old_space_size=4096',
'--disable-web-security'
],
}
},
captureTimeout: 210000,
browserDisconnectTolerance: 3,
browserDisconnectTimeout: 210000,
browserNoActivityTimeout: 210000,
});
};`

{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "angular6-migrate": { "root": ".", "sourceRoot": ".", "projectType": "application", "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "build/", "index": ".//index.html", "main": ".//container/ui/app/main.ts", "tsConfig": ".//tsconfig.app.json", "polyfills": ".//polyfills.ts", "assets": [ "container/ui/assets/font", "container/ui/assets/img" ], "styles": [ "container/ui/assets/css/widgets/scrollpane/scrollpane.css", "container/ui/assets/css/widgets/button/button.css", "container/ui/assets/css/widgets/form/form.css", "container/ui/assets/css/layout/layout.css", "container/ui/assets/css/widgets/input-validator/number-polyfill.css" ], "scripts": [ "node_modules/lodash/lodash.js", "node_modules/jquery/dist/jquery.js", "node_modules/jquery-ui-dist/jquery-ui.js", "node_modules/perfect-scrollbar/dist/js/perfect-scrollbar.jquery.js", "node_modules/moment/moment.js" ] }, "configurations": { "production": { "optimization": true, "outputHashing": "all", "sourceMap": false, "extractCss": true, "namedChunks": false, "aot": true, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true, "serviceWorker": true, "ngswConfigPath": ".//ngsw-config.json", "fileReplacements": [ { "replace": ".//container/ui/app/environments/environment.ts", "with": ".//container/ui/app/environments/environment.prod.ts" } ] } } }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { "browserTarget": "angular6-migrate:build" }, "configurations": { "production": { "browserTarget": "angular6-migrate:build:production" } } }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", "options": { "browserTarget": "angular6-migrate:build" } }, "test": { "builder": "@angular-devkit/build-angular:karma", "options": { "main": ".//test.ts", "karmaConfig": ".//karma.conf.js", "polyfills": ".//polyfills.ts", "tsConfig": ".//tsconfig.spec.json", "scripts": [ "node_modules/lodash/lodash.js", "node_modules/jquery/dist/jquery.js", "node_modules/jquery-ui-dist/jquery-ui.js", "node_modules/perfect-scrollbar/dist/js/perfect-scrollbar.jquery.js", "node_modules/moment/moment.js" ], "styles": [ "container/ui/assets/css/widgets/scrollpane/scrollpane.css", "container/ui/assets/css/widgets/button/button.css", "container/ui/assets/css/widgets/form/form.css", "container/ui/assets/css/layout/layout.css", "container/ui/assets/css/widgets/input-validator/number-polyfill.css" ], "assets": [ "container/ui/assets/font", "container/ui/assets/img" ] } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [ ".//tsconfig.app.json", ".//tsconfig.spec.json" ], "exclude": [] } } } }, "angular6-migrate-e2e": { "root": "", "sourceRoot": "", "projectType": "application", "architect": { "e2e": { "builder": "@angular-devkit/build-angular:protractor", "options": { "protractorConfig": "./protractor.conf.js", "devServerTarget": "angular6-migrate:serve" } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [], "exclude": [] } } } } }, "defaultProject": "angular6-migrate", "schematics": { "@schematics/angular:class": { "spec": false }, "@schematics/angular:component": { "spec": true, "inlineStyle": false, "inlineTemplate": false, "prefix": "app", "styleext": "css" }, "@schematics/angular:directive": { "prefix": "app" } } }

I think you need to npm i @angular-devkit/build-angular

I already done, it is available in node_modules. But it is not getting picked

Hi, I had same problem, I found response here :

You can run tests a single time via --watch=false.

The singleRun piece is related to #10711 (?)

As @kekel87 says: switching over to --watch=false is working for the time.

https://github.com/angular/angular-cli/wiki/test

Tests will execute after a build is executed via Karma, and it will automatically watch your files for changes. You can run tests a single time via --watch=false.

I was having this problem but it turned out to be due to polyfills.ts being added to the tsconfig.spec.json,
Polyfills was importing core-js/es7/reflect and I was also doing the same in the src/test.ts removing the import from src/test.ts fixed my issue

It would be nice to have documentation for all of the cli breaking changes here, if breaking changes are going to be made.

So, for example, if someone has been doing this for a couple of versions/years:

ng test -sr -cc

They should not have to start searching github for obscure errors like :

Configuration ',' could not be found in project 

... that seem to reduce to ' change/update your cli args'

@jderus Please note that we started following POSIX flags, so single dashes flags are single letters only. The -c flag has been updated to specify a configuration, and our workspace has been entirely revamped. This whole thread is likely an issue of documentation of how the new workspace integrates with command line flags and the configuration file. We're working on improving our documentation for the CLI and integrating it with angular.io, so this will be resolved.

We also removed the single run flag, and use watch everywhere for consistency.

Closing this as ng test --watch=false --code-coverage works.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IngvarKofoed picture IngvarKofoed  路  3Comments

NCC1701M picture NCC1701M  路  3Comments

rajjejosefsson picture rajjejosefsson  路  3Comments

ericel picture ericel  路  3Comments

daBishMan picture daBishMan  路  3Comments