Karma tests pass in watch mode, but fail when --single-run flag is passed

时间:2016-07-11 21:11:23

标签: javascript node.js karma-runner browserify karma-mocha

I'm trying to update a Node.js library to also work in browsers. I have a large number of tests that all work as expected in Node.js but are giving me a number of issues when I try to run them in a browser (via Karma & Browserify). One particular issue I've encountered is that certain files will pass when karma is left in "watch" mode, but fail in "single run" mode:

Watch mode:

~/node-sdk (browser) $ karma start
11 07 2016 16:55:59.122:INFO [framework.browserify]: registering rebuild (autoWatch=true)
11 07 2016 16:56:11.595:INFO [framework.browserify]: 9423226 bytes written (11.72 seconds)
11 07 2016 16:56:11.711:INFO [framework.browserify]: bundle built
11 07 2016 16:56:11.732:WARN [karma]: No captured browser, open http://localhost:9876/
11 07 2016 16:56:11.741:INFO [karma]: Karma v1.1.1 server started at http://localhost:9876/
11 07 2016 16:56:11.741:INFO [launcher]: Launching browsers Chrome, Firefox with unlimited concurrency
11 07 2016 16:56:11.748:INFO [launcher]: Starting browser Chrome
11 07 2016 16:56:11.758:INFO [launcher]: Starting browser Firefox
11 07 2016 16:56:13.959:INFO [Chrome 51.0.2704 (Mac OS X 10.11.5)]: Connected on socket /#8p3Hx9wFfm_gMYyEAAAA with id 2615838
11 07 2016 16:56:15.449:INFO [Firefox 47.0.0 (Mac OS X 10.11.0)]: Connected on socket /#f6SIfND_MvqYDOzbAAAB with id 65572400
Firefox 47.0.0 (Mac OS X 10.11.0): Executed 2 of 2 SUCCESS (0.047 secs / 0.01 secs)
Chrome 51.0.2704 (Mac OS X 10.11.5): Executed 2 of 2 SUCCESS (0.03 secs / 0.017 secs)
TOTAL: 4 SUCCESS

Single-run mode:

~/node-sdk (browser) $ karma start --single-run
11 07 2016 16:55:36.294:INFO [framework.browserify]: bundle built
11 07 2016 16:55:36.323:INFO [karma]: Karma v1.1.1 server started at http://localhost:9876/
11 07 2016 16:55:36.325:INFO [launcher]: Launching browsers Chrome, Firefox with unlimited concurrency
11 07 2016 16:55:36.334:INFO [launcher]: Starting browser Chrome
11 07 2016 16:55:36.345:INFO [launcher]: Starting browser Firefox
11 07 2016 16:55:38.562:INFO [Chrome 51.0.2704 (Mac OS X 10.11.5)]: Connected on socket /#PwrOhxXF9cdzx-0UAAAA with id 34820387
Chrome 51.0.2704 (Mac OS X 10.11.5) ERROR
  Uncaught TypeError: self.req.on is not a function
  at /var/folders/95/_6btw8d94sq2b91k8j794zpm0000gn/T/node_modules/request/request.js:798:0 <- /var/folders/95/_6btw8d94sq2b91k8j794zpm0000gn/T/05a75ef7d31df884a8d5b5e1cec33ffd.browserify:53193
Chrome 51.0.2704 (Mac OS X 10.11.5): Executed 2 of 2 ERROR (0.043 secs / 0.025 secs)
11 07 2016 16:55:40.672:INFO [Firefox 47.0.0 (Mac OS X 10.11.0)]: Connected on socket /Chrome 51.0.2704 (Mac OS X 10.11.5): Executed 2 of 2 ERROR (0.043 secs / 0.025 secs)
Firefox 47.0.0 (Mac OS X 10.11.0): Executed 2 of 2 SUCCESS (0.084 secs / 0.012 secs)

Does anyone have any idea what could cause that?

Here's my full code: https://github.com/watson-developer-cloud/node-sdk/tree/2b31b5d74f5e471729bf45dab70ef5428f9ab711

Here's the one test file it's currently running (although several others seem to have the same error): https://github.com/watson-developer-cloud/node-sdk/blob/2b31b5d74f5e471729bf45dab70ef5428f9ab711/test/test.alchemy_data_news.v1.js

Here's the particular line that it's reporting an error from (I doubt this is the actual source of the issue, but it's all I'm getting from the logs): https://github.com/request/request/blob/v2.72.0/request.js#L798

Update: It seems to require multiple browsers to trigger. If I run the tests in only firefox or chrome, they pass in single-run mode also. Still not sure what the root cause is though.

Update 2: Running with a single browser does better, and some of my individual tests pass, but other test files give me errors like this:

12 07 2016 10:03:12.702:ERROR [framework.browserify]: TypeError: Cannot read property 'apply' of undefined while parsing file: /Users/nfriedly/node-sdk/test/test.visual_recognition.v3.js

What does that mean? If I manually browserify the file, it works fine, as does running it in node.js (with mocha). I think it may only occur in files that use fs.read* (via brfs).

0 个答案:

没有答案