question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ERRORS & BUILD FAILURE: When executing tests with karma

See original GitHub issue

When I run mvn install within an Angular project, I get the following error messages when executing the unit tests:

[INFO] — frontend-maven-plugin:1.7.6:karma (run tests) @ test-ui — [INFO] Running ‘karma start karma.conf.ci.js’ in /Users/codehan/Documents/projects/test-ui [ERROR] [ERROR] /Users/codehan/Documents/projects/test-ui/node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/karma.ts:62 [ERROR] throw new Error(The '@angular-devkit/build-angular/plugins/karma' karma plugin is meant to + [ERROR] ^ [ERROR] Error: The ‘@angular-devkit/build-angular/plugins/karma’ karma plugin is meant to be used from within Angular CLI and will not work correctly outside of it.

And some lines below

[INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 24.666 s [INFO] Finished at: 2019-05-21T14:31:09+02:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.7.6:karma (run tests) on project test-ui: Failed to run task: ‘karma start karma.conf.ci.js’ failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

I use the frontend-maven-plugin in the version 1.7.6 and have it inserted like this in my pom.xml.

  <build>
    <plugins>
      <!-- Frontend plugin -->
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>1.7.6</version>
        <configuration>
          <nodeVersion>v11.10.0</nodeVersion>
        </configuration>
        <executions>
        ...

My karma.conf.js looks like this:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma'),
      require('karma-chrome-launcher'),
      require('karma-phantomjs-launcher')
    ],
    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'],
    phantomjsLauncher: {
      // Have phantomjs exit if a ResourceError is encountered (useful if karma
      // exits without killing phantom)
      exitOnResourceError: true
    },    
    singleRun: false
  });
};

My karma.conf.ci.js like this:

var baseConfig = require('./karma.conf.js');

module.exports = function (config) {
  baseConfig(config);
  config.set({
    plugins: [
      require('karma-jasmine'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma'),
      require('karma-chrome-launcher')
    ],
    browsers: ['Chrome'],
    singleRun: true
  });
};

I use the following versions of the packages:

Angular: “@ angular-devkit / build-angular”: “^0.12.4”, “@angular / cli”: “^7.3.9”, “@angle / compiler-cli”: “7.2.0”, “@angular / core”: “7.2.0”, “@ angular-devkit / architect”: “^0.13.9”, “@ angular-devkit / build-optimizer”: “^0.13.9”, “@ angular-devkit / build-webpack”: “^0.13.9”, “@ angular-devkit / core”: “^7.3.9”,

Karma “karma”: “^1.7.1”, “karma-chrome-launcher”: “~2.1.1”, “karma-cli”: “~1.0.1”, “karma-coverage-istanbul-reporter”: “^1.4.3”, “karma-firefox-launcher”: “^1.0.1”, “karma-jasmine”: “^1.1.2”, “karma-jasmine-html-reporter”: “^0.2.2”, “karma-phantomjs-launcher”: “^1.0.4”, “karma mocha reporter”: “^2.2.5”, “karma-webpack”: “^3.0.5”,

Jasmine “@ types / jasmine”: “2.5.45”, “jasmine-core”: “^2.99.1”, “jasmine-spec-reporter”: “~4.1.0”,

Java Java version: 1.8.0_201

Maven Apache Maven 3.6.1

Operating system MacOS Mojave (Version 10.14.5)

IDE Visual Studio Code

What am I doing wrong?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
imtiazShakilcommented, Jun 23, 2019

The new angular Client needs project name if you override the default karma configuration. so you’ve to run test like this:

ng test my-app --karma-config karma.conf.ci.js

So to run the same command using npm we would need command like this: npm test -- my-app --karma-config karma.conf.ci.js

[Notice: I added -- after npm test command, because it allows us to include package specific arguments (here it is --karma-config) ]

Finally to sum it up, here is the updated pom:

<execution>
    <id>run karma tests</id>
    <goals>
        <goal>npm</goal>
    </goals>
    <phase>test</phase>

    <configuration>
    	<arguments>test -- my-app --karma-config karma.conf.ci.js</arguments>
    </configuration>
</execution>
1reaction
codehan-decommented, May 22, 2019

Maybe this works: angular/angular-cli#10703 (comment)

If I do: ng test --karma-config karma.conf.js this error message occurs:

[ERROR] Project ‘karma.conf.js’ does not support the ‘test’ target. [ERROR] Error: Project ‘karma.conf.js’ does not support the ‘test’ target.

          <execution>
            <id>test</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run test --karma-config karma.conf.js</arguments>
            </configuration>
          </execution>
Read more comments on GitHub >

github_iconTop Results From Across the Web

ERRORS & BUILD FAILURE: When executing tests with karma
This is the cause of error: Running 'karma start karma.conf.ci.js . This can't be done in that way. Up to Angular 5 it...
Read more >
Maven build won't fail when karma test fails #613 - GitHub
The failed karma test is recognized during the build but it doesn't lead to a maven build failure. [INFO] [INFO] Running 'karma start...
Read more >
Karma is running with 0 tests, and it fails the build
Yes, that's by design. Executing 0 tests is a failure. We had issues before when somebody would accidentally disable all tests and the...
Read more >
Troubleshooting - Karma test runner
I'm getting a weird error from the browser, how can I debug it? # ... Go to the captured browser and click the...
Read more >
Angular-Karma-Test-Explorer/Bugs - Gitter
When is run the command with the same parameters this result in an error: ... at c:\Users\«someUser».vscode\extensions\raagh.angular-karma-test-explorer-1.2 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found