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

Tests fail with latest version of Mocha #3710

Closed
1 of 2 tasks
Download opened this issue Nov 25, 2020 · 2 comments
Closed
1 of 2 tasks

Tests fail with latest version of Mocha #3710

Download opened this issue Nov 25, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@Download
Copy link
Contributor

Download commented Nov 25, 2020

You want to:

  • report a bug
  • request a feature

Current behaviour

When running the tests under the latest version of Mocha, some of them fail.

Steps to reproduce (if the current behavior is a bug)

  • Git clone this repo
  • npm install
  • Observe that vulnerabilities are mentioned; these vulnerabilities come from Mocha
  • npm outdated to show the list of outdated dependencies
  • Update all dependencies except for Mocha and Prettier to their latest versions (see Update most dependencies #3711)
  • npm test
  • Observe: all tests succeed
  • npm uninstall --save-dev mocha && npm install --save-dev mocha
  • npm test
  • Observe: some tests fail
C:\ws\socketio>npm outdated
Package   Current  Wanted  Latest  Location
mocha       3.5.3   3.5.3   8.2.1  socket.io
prettier   1.19.1  1.19.1   2.2.0  socket.io

C:\ws\socketio>npm uninstall --save-dev mocha && npm install --save-dev mocha
removed 24 packages and audited 303 packages in 2.142s

21 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ mocha@8.2.1
added 57 packages from 31 contributors and audited 361 packages in 6.574s

31 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities


C:\ws\socketio>npm test

> socket.io@3.0.3 test C:\ws\socketio
> npm run format:check && npm run compile && nyc mocha --require ts-node/register --reporter spec --slow 200 --bail --timeout 10000 test/socket.io.ts


> socket.io@3.0.3 format:check C:\ws\socketio
> prettier --check "lib/**/*.ts" "test/**/*.ts"

Checking formatting...
All matched files use Prettier code style!

> socket.io@3.0.3 compile C:\ws\socketio
> rimraf ./dist && tsc



  socket.io
    √ should be the same version as client
    server attachment
      http.Server
        √ should serve client
        √ should serve source map
        √ should serve client (min)
        √ should serve source map (min)
        √ should serve client (gzip)
        √ should serve bundle with msgpack parser
        √ should serve source map for bundle with msgpack parser
        √ should handle 304
        √ should not serve static files
        √ should work with #attach
        √ should work with #attach (and merge options)
      port
        √ should be bound
        √ should be bound as a string
        √ with listen
        √ as a string
    handshake
      √ should send the Access-Control-Allow-xxx headers on OPTIONS request
      √ should send the Access-Control-Allow-xxx headers on GET request
      √ should allow request if custom function in opts.allowRequest returns true
      √ should disallow request if custom function in opts.allowRequest returns false
    close
      √ should be able to close sio sending a srv
      √ should be able to close sio sending a port
      1) should be able to close sio sending a port


  22 passing (433ms)
  1 failing

  1) socket.io
       close
         should be able to close sio sending a port:
     Uncaught TypeError: Cannot read property 'sockets' of undefined
      at Socket.clientSocket.on (test\socket.io.ts:292:43)
      at Socket.Emitter.emit (node_modules\component-emitter\index.js:145:20)
      at Socket.onconnect (node_modules\socket.io-client\build\socket.js:291:15)
      at Socket.onpacket (node_modules\socket.io-client\build\socket.js:190:22)
      at Manager.<anonymous> (node_modules\component-bind\index.js:21:15)
      at Manager.Emitter.emit (node_modules\component-emitter\index.js:145:20)
      at Manager.ondecoded (node_modules\socket.io-client\build\manager.js:209:15)
      at Decoder.<anonymous> (node_modules\component-bind\index.js:21:15)
      at Decoder.Emitter.emit (node_modules\component-emitter\index.js:145:20)
      at Decoder.add (node_modules\socket.io-parser\dist\index.js:117:23)
      at Manager.ondata (node_modules\socket.io-client\build\manager.js:201:22)
      at Socket.<anonymous> (node_modules\component-bind\index.js:21:15)
      at Socket.Emitter.emit (node_modules\component-emitter\index.js:145:20)
      at Socket.onPacket (node_modules\engine.io-client\lib\socket.js:388:16)
      at XHR.<anonymous> (node_modules\engine.io-client\lib\socket.js:197:14)
      at XHR.Emitter.emit (node_modules\component-emitter\index.js:145:20)
      at XHR.onPacket (node_modules\engine.io-client\lib\transport.js:103:10)
      at callback (node_modules\engine.io-client\lib\transports\polling.js:101:12)
      at Array.forEach (<anonymous>)
      at XHR.onData (node_modules\engine.io-client\lib\transports\polling.js:105:56)
      at Request.<anonymous> (node_modules\engine.io-client\lib\transports\polling-xhr.js:95:12)
      at Request.Emitter.emit (node_modules\component-emitter\index.js:145:20)
      at Request.onData (node_modules\engine.io-client\lib\transports\polling-xhr.js:236:10)
      at Request.onLoad (node_modules\engine.io-client\lib\transports\polling-xhr.js:287:12)
      at XMLHttpRequest.xhr.onreadystatechange (node_modules\engine.io-client\lib\transports\polling-xhr.js:191:18)
      at XMLHttpRequest.dispatchEvent (node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:622:25)
      at setState (node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:641:14)
      at IncomingMessage.<anonymous> (node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:480:13)
      at endReadableNT (_stream_readable.js:1145:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



C:\ws\socketio\node_modules\mocha\lib\runner.js:962
    throw err;
    ^

TypeError: Cannot read property 'sockets' of undefined
    at Socket.clientSocket.on (C:\ws\socketio\test\socket.io.ts:318:43)
    at Socket.Emitter.emit (C:\ws\socketio\node_modules\component-emitter\index.js:145:20)
    at Socket.onconnect (C:\ws\socketio\node_modules\socket.io-client\build\socket.js:291:15)
    at Socket.onpacket (C:\ws\socketio\node_modules\socket.io-client\build\socket.js:190:22)
    at Manager.<anonymous> (C:\ws\socketio\node_modules\component-bind\index.js:21:15)
    at Manager.Emitter.emit (C:\ws\socketio\node_modules\component-emitter\index.js:145:20)
    at Manager.ondecoded (C:\ws\socketio\node_modules\socket.io-client\build\manager.js:209:15)
    at Decoder.<anonymous> (C:\ws\socketio\node_modules\component-bind\index.js:21:15)
    at Decoder.Emitter.emit (C:\ws\socketio\node_modules\component-emitter\index.js:145:20)
    at Decoder.add (C:\ws\socketio\node_modules\socket.io-parser\dist\index.js:117:23)
    at Manager.ondata (C:\ws\socketio\node_modules\socket.io-client\build\manager.js:201:22)
    at Socket.<anonymous> (C:\ws\socketio\node_modules\component-bind\index.js:21:15)
    at Socket.Emitter.emit (C:\ws\socketio\node_modules\component-emitter\index.js:145:20)
    at Socket.onPacket (C:\ws\socketio\node_modules\engine.io-client\lib\socket.js:388:16)
    at XHR.<anonymous> (C:\ws\socketio\node_modules\engine.io-client\lib\socket.js:197:14)
    at XHR.Emitter.emit (C:\ws\socketio\node_modules\component-emitter\index.js:145:20)
    at XHR.onPacket (C:\ws\socketio\node_modules\engine.io-client\lib\transport.js:103:10)
    at callback (C:\ws\socketio\node_modules\engine.io-client\lib\transports\polling.js:101:12)
    at Array.forEach (<anonymous>)
    at XHR.onData (C:\ws\socketio\node_modules\engine.io-client\lib\transports\polling.js:105:56)
    at Request.<anonymous> (C:\ws\socketio\node_modules\engine.io-client\lib\transports\polling-xhr.js:95:12)
    at Request.Emitter.emit (C:\ws\socketio\node_modules\component-emitter\index.js:145:20)
    at Request.onData (C:\ws\socketio\node_modules\engine.io-client\lib\transports\polling-xhr.js:236:10)
    at Request.onLoad (C:\ws\socketio\node_modules\engine.io-client\lib\transports\polling-xhr.js:287:12)
    at XMLHttpRequest.xhr.onreadystatechange (C:\ws\socketio\node_modules\engine.io-client\lib\transports\polling-xhr.js:191:18)
    at XMLHttpRequest.dispatchEvent (C:\ws\socketio\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:622:25)
    at setState (C:\ws\socketio\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:641:14)
    at IncomingMessage.<anonymous> (C:\ws\socketio\node_modules\xmlhttprequest-ssl\lib\XMLHttpRequest.js:480:13)
    at IncomingMessage.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |
----------|---------|----------|---------|---------|-------------------
npm ERR! Test failed.  See above for more details.

Other information (e.g. stacktraces, related issues, suggestions how to fix)

I'm a bit stumped at the moment what is going on here, so not preparing a PR (yet).

See #3709

@AviVahl
Copy link
Contributor

AviVahl commented Dec 28, 2020

root cause is ._nsps and .sockets being Maps and not plain objects...

so:
expect(Object.keys(sio._nsps["/"].sockets).length).to.equal(0); should become expect(sio._nsps.get("/")!.sockets.size).to.equal(1);

There are several other issues that will fail newer mocha:

  • tests don't cleanup after themselves. newer mocha doesn't force exit.
  • done is being called several times, and mocha catches more cases now.

darrachequesne added a commit that referenced this issue Jun 27, 2022
@darrachequesne
Copy link
Member

Here we go: 713a6b4

Thanks for the heads-up 👍

@darrachequesne darrachequesne added the enhancement New feature or request label Jun 27, 2022
dzad pushed a commit to dzad/socket.io that referenced this issue May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants