Skip to content

Commit

Permalink
test: fix ci tests for web worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateu Aguiló Bosch committed May 28, 2018
1 parent 97e7281 commit abe65a1
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/helpers/workers/web.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
Expand Down

0 comments on commit abe65a1

Please sign in to comment.