业力:移动文件夹 - >套接字上缺少错误处理程序?

时间:2016-03-12 01:38:40

标签: javascript node.js socket.io angular karma-runner

我为Karma 0.13.22运行的Angular 2.0项目提供了一组有效的单元测试,连接到带有Socket.io 1.4.5的Chrome 48浏览器。我正在这个配置下进行测试,该工作正常:

app/
tests/app
karma-test-shim.js
karma.conf.js

然后,在不更改任何代码的情况下,我移动了一个文件夹:

source/app/
tests/app
karma-test-shim.js
karma.conf.js

...然后我使用新路径更新了karma-test-shim.jskarma.conf.js

现在测试甚至都没有运行,我收到了这个错误:

Missing error handler on `socket`.
TypeError: (msg || "").replace is not a function
  at /home/spryno724/projects/portfolio/node_modules/karma/lib/reporter.js:45:23
  at onBrowserError (/home/spryno724/projects/portfolio/node_modules/karma/lib/reporters/base.js:58:60)
  ... more stack trace ...

11 03 2016 20:24:11.038:WARN [Chrome 48.0.2564 (Windows 10 0.0.0)]: Disconnected (1 times)

知道造成这种情况的原因是什么? 唯一更改的是文件夹路径。

来自karma.conf.js 的示例:

files: [
  // Load Angular 2 dependencies and the SystemJS shim
  { pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: true },
  { pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true },
  { pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: true },
  { pattern: 'node_modules/angular2/bundles/angular2.dev.js', included: true, watched: true },
  { pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: true },
  { pattern: 'karma-test-shim.js', included: true, watched: true },

  // The application and test files
  { pattern: 'source/app/**/*.js', included: false, watched: false },
  { pattern: 'test/unit/app/**/*.js', included: false, watched: false },

  // Support for debugging sessions
  { pattern: 'source/app/**/*.ts', included: false, watched: false },
  { pattern: 'test/unit/app/**/*.js.map', included: false, watched: false }
]

1 个答案:

答案 0 :(得分:0)

请参阅https://github.com/oliver-spryn/portfolio

上的项目

您可以尝试更改您的karma-test-shim.js。在System.config下,更改格式:'注册'格式化:' cjs'。

我复制了你的karma.conf.js + karma-test-shim.js并创建了一个简单的项目来模拟你遇到的问题(修复如上)。 https://github.com/phhoangbao/angular2-test