ERRORS & BUILD FAILURE: When executing tests with karma
See original GitHub issueWhen 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:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
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
--
afternpm 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:
If I do: ng test --karma-config karma.conf.js this error message occurs: