Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
HeavenlyHost opened this issue Jun 10, 2016 · 9 comments
Closed

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

HeavenlyHost opened this issue Jun 10, 2016 · 9 comments
Labels

Comments

@HeavenlyHost
Copy link

HeavenlyHost commented Jun 10, 2016

Can someone explain to me what I am doing wrong with the karma coverage. I am currently developing an angular 2 (RC1) service in typescript and want to not only run unit tests on it but also provide code coverage reports. If running the tests without the coverage reporter all is good and the tests are run. Unfortunately, when I include the coverage reporter karma bails with the following error...

10 06 2016 10:45:49.583:DEBUG [web-server]: serving (cached): D:/Git/@my-namespace/my-service/node_modules/rxjs/scheduler/FutureAction.js
Missing error handler on socket.
TypeError: (msg || "").replace is not a function
at D:\Git@my-namespace\my-service\node_modules\karma\lib\reporter.js:45:23

What I am doing is building typescript into a folder called dist and then exposing this to karma test and coverage

details are below...

... any ideas...?

Expected behavior

karma should run tests and create a coverage file

Actual behavior

10 06 2016 10:45:49.583:DEBUG [web-server]: serving (cached): D:/Git/@my-namespace/my-service/node_modules/rxjs/scheduler/FutureAction.js
Missing error handler on socket.
TypeError: (msg || "").replace is not a function
at D:\Git@my-namespace\my-service\node_modules\karma\lib\reporter.js:45:23

Enviroment Details

Typescript: 1.8.10
Karma version: 0.13.22
Karma coverage: 0.5.5

karma.config.js

module.exports = function(config) {

    // transpiled app JS files
    var appBase   = "dist/";

    // component assets fetched by Angular's compiler
    var appAssets ="/base/dist/";

    config.set({
        autoWatch: true,
        basePath: ".",
        browserNoActivityTimeout: 20000,
        browsers: ["Chrome"],
        colors: true,
        exclude: [
             "node_modules/**/*.spec.js"
        ],
        files: [
            // Standard libs
            "node_modules/systemjs/dist/system-polyfills.js",
            "node_modules/systemjs/dist/system.src.js",
            "node_modules/es6-shim/es6-shim.js",
            "node_modules/reflect-metadata/Reflect.js",
            "node_modules/zone.js/dist/zone.js",
            "node_modules/zone.js/dist/jasmine-patch.js",
            "node_modules/zone.js/dist/async-test.js",
            "node_modules/zone.js/dist/fake-async-test.js",

            // Standard libs with custom patterns
            {pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false},,
            {pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},

            // Custom shim
            "karma-test-shim.js",

            // Transpiled application & spec code paths loaded via module imports
            {pattern: 'dist/**/*.js', included: false, watched: true},
            {pattern: 'dist/**/*.js.map', included: false, watched: false}
        ],
        frameworks: ["jasmine"],
        logLevel: config.LOG_DEBUG,
        plugins: [
            "karma-jasmine",
            "karma-chrome-launcher",
            "karma-coverage"
        ],
        port: 9876,
        preprocessors: {
            // source files, that you wanna generate coverage for
            // do not include tests or libraries
            // (these files will be instrumented by Istanbul)      
            "dist/**/!(*spec).js": ["coverage"]
        },
        proxies: {
            // proxied base paths for loading assets
            // required for component assets fetched by Angular's compiler
            "/dist/": appAssets
        },
        reporters: ["progress", "dots", "coverage"],
        singleRun: true,
    });
 }
@kleijnweb
Copy link

I have tried switching to PhantomJS, exact same error.

@kleijnweb
Copy link

Not so sure it is a Karma (config) issue though, because this works:


import {
  beforeEachProviders,
  it,
  describe,
  expect,
  inject
} from '@angular/core/testing';

describe('Test', () => {

  it('True should be true', () => {
    expect(true).toBe(true);
  })
});

@kleijnweb
Copy link

In my case, I was doing stuff outside of a describe block. Problem solved (although that error could be a little more descriptive).

@HeavenlyHost
Copy link
Author

I am sorry but this is still not working and needs sorting, either this is a problem with Karma or with Coverage or Both. I will need a viable solution to this 😒 additionally I am building with SystemJS as module loader as this is the recommended way as per the Angular team.

@bryanrideshark
Copy link

I also am encountering this problem, also doing test loading via SystemJS

@chuckamus-prime
Copy link

Also having this issue, test loading via systemjs as well. angular 2 typescript. however with mine, didnt seem to matter if anything was outside the describe blocks.

@chuckamus-prime
Copy link

chuckamus-prime commented Jul 28, 2016

not sure if this is a fix for everyone, but we added "reflect-metadata": "0.1.2" as a package for node and it fixed it for us.

@mdocter
Copy link

mdocter commented Sep 13, 2016

I'm encountering the same in an Angular 2 CLI project. I first get the Missing error handler on 'socket'. message described in #1751 and than this one. If I clear the reporters: [...] array in the karma.conf.js file it's gone, but that shouldn't be necessary.

@wesleycho
Copy link
Member

I'm going to close this issue as this is a user problem - it should be noted that there is a starter with coverage all set up properly with https://github.com/preboot/angular2-webpack, primarily maintained by one of the developers on the Angular docs team, so clearly coverage works fine with karma and Angular 2, once one knows all of the important aspects about how Angular 2 works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants