From abe65a1084d1c0e0bd1a005d84d33b5af6c7bd71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateu=20Aguil=C3=B3=20Bosch?= Date: Mon, 28 May 2018 19:35:12 +0200 Subject: [PATCH] test: fix ci tests for web worker --- src/helpers/workers/web.test.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/helpers/workers/web.test.js b/src/helpers/workers/web.test.js index 38d94f3..78d3c4e 100644 --- a/src/helpers/workers/web.test.js +++ b/src/helpers/workers/web.test.js @@ -5,20 +5,31 @@ jest.mock('pino', () => { return output; }); +const app = require('../app'); +const Adios = require('adios'); const pino = require('pino'); describe('The web worker', () => { + afterAll(() => { + jest.restoreAllMocks(); + }); + test('Initializes with the adios socket', () => { expect.assertions(4); let shutdown; - const Adios = require('adios'); jest.spyOn(Adios.child, 'init').mockImplementation(cb => { shutdown = cb; }); + const fakeServer = { + close: jest.fn().mockImplementation(cb => { + cb(); + }), + }; + jest.spyOn(app, 'listen').mockImplementation(() => fakeServer); const server = require('./web'); - expect(server.listening).toBe(true); + expect(app.listen).toHaveBeenCalled(); return shutdown().then(() => { - expect(server.listening).toBe(false); + expect(server.close).toHaveBeenCalled(); expect(pino.info.mock.calls[0][0]).toBe( 'Shutting down server for web worker %s.' );