|
| 1 | +import * as chai from 'chai'; |
| 2 | + |
| 3 | +import chaiAsPromised from 'chai-as-promised'; |
| 4 | + |
| 5 | +import Worker from 'web-worker'; |
| 6 | +import Pool from '../src/pool.js'; |
| 7 | +import create from '../src/worker/create.js'; |
| 8 | + |
| 9 | +chai.use(chaiAsPromised); |
| 10 | + |
| 11 | +const { expect } = chai; |
| 12 | + |
| 13 | +describe('Pool', () => { |
| 14 | + it('shall decode a buffer with a worker', async () => { |
| 15 | + const pool = new Pool(1, create); |
| 16 | + const buffer = new ArrayBuffer(1); |
| 17 | + (new Uint8Array(buffer)).set([0]); |
| 18 | + const fileDirectory = { Compression: 1 }; |
| 19 | + const decoded = await pool.decode(fileDirectory, buffer); |
| 20 | + const decodedArray = new Uint8Array(decoded); |
| 21 | + expect(decodedArray).to.eql(new Uint8Array([0])); |
| 22 | + pool.destroy(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('shall properly propagate an exception', async () => { |
| 26 | + const pool = new Pool(1, () => { |
| 27 | + return new Worker(new URL('../src/worker/decoder.js', import.meta.url), { |
| 28 | + type: 'module', |
| 29 | + }); |
| 30 | + }); |
| 31 | + const buffer = new ArrayBuffer(1); |
| 32 | + (new Uint8Array(buffer)).set([0]); |
| 33 | + const fileDirectory = { Compression: -1 }; |
| 34 | + |
| 35 | + await expect(pool.decode(fileDirectory, buffer)).to.eventually.be.rejected; |
| 36 | + pool.destroy(); |
| 37 | + }); |
| 38 | +}); |
0 commit comments