Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karma won't run (socket.io throwing error)

I have an Angular 2 project, written in Typescript. I am trying to get Travis CI set up. Unfortunately, I am getting an error thrown from Karma:

Missing error handler on socket.

TypeError: (msg || "").replace is not a function

Expected behavior

My Travis CI build to complete the Jasmine Unit tests defined, reporting the number run and success vs. failure.

Actual behavior

This is the output from my build log. Here is the full build log. Also, here is the full github repository that was being built.

[09:39:04] Starting 'client.unit_test'...
05 04 2016 09:39:04.281:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
05 04 2016 09:39:04.287:INFO [launcher]: Starting browser Chrome
05 04 2016 09:39:05.519:INFO [Chrome 49.0.2623 (Linux 0.0.0)]: Connected on socket /#7wcOJ3uFvZX-HgZeAAAA with id 49035067
Missing error handler on `socket`.
TypeError: (msg || "").replace is not a function
  at /home/travis/build/georgeedwards/Gen-App/node_modules/karma/lib/reporter.js:45:23
  at [object Object].onBrowserError (/home/travis/build/georgeedwards/Gen-App/node_modules/karma/lib/reporters/base.js:58:60)

Enviroment Details

Node v5.10.0

Angular 2.0.0-beta.12

├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected] 
├── [email protected]

Any ideas what may be causing this, or what info you might need to debug this?

like image 821
George Edwards Avatar asked Oct 30 '22 06:10

George Edwards


1 Answers

I have seen issues similar to this in the past. 99% of the time this is related to not including a file in the karma.conf.js files array that is reference by the app.

Another likely issue is that module names are not correctly being translated from their respective file ref names.

Here is a snippet from my karma-test-shim.js where I translate my file names to module names:

System.config({
    packages: {
        'base/wwwroot/app': {
            defaultExtension: false,
            format: 'register',
            map: Object.keys(window.__karma__.files).
                  filter(function onlyAppFiles(filePath) {
                      return /^\/base\/wwwroot\/app\/.*\.js$/.test(filePath)
                  }).
                  reduce(function createPathRecords(pathsMapping, appPath) {
                      // creates local module name mapping to global path with karma's fingerprint in path, e.g.:
                      var moduleName = appPath.replace(/^\/base\/wwwroot\/app\//, './').replace(/\.js$/, '');
                      pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath];
                      return pathsMapping;
                  }, {})
        }
    }
});

The structure of my project is:

/
 karma.conf.js
 karma-test-shim.js
 wwwroot/
         app/
             //Angular 2 project and spec files

Julie Ralph, a dev on the Angular 2 team, has a seed project for setting up karma tests for an Angular 2 project which I found to be very helpful when creating the karma shim.

like image 179
Teddy Sterne Avatar answered Nov 15 '22 07:11

Teddy Sterne