简体   繁体   English

Karma不会运行(socket.io抛出错误)

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

I have an Angular 2 project, written in Typescript. 我有一个Angular 2项目,用Typescript编写。 I am trying to get Travis CI set up. 我想让Travis CI成立。 Unfortunately, I am getting an error thrown from Karma: 不幸的是,我收到了来自Karma的错误:

Missing error handler on socket . socket上缺少错误处理程序。

TypeError: (msg || "").replace is not a function TypeError:(msg ||“”).replace不是函数

Expected behavior 预期的行为

My Travis CI build to complete the Jasmine Unit tests defined, reporting the number run and success vs. failure. 我的Travis CI构建完成了定义的Jasmine Unit测试,报告了运行次数和成功与失败。

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. 此外, 是正在构建的完整github存储库。

[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 节点v5.10.0

Angular 2.0.0-beta.12 Angular 2.0.0-beta.12

├── karma@0.13.22 
├── karma-chrome-launcher@0.1.12 
├── karma-coverage@0.2.7 
├── karma-firefox-launcher@0.1.7 
├── karma-ie-launcher@0.1.5 
├── karma-jasmine@0.3.8 
├── karma-ng-html2js-preprocessor@0.1.2 
├── karma-opera-launcher@0.1.0 
├── karma-phantomjs-launcher@0.1.4

Any ideas what may be causing this, or what info you might need to debug this? 可能导致此问题的任何想法,或者您可能需要调试此信息的信息?

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. 99%的时间与应用程序引用的karma.conf.js文件数组中不包含文件有关。

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: 这是我的karma-test-shim.js ,我将文件名转换为模块名称:

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. 作为Angular 2团队的开发人员,Julie Ralph有一个种子项目 ,用于为Angular 2项目设置业力测试,我发现在创建业力垫片时非常有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM