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