ng test not obeying single run flag
Versions
Angular CLI: 6.0.0
Node: 10.0.0
OS: win32 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
@angular/cdk 6.0.1
@angular/material 6.0.1
@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
Repro steps
- Upgrade Angular CLI to V6 (global/local)
- Upgrade Angular to V6
- Upgrade other dependencies
- Ensure karma.conf.js has
singleRun: falsein it - Run
ng tOR runng t --single-run=false
Observed behavior
If ng t is run, tests will run successfully but browser window will close on finish (despite karma.conf.js having singleRun: false inside it)
If ng t --single-run=false is run, it errors: Unknown option: '--singleRun' Note that running ng t --no-single-run creates the same error.
Desired behavior
I would like the browser window to remain open, as it always did, pre-upgrade
Same issue here as well, any fix?
Are you able to run unit tests after angular 6 upgrade?
Same here, any solutions? It's a bit urgent.
This works:
ng test --watch
Cheers!
Same here
@JohannesHoppe are you able to get code coverage report? While running ng test i m getting error in test.ts
import 'zone.js/dist/long-stack-trace-zone';
Chrome 66.0.3359 (Windows 7 0.0.0) ERROR { "message": "Uncaught SyntaxError: Unexpected string\nat test.ts:2:8\n\nSyntaxError: Unexpected string", "str": "Uncaught SyntaxError: Unexpected string\nat test.ts:2:8\n\nSyntaxError: Unexpected string" } Chrome 66.0.3359 (Windows 7 0.0.0) ERROR { "message": "Uncaught SyntaxError: Unexpected string\nat test.ts:2:8\n\nSyntaxError: Unexpected string", "str": "Uncaught SyntaxError: Unexpected string\nat test.ts:2:8\n\nSyntaxError: Unexpected string" }
Chrome 66.0.3359 (Windows 7 0.0.0) ERROR { "message": "Uncaught SyntaxError: Unexpected string\nat test.ts:2:8\n\nSyntaxError: Unexpected string", "str": "Uncaught SyntaxError: Unexpected string\nat test.ts:2:8\n\nSyntaxError: Unexpected string" }
@Tataraovoleti
Sure, ng test --watch --code-coverage gives me watch-mode and code-coverage.
It's located in './coverage'
Can you please provide me your karma.conf.js configuration? Did you configure preProcessors in karma.conf.js ?
It's the default:
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/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-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
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
Hi @JohannesHoppe Thank you , this configuration is working for me.
I created a new project with Angular CLI 6.0, I have not modified the Karma configuration file. I confirm that when the test ends google closes
ng test --watch is a workaround, we wait for fix, thks
is ng test --single-run is equivalent to ng test now in angular6?
I observed same behavior.
I'm experiencing same issue after upgrading. ng test --watch works like ng test did before upgrade. Is this the expected behavior in angular 6?
The wiki of the angular-cli says: You can run tests a single time via --watch=false https://github.com/angular/angular-cli/wiki/test tried it out and it works
@Gerros The issue is that ng test no longer observes the singleRun flag in the karma configuration, and instead forces the tests into a single-run. So the problem is that the tests ALWAYS single-run now (unless you specify --watch as a command line flag)
@jwa107 This should be corrected in 6.0.1. The singleRun karma option is only changed if the watch option is explicitly used. The single run command line flag no longer exists in v6.
If issues still presents with the latest version of the CLI, please open a new issue detailing the problem.
--no-watch should also work (more elegant).
I switch ng test --single-run to ng test --watch=false and it is works good.
ng test --watch=false doesn't work with Angular CLI 7.0.1, it still watches and can't be killed unless you spam ctrl + c about 15 times quickly..
Same result in @angular/[email protected] and actually it looks like the test runs twice