Reputation: 814
I have trying many many configurations unsuccessfully. The one detailed below, throws an error when I am executing karma start
.
arma plugin is meant to be used from within Angular CLI and will not work correctly outside of it
At project level I have this karma.config.js
module.exports = require('./src/karma.conf.js');
that is pointing to this configuration:
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-electron'),
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
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['AngularElectron'],
singleRun: true,
customLaunchers: {
AngularElectron: {
base: 'Electron',
browserWindowOptions: {
webPreferences: {
nodeIntegration: true,
allowRunningInsecureContent: true
}
}
}
},
client: {
useIframe: false
}
});
};
My package.json is visible from https://github.com/twolfson/karma-electron/issues/43
What should I change?
Thanks for your help
Upvotes: 0
Views: 732
Reputation: 11
I checked out the issue on GH, and your immediate problem is that you need to use ng test
, but there's another key detail not covered by the docs that you might need to know to get karma-electron working with the Angular/Jasmine stack (I just worked this out):
The var fs = require('fs')
in electron's index.js will fail to resolve without a custom webpack.config.js
a. run an npm i @angular-builders/custom-webpack -D
b. In your angular.json, modify your test project:
"test": {
"builder": "@angular-builders/custom-webpack:karma",
"options": {
...
"customWebpackConfig": {
"path": "./webpack.config.js"
}
}
}
c. Add a webpack.config.js at the project root with this inside:
module.exports = {
target: 'electron-renderer'
};
This will enable require functionality.
Upvotes: 1