karma-runner / karma-runner/karma
Karma with RequireJs - Hangs when using a module that using a directory path config
- Dominant language
- JavaScript
- Stars
- 12k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
I was able to pare down my entire karma setup to nothing more than the bare minimum to confirm what seems to cause the issue.
Issue:
When starting karma, I receive the following message: "[2015-05-16 20:32:54.432] [WARN] Chrome 42.0.2311 (Windows 7) - Disconnected (1 times), because no message in 10000 ms."
Observations:
I have configured a config called "logic", which maps to "app/_logic" directory. I have been able to isolate what causes karma to hang down to this directory mapping. I created a simple module called "fakie.js" that attempts to load "logic/fhir/enums" as a dependency. However, using the "logic" mapping causes Karma to hang and then quit, reporting nothing back besides the error. If I use the real path to the file "app/_logic/fhir/enums" then it will work as expected. The only conclusion I can draw from this is that somehow using these directory paths causes it to fail. Just curious if there is a workaround ... OTHER than using fully qualified paths. Our application is using directory mappings like this one all over the place to make the dependencies in our modules manageable ... so changing them to use qualified paths is out of the question.
Thanks in advance!
Project Directory Structure:
- root
- app
- _logic
- fhir
- enums.js
- lib
- test
- dev.karma.conf.js
- ut
- fakie.js
Relevant Code:
Here is my karma config:
``` javascript
module.exports = function(config) {
config.set({
basePath: '../',
frameworks: ['requirejs', 'jasmine'],
files: [
'test/ut/test-main.js',
{ pattern: 'test/ut/_logic/fhir/fakie.js', included: false },
{ pattern: 'app/_logic/fhir/enums.js', included: false },
],
exclude: [
],
preprocessors: {
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
loggers: [{ type: 'console' }],
autoWatch: false,
autoWatchInternval: 1000,
browsers: ['Chrome'],
singleRun: true
});
};
```
Here is my require.js bootstrap file:
``` javascript
var allTestFiles = [];
var TEST_REGEXP = /\.js$/i;
var Excluded = [
'require.js',
'adapter.js',
'jasmine.js',
'boot.js'
];
var pathToModule = function(path) {
return path.replace(/^\/base\//, '');
};
Object.keys(window.__karma__.files).forEach(function(file) {
var isExcluded = false;
//if it is in this list than it needs a fully qualified path including ".js", otherwise, it will be loaded via requireJS
Excluded.forEach(function(filename) {
if (file.indexOf(filename) > -1){
isExcluded = true;
return;
}
});
if (file.indexOf('.debug') > -1) {
//don't load a second time since .min versions are going to be loaded
}
else if (!isExcluded && TEST_REGEXP.test(file)) {
// Normalize paths to RequireJS module names.
allTestFiles.push(pathToModule(file).replace(/\.js$/, ''));
}
});
console.log(allTestFiles);
require.config({
baseUrl: '/base',
waitSeconds: 0,
paths: {
'logic': 'app/_logic'
},
deps: allTestFiles,
callback: function() {
console.log('...Starting Karma...');
window.__karma__.start();
console.log('...Karma Running...');
}
});
```
fakie.js:
``` javascript
define(['logic/fhir/enums'], function (Enums) {
console.log('Whiskey Tango Foxtrot!!!>>><<
Contributor guide
Research direction
Start with test/dev.karma.conf.js and the RequireJS bootstrap referenced by test/ut/test-main.js, then reproduce the hang using test/ut/_logic/fhir/fakie.js and app/_logic/fhir/enums.js. Compare the directory mapping for logic with the fully qualified module path; done means Karma completes the run without Chrome disconnecting while retaining the mapping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing-qa, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100