angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng test not obeying single run flag

Open antipalindrome opened this issue 8 years ago • 22 comments

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: false in it
  • Run ng t OR run ng 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

antipalindrome avatar May 07 '18 18:05 antipalindrome

Same issue here as well, any fix?

Ratikant01 avatar May 08 '18 06:05 Ratikant01

Are you able to run unit tests after angular 6 upgrade?

Tataraovoleti avatar May 08 '18 07:05 Tataraovoleti

Same here, any solutions? It's a bit urgent.

JohannesHoppe avatar May 08 '18 10:05 JohannesHoppe

This works:

ng test --watch

Cheers!

JohannesHoppe avatar May 08 '18 10:05 JohannesHoppe

Same here

WizardPC avatar May 08 '18 15:05 WizardPC

@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 avatar May 09 '18 05:05 Tataraovoleti

@Tataraovoleti Sure, ng test --watch --code-coverage gives me watch-mode and code-coverage. It's located in './coverage'

JohannesHoppe avatar May 09 '18 06:05 JohannesHoppe

Can you please provide me your karma.conf.js configuration? Did you configure preProcessors in karma.conf.js ?

Tataraovoleti avatar May 09 '18 06:05 Tataraovoleti

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
  });
};

JohannesHoppe avatar May 09 '18 06:05 JohannesHoppe

Hi @JohannesHoppe Thank you , this configuration is working for me.

Tataraovoleti avatar May 09 '18 09:05 Tataraovoleti

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

mmenik avatar May 09 '18 10:05 mmenik

is ng test --single-run is equivalent to ng test now in angular6? I observed same behavior.

Tataraovoleti avatar May 09 '18 11:05 Tataraovoleti

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?

jordanpowell88 avatar May 15 '18 13:05 jordanpowell88

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 avatar May 17 '18 13:05 Gerros

@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)

antipalindrome avatar May 17 '18 16:05 antipalindrome

@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.

clydin avatar May 17 '18 16:05 clydin

--no-watch should also work (more elegant).

rkrisztian avatar May 24 '18 12:05 rkrisztian

I switch ng test --single-run to ng test --watch=false and it is works good.

pumano avatar May 28 '18 09:05 pumano

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..

chrillewoodz avatar Nov 02 '18 12:11 chrillewoodz

Same result in @angular/[email protected] and actually it looks like the test runs twice

marianocodes avatar Nov 27 '18 00:11 marianocodes