X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fworker%2Fthread-worker.test.mjs;h=3151b90a4a04d367e262f9f3cee8bf8569bc25c4;hb=7cf454e9907ee712de0020b449bbb9dddc0eb8d8;hp=e4a408d5246b600e08bed68c3979afb0e625e021;hpb=ded253e27e59ae936fe91d789d8454b7eb11dd6a;p=poolifier.git diff --git a/tests/worker/thread-worker.test.mjs b/tests/worker/thread-worker.test.mjs index e4a408d5..3151b90a 100644 --- a/tests/worker/thread-worker.test.mjs +++ b/tests/worker/thread-worker.test.mjs @@ -9,6 +9,14 @@ describe('Thread worker test suite', () => { restore() }) + it('Verify worker properties value after initialization', () => { + const worker = new ThreadWorker(() => {}) + expect(worker.isMain).toBe(true) + expect(worker.mainWorker).toBe(null) + expect(worker.taskFunctions).toBeInstanceOf(Map) + expect(worker.taskFunctions.size).toBe(2) + }) + it('Verify that sync kill handler is called when worker is killed', () => { const worker = new ThreadWorker(() => {}, { killHandler: stub().returns() @@ -45,9 +53,15 @@ describe('Thread worker test suite', () => { status: false, error: new TypeError('name parameter is an empty string') }) - expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Function) - expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Function) - expect(worker.taskFunctions.get('fn2')).toBeInstanceOf(Function) + expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({ + taskFunction: expect.any(Function) + }) + expect(worker.taskFunctions.get('fn1')).toStrictEqual({ + taskFunction: expect.any(Function) + }) + expect(worker.taskFunctions.get('fn2')).toStrictEqual({ + taskFunction: expect.any(Function) + }) expect(worker.taskFunctions.size).toBe(3) expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual( worker.taskFunctions.get('fn1') @@ -65,8 +79,12 @@ describe('Thread worker test suite', () => { ) }) worker.removeTaskFunction('fn2') - expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Function) - expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Function) + expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({ + taskFunction: expect.any(Function) + }) + expect(worker.taskFunctions.get('fn1')).toStrictEqual({ + taskFunction: expect.any(Function) + }) expect(worker.taskFunctions.get('fn2')).toBeUndefined() expect(worker.taskFunctions.size).toBe(2) expect(worker.port.postMessage.calledOnce).toBe(true)