1

i have a problem, i don't think it's normal.

When i launch the command 'ng test --watch=false' with at least one test in error (wrong expect) the command quit with this error

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ulys-nav@0.0.1 test: `ng test --watch=false`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ulys-nav@0.0.1 test 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:
npm ERR!     /Users/martels3/.npm/_logs/2019-10-21T11_20_00_883Z-debug.log

But when i fix the test (correct expect), every is normal (without error).

Here is my karma.conf.js

const puppeteer = require('puppeteer');
process.env.CHROME_BIN = puppeteer.executablePath();

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
      jasmine: {
        random: false
      }
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../coverage'),
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome', 'ChromeHeadless'],
    customLaunchers: {
      ChromeHeadlessCI: {
        base: 'ChromeHeadless',
        flags: ['--no-sandbox', '--disable-gpu']
      }
    },
    singleRun: false,
    captureTimeout: 210000,
    browserDisconnectTolerance: 3,
    browserDisconnectTimeout: 210000,
    browserNoActivityTimeout: 210000
  });
};

Is it normal to have this horrible error? Because when i launch this command in the CI (bitRise), it quit because of this and i don't want to !

Stefan MARTEL
  • 61
  • 1
  • 10
  • I found why there is this error, it's because i call the command with 'npm run test' and not 'npm test'. With 'npm test', i have this error "npm ERR! Test failed. See above for more details". How can i avoid the npm ERR when i have one test which failed ? – Stefan MARTEL Oct 21 '19 at 13:05

1 Answers1

0

Maybe you still have the problem. I think I have the solution for you even if it's not the best one. The reason for this kind of problems is the configuration of the sourceMapproperty. If you search for the keyword in your project you will find it in angular.json and tsconfig.json

In angular.json is is set to false and in tsconfig.json it is true. While set to true the browser disconnects and the tests do not work. So the solution is to configure you command like this:

ng test --source-map=false --watch=false

For me this is the solution that helps because the sourceMap seems to be buggy. Related to this GitHub issue https://github.com/karma-runner/karma/issues/3267 and an explaination what sourceMaps are:

What will happen if sourcemap is set as false in Angular

CptDayDreamer
  • 1,526
  • 6
  • 25
  • 61