mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 23:52:06 +00:00
fix(server): unregister error event listener (#9245)
Co-authored-by: Daniel Roe <daniel@roe.dev>
This commit is contained in:
parent
c56d4840ad
commit
e687842536
@ -75,8 +75,16 @@ export default class Listener {
|
||||
// Call server.listen
|
||||
try {
|
||||
this.server = await new Promise((resolve, reject) => {
|
||||
this._server.on('error', error => reject(error))
|
||||
const s = this._server.listen(listenArgs, error => error ? reject(error) : resolve(s))
|
||||
this._server.once('error', reject)
|
||||
this._server.listen(listenArgs, (error) => {
|
||||
this._server.off('error', reject)
|
||||
|
||||
if (error) {
|
||||
reject(error)
|
||||
} else {
|
||||
resolve(this._server)
|
||||
}
|
||||
})
|
||||
})
|
||||
} catch (error) {
|
||||
return this.serverErrorHandler(error)
|
||||
|
@ -17,7 +17,8 @@ describe('server: listener', () => {
|
||||
const mockServer = () => {
|
||||
const server = {
|
||||
address: jest.fn(),
|
||||
on: jest.fn(),
|
||||
once: jest.fn(),
|
||||
off: jest.fn(),
|
||||
listen: jest.fn((listenArgs, callback) => {
|
||||
Promise.resolve().then(callback)
|
||||
return server
|
||||
@ -73,8 +74,8 @@ describe('server: listener', () => {
|
||||
|
||||
expect(http.createServer).toBeCalledTimes(1)
|
||||
expect(http.createServer).toBeCalledWith(options.app)
|
||||
expect(server.on).toBeCalledTimes(1)
|
||||
expect(server.on).toBeCalledWith('error', expect.any(Function))
|
||||
expect(server.once).toBeCalledTimes(1)
|
||||
expect(server.once).toBeCalledWith('error', expect.any(Function))
|
||||
expect(server.listen).toBeCalledTimes(1)
|
||||
expect(server.listen).toBeCalledWith(
|
||||
{
|
||||
@ -111,8 +112,8 @@ describe('server: listener', () => {
|
||||
|
||||
expect(https.createServer).toBeCalledTimes(1)
|
||||
expect(https.createServer).toBeCalledWith(options.https, options.app)
|
||||
expect(server.on).toBeCalledTimes(1)
|
||||
expect(server.on).toBeCalledWith('error', expect.any(Function))
|
||||
expect(server.once).toBeCalledTimes(1)
|
||||
expect(server.once).toBeCalledWith('error', expect.any(Function))
|
||||
expect(server.listen).toBeCalledTimes(1)
|
||||
expect(server.listen).toBeCalledWith(
|
||||
{
|
||||
@ -150,8 +151,8 @@ describe('server: listener', () => {
|
||||
|
||||
expect(http.createServer).toBeCalledTimes(1)
|
||||
expect(http.createServer).toBeCalledWith(options.app)
|
||||
expect(server.on).toBeCalledTimes(1)
|
||||
expect(server.on).toBeCalledWith('error', expect.any(Function))
|
||||
expect(server.once).toBeCalledTimes(1)
|
||||
expect(server.once).toBeCalledWith('error', expect.any(Function))
|
||||
expect(server.listen).toBeCalledTimes(1)
|
||||
expect(server.listen).toBeCalledWith(
|
||||
{
|
||||
@ -204,7 +205,7 @@ describe('server: listener', () => {
|
||||
const serverError = new Error('error occurred')
|
||||
server.listen.mockImplementationOnce((listenArgs, callback) => {
|
||||
Promise.resolve().then(callback)
|
||||
const errorListener = server.on.mock.calls[0][1]
|
||||
const errorListener = server.once.mock.calls[0][1]
|
||||
errorListener(serverError)
|
||||
return server
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user