I'm currently facing an issue with running my Jasmine tests using Karma. Any help or suggestions would be greatly appreciated.
When I try to run the tests with Karma (using "karma start --singleRun=true"), the browser opens but nothing happens and eventually, Karma times out with the following error:
26 06 2019 14:40:24.431:INFO [karma]: Delaying execution, these browsers are not ready: Chrome 75.0.3770 (Windows 10.0.0)
26 06 2019 14:42:01.326:WARN [Chrome 75.0.3770 (Windows 10.0.0)]: Disconnected (0 times), because no message in 160000 ms.
26 06 2019 14:42:01.327:DEBUG [Chrome 75.0.3770 (Windows 10.0.0)]: CONFIGURING -> DISCONNECTED
Chrome 75.0.3770 (Windows 10.0.0) ERROR
Disconnected, because no message in 160000 ms.
26 06 2019 14:42:01.330:DEBUG [launcher]: CAPTURED -> BEING_KILLED
26 06 2019 14:42:01.332:DEBUG [launcher]: BEING_KILLED -> BEING_FORCE_KILLED
26 06 2019 14:42:01.333:WARN [karma]: No captured browser, open http://localhost:9876/
Chrome 75.0.3770 (Windows 10.0.0): Executed 0 of 0 DISCONNECTED (2 mins 40.011 secs / 0 secs)
If I try running the tests with "--singleRun=false" and set breakpoints in my test code, then run "karma run karma.conf.js" from a new command prompt, I observed that breakpoints inside the implementation callbacks for my tests are never hit. Other breakpoints work fine.
For example, if I have the following test:
describe(">String Utils", function() {
it("should be able to lower case a string",function() {
expect(utils.toLowerCase).toBeDefined();
expect(utils.toLowerCase("HELLO WORLD")).toEqual("hello world");
});
});
A breakpoint on the "describe" or "it" functions gets hit, but the breakpoints on the "expect" statements do not get hit.
I've checked for errors while setting up the jasmine spec inside the "it" functions, but everything seems okay. However, Karma never calls the implementation callbacks and the browser remains idle continuously.
You can find my karma.conf.js, spec-bundle.js, and webpack configuration below.
For more details or if you'd like to see additional information, you can visit my GitHub repository: https://github.com/webgirlwonder/karma-jasmine-test
// Karma configuration
// Generated on Fri May 17 2019 10:37:04 GMT-0500 (Central Daylight Time)
var webpackConfig = require('./webpack.config.js');
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine','requirejs'],
files: [
'spec-bundle.js'
],
exclude: [],
preprocessors: {
'spec-bundle.js': ['webpack' ]
},
webpack: webpackConfig,
reporters: ['spec'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
browsers: ['Chrome'],
concurrency: Infinity,
captureTimeout: 160000,
browserNoActivityTimeout: 160000,
})
}
spec-bundle.js
/*
* Create a context for all tests files below the src folder and all sub-folders.
*/
const context = require.context('./spec/', true, /\Spec\.js$/);
/*
* For each file, call the context function that will require the file and load it up here.
*/
context.keys().forEach(context);
webpack
const config = {
"mode": "development",
"entry": "./spec/MyJSUtilities.spec.js",
"target": "node",
"output": {
"path": __dirname+'/static',
"filename": "[name].[chunkhash:8].js"
}
}
module.exports = config;