nodejs 8.9의 서버 및 클라이언트 구성 요소로 moza를 사용하여 nodejs-app를 테스트하고 있습니다.모카 테스트 socketio 미들웨어가 패키지를 완성하지 못합니다
모카를 제대로 종료하려면 테스트를 실행 한 후에 모든 소켓과 http 서버를 닫아야합니다. 정상적인 테스트에서는 정상적으로 작동하지만 socketio-server에 미들웨어를 등록하자마자 mocha 프로세스가 닫히지 않고 영원히 열리게됩니다.
Testcode (mocha test.spec.js
를 통해 실행 문제를 볼 수있는 두 번째 테스트에서 코멘트) : 그런 일이 왜
// test.spec.js
'use strict'
const Express = require('express')
const Http = require('http')
const ioserver = require('socket.io')
const ioclient = require('socket.io-client')
const NODE_PORT = process.env.NODE_PORT || 3000
describe('Client', function() {
beforeEach(() => {
const express = new Express()
this._http = Http.Server(express)
this._ioserver = ioserver(this._http)
this._http.listen(NODE_PORT)
})
// this test works perfectly, even when I copy it and run it
// multiple times in this suite
it('should connect to a socketio-server', (done) => {
this._ioserver.on('connection',() => {
client.close()
done()
})
const client = ioclient.connect(`http://localhost:${NODE_PORT}`)
})
// this test also finished, but the suite hangs afterwards - as if
// a socket-client or socket-server was not closed properly.
it('should finish the test suite even with a middleware', (done) => {
this._ioserver.use((socket, next) => {
return next()
})
this._ioserver.on('connection',() => {
client.close()
done()
})
const client = ioclient.connect(`http://localhost:${NODE_PORT}`)
})
afterEach(() => {
this._ioserver.close()
this._http.close()
})
})
어떤 아이디어?
을 내가 ('client.disconnect를 사용하는'대신 :이 솔루션은 서버가과 같이 열 연결을 선언 한 후 클라이언트가 열려 연결을 선언 한 후에 만
done()
전화를 하지입니다 close()'아마도 이것이 원인 일 수 있습니다. –그 두 가지는 동의어이며 동일한 메소드를 호출합니다. – Lars
다음의 버그 보고서를 열었습니다 : https://github.com/mochajs/mocha/issues/3095 – Lars