Apply dependencies update
[poolifier.git] / tests / worker / thread-worker.test.js
1 const { expect } = require('expect')
2 const { ThreadWorker } = require('../../lib')
3
4 describe('Thread worker test suite', () => {
5 let numberOfMessagesPosted = 0
6 const postMessage = function () {
7 numberOfMessagesPosted++
8 }
9 class SpyWorker extends ThreadWorker {
10 getMainWorker () {
11 return { postMessage }
12 }
13 }
14
15 it('Verify worker has default maxInactiveTime', () => {
16 const worker = new ThreadWorker(() => {})
17 expect(worker.opts.maxInactiveTime).toStrictEqual(60000)
18 })
19
20 it('Verify worker invoke the getMainWorker and postMessage methods', () => {
21 const worker = new SpyWorker(() => {})
22 worker.sendToMainWorker({ ok: 1 })
23 expect(numberOfMessagesPosted).toBe(1)
24 })
25 })