1 const { expect
} = require('expect')
2 const { ThreadWorker
} = require('../../lib')
4 describe('Thread worker test suite', () => {
5 let numberOfMessagesPosted
= 0
6 const postMessage = function () {
7 ++numberOfMessagesPosted
9 class SpyWorker
extends ThreadWorker
{
11 return { postMessage
}
15 it('Verify worker has default maxInactiveTime', () => {
16 const worker
= new ThreadWorker(() => {})
17 expect(worker
.opts
.maxInactiveTime
).toStrictEqual(60000)
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)