karma: sockets.forEach is not a function

Running karma 0.13.16 I encountered the following issue after the last test run successfully:

Missing error handler on `socket`.
TypeError: sockets.forEach is not a function
at disconnectBrowsers (/project-path/node_modules/karma/lib/server.js:314:13)
at [object Object].<anonymous> (/project-path/node_modules/karma/lib/server.js:291:7)
at emitTwo (events.js:92:20)
at [object Object].emit (events.js:172:7)
at emitRunCompleteIfAllBrowsersDone (/project-path/node_modules/karma/lib/server.js:256:12)
at [object Object].<anonymous> (/project-path/node_modules/karma/lib/server.js:278:9)
at emitTwo (events.js:92:20)
at [object Object].emit (events.js:172:7)
at [object Object].onComplete (/project-path/node_modules/karma/lib/browser.js:142:13)
at Socket.<anonymous> (/project-path/node_modules/karma/lib/events.js:13:22)
at emitTwo (events.js:92:20)
at Socket.emit (events.js:172:7)
at Socket.onevent (/project-path/node_modules/socket.io/lib/socket.js:335:8)
at Socket.onpacket (/project-path/node_modules/socket.io/lib/socket.js:295:12)
at Client.ondecoded (/project-path/node_modules/socket.io/lib/client.js:193:14)
at Decoder.Emitter.emit (/project-path/node_modules/component-emitter/index.js:134:20)
at Decoder.add (/project-path/node_modules/socket.io-parser/index.js:247:12)
at Client.ondata (/project-path/node_modules/socket.io/lib/client.js:175:18)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at Socket.onPacket (/project-path/node_modules/engine.io/lib/socket.js:101:14)
at emitOne (events.js:77:13)
at WebSocket.emit (events.js:169:7)
at WebSocket.Transport.onPacket (/project-path/node_modules/engine.io/lib/transport.js:93:8)
at WebSocket.Transport.onData (/project-path/node_modules/engine.io/lib/transport.js:104:8)
at WebSocket.onData (/project-path/node_modules/engine.io/lib/transports/websocket.js:76:30)
at emitTwo (events.js:87:13)
at WebSocket.emit (events.js:172:7)
at Receiver.ontext (/project-path/node_modules/ws/lib/WebSocket.js:816:10)
at Receiver.parse (/project-path/node_modules/ws/lib/Receiver.hixie.js:145:8)
at doAdd (/project-path/node_modules/ws/lib/Receiver.hixie.js:104:19)
at Receiver.add (/project-path/node_modules/ws/lib/Receiver.hixie.js:108:22)
at Socket.realHandler (/project-path/node_modules/ws/lib/WebSocket.js:800:20)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at TCP.onread (net.js:523:20)

05 01 2016 23:59:46.725:WARN [PhantomJS 1.9.8 (Linux 0.0.0)]: Disconnected (1 times), because no message in 10000 ms.
JS 1.9.8 (Linux 0.0.0): Executed 42 of 42 DISCONNECTED (10.248 secs / 0.329 secs)
05 01 2016 23:59:46.726:ERROR [karma]: [TypeError: sockets.forEach is not a function]
TypeError: sockets.forEach is not a function
at disconnectBrowsers (/project-path/node_modules/karma/lib/server.js:314:13)
at [object Object].<anonymous> (/project-path/node_modules/karma/lib/server.js:291:7)
at emitTwo (events.js:92:20)
at [object Object].emit (events.js:172:7)
at emitRunCompleteIfAllBrowsersDone (/project-path/node_modules/karma/lib/server.js:256:12)
at [object Object].<anonymous> (/project-path/node_modules/karma/lib/server.js:278:9)
at emitOne (events.js:82:20)
at [object Object].emit (events.js:169:7)
at [object Object]._onTimeout (/project-path/node_modules/karma/lib/browser.js:50:15)
at Timer.listOnTimeout (timers.js:92:15)

/project-path/node_modules/karma/lib/server.js:314
sockets.forEach(function (socket) {
^

TypeError: sockets.forEach is not a function
at disconnectBrowsers (/project-path/node_modules/karma/lib/server.js:314:13)
at process.<anonymous> (/project-path/node_modules/karma/lib/server.js:355:5)
at emitOne (events.js:77:13)
at process.emit (events.js:169:7)
at process._fatalException (node.js:234:26)

I didn’t make any changes to the code or to the test itself but reinstalled the node_modules.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 37 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I succeed!!! I input ‘npm install socket.io@1.3.5 --save’ in command and it is work~

Just published 0.13.19 which fixes this.

Yep I’m seeing it once again too.

I seem to still have this problem with the latest version of Karma:

10 03 2016 17:07:39.954:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
10 03 2016 17:07:39.959:INFO [launcher]: Starting browser PhantomJS
10 03 2016 17:07:40.751:INFO [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Connected on socket /#whtCZIqgWvlZk5nVAAAA with id 56004832
[snip]
PhantomJS 1.9.8 (Mac OS X 0.0.0): Executed 61 of 862 (4 FAILED) ERROR (0.458 secs / 0.519 secs)
Missing error handler on `socket`.
TypeError: Cannot read property 'charAt' of undefined
    at posix (/project/node_modules/karma-junit-reporter/node_modules/path-is-absolute/index.js:4:13)
    at writeXmlForBrowser (/project/node_modules/karma-junit-reporter/index.js:61:9)
    at onBrowserComplete (/project/node_modules/karma-junit-reporter/index.js:126:5)
    at null.<anonymous> (/project/node_modules/karma/lib/events.js:13:22)
    at emitTwo (events.js:92:20)
    at emit (events.js:172:7)
    at onComplete (/project/node_modules/karma/lib/browser.js:142:13)
    at Socket.<anonymous> (/project/node_modules/karma/lib/events.js:13:22)
    at emitTwo (events.js:92:20)
    at Socket.emit (events.js:172:7)
    at Socket.onevent (/project/node_modules/karma/node_modules/socket.io/lib/socket.js:335:8)
    at Socket.onpacket (/project/node_modules/karma/node_modules/socket.io/lib/socket.js:295:12)
    at Client.ondecoded (/project/node_modules/karma/node_modules/socket.io/lib/client.js:193:14)
    at Decoder.Emitter.emit (/project/node_modules/karma/node_modules/socket.io/node_modules/socket.io-parser/node_modules/component-emitter/index.js:134:20)
    at Decoder.add (/project/node_modules/karma/node_modules/socket.io/node_modules/socket.io-parser/index.js:247:12)
    at Client.ondata (/project/node_modules/karma/node_modules/socket.io/lib/client.js:175:18)
10 03 2016 17:07:41.710:WARN [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Disconnected (1 times)
PhantomJS 1.9.8 (Mac OS X 0.0.0): Executed 61 of 862 (4 FAILED) DISCONNECTED (10.462 secs / 0.519 secs)
10 03 2016 17:07:51.712:ERROR [karma]: [TypeError: Cannot read property 'charAt' of undefined]
TypeError: Cannot read property 'charAt' of undefined
    at posix (/project/node_modules/karma-junit-reporter/node_modules/path-is-absolute/index.js:4:13)
    at writeXmlForBrowser (/project/node_modules/karma-junit-reporter/index.js:61:9)
    at onBrowserComplete (/project/node_modules/karma-junit-reporter/index.js:126:5)
    at null.<anonymous> (/project/node_modules/karma/lib/events.js:13:22)
    at emitOne (events.js:82:20)
    at emit (events.js:169:7)
    at null._onTimeout (/project/node_modules/karma/lib/browser.js:50:15)
    at Timer.listOnTimeout (timers.js:92:15)

Any idea what it could be? Tried downgrading to .19, but I had the same problem.

This is due to socket.io bumping to 1.4.0. 1.3.7 worked just fine. We are having this problem too and it is causing our CI to fail.