From 1fafe34fa1622f03cece00731d5ffe7c6244990b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Tue, 16 May 2023 22:47:47 +0100 Subject: [PATCH] test: get coverage work --- .gitignore | 1 + jest.config.cjs | 8 +++++++- src/decrypt-worker/client.ts | 12 +----------- src/util/DecryptionQueue.ts | 13 +++++++++++++ 4 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 src/util/DecryptionQueue.ts diff --git a/.gitignore b/.gitignore index a547bf3..6cf4bce 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ pnpm-debug.log* lerna-debug.log* node_modules +coverage/ dist dist-ssr *.local diff --git a/jest.config.cjs b/jest.config.cjs index 0b3269b..d353e67 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -1,6 +1,12 @@ module.exports = { roots: ['/src'], - collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts', '!src/mocks/**'], + collectCoverageFrom: [ + 'src/**/*.{js,jsx,ts,tsx}', + '!src/**/*.d.ts', + '!src/mocks/**', + // Worker client file uses "import.meta.url" and breaks coverage collector. + '!src/decrypt-worker/client.ts', + ], coveragePathIgnorePatterns: [], setupFilesAfterEnv: ['./src/test-utils/setup-jest.ts'], testEnvironment: 'jsdom', diff --git a/src/decrypt-worker/client.ts b/src/decrypt-worker/client.ts index b65cc05..2eb702b 100644 --- a/src/decrypt-worker/client.ts +++ b/src/decrypt-worker/client.ts @@ -1,6 +1,6 @@ -import { ConcurrentQueue } from '~/util/ConcurrentQueue'; import { WorkerClientBus } from '~/util/WorkerEventBus'; import { DECRYPTION_WORKER_ACTION_NAME } from './constants'; +import { DecryptionQueue } from '~/util/DecryptionQueue'; // TODO: Worker pool? export const workerClient = new Worker(new URL('./worker', import.meta.url), { type: 'module' }); @@ -8,15 +8,5 @@ export const workerClient = new Worker(new URL('./worker', import.meta.url), { t // FIXME: report the error so is obvious to the user. workerClient.onerror = (err) => console.error(err); -class DecryptionQueue extends ConcurrentQueue<{ id: string; blobURI: string }> { - constructor(private workerClientBus: WorkerClientBus, maxQueue?: number) { - super(maxQueue); - } - - async handler(item: { id: string; blobURI: string }): Promise { - return this.workerClientBus.request(DECRYPTION_WORKER_ACTION_NAME.DECRYPT, item.blobURI); - } -} - export const workerClientBus = new WorkerClientBus(workerClient); export const decryptionQueue = new DecryptionQueue(workerClientBus); diff --git a/src/util/DecryptionQueue.ts b/src/util/DecryptionQueue.ts new file mode 100644 index 0000000..e111d22 --- /dev/null +++ b/src/util/DecryptionQueue.ts @@ -0,0 +1,13 @@ +import { DECRYPTION_WORKER_ACTION_NAME } from '~/decrypt-worker/constants'; +import { ConcurrentQueue } from './ConcurrentQueue'; +import { WorkerClientBus } from './WorkerEventBus'; + +export class DecryptionQueue extends ConcurrentQueue<{ id: string; blobURI: string }> { + constructor(private workerClientBus: WorkerClientBus, maxQueue?: number) { + super(maxQueue); + } + + async handler(item: { id: string; blobURI: string }): Promise { + return this.workerClientBus.request(DECRYPTION_WORKER_ACTION_NAME.DECRYPT, item.blobURI); + } +}