mirror of
https://git.unlock-music.dev/um/um-react.git
synced 2024-11-23 22:42:16 +00:00
test: get coverage work
This commit is contained in:
parent
e60e669d32
commit
1fafe34fa1
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,6 +8,7 @@ pnpm-debug.log*
|
|||||||
lerna-debug.log*
|
lerna-debug.log*
|
||||||
|
|
||||||
node_modules
|
node_modules
|
||||||
|
coverage/
|
||||||
dist
|
dist
|
||||||
dist-ssr
|
dist-ssr
|
||||||
*.local
|
*.local
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
roots: ['<rootDir>/src'],
|
roots: ['<rootDir>/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: [],
|
coveragePathIgnorePatterns: [],
|
||||||
setupFilesAfterEnv: ['./src/test-utils/setup-jest.ts'],
|
setupFilesAfterEnv: ['./src/test-utils/setup-jest.ts'],
|
||||||
testEnvironment: 'jsdom',
|
testEnvironment: 'jsdom',
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { ConcurrentQueue } from '~/util/ConcurrentQueue';
|
|
||||||
import { WorkerClientBus } from '~/util/WorkerEventBus';
|
import { WorkerClientBus } from '~/util/WorkerEventBus';
|
||||||
import { DECRYPTION_WORKER_ACTION_NAME } from './constants';
|
import { DECRYPTION_WORKER_ACTION_NAME } from './constants';
|
||||||
|
import { DecryptionQueue } from '~/util/DecryptionQueue';
|
||||||
|
|
||||||
// TODO: Worker pool?
|
// TODO: Worker pool?
|
||||||
export const workerClient = new Worker(new URL('./worker', import.meta.url), { type: 'module' });
|
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.
|
// FIXME: report the error so is obvious to the user.
|
||||||
workerClient.onerror = (err) => console.error(err);
|
workerClient.onerror = (err) => console.error(err);
|
||||||
|
|
||||||
class DecryptionQueue extends ConcurrentQueue<{ id: string; blobURI: string }> {
|
|
||||||
constructor(private workerClientBus: WorkerClientBus<DECRYPTION_WORKER_ACTION_NAME>, maxQueue?: number) {
|
|
||||||
super(maxQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
async handler(item: { id: string; blobURI: string }): Promise<void> {
|
|
||||||
return this.workerClientBus.request(DECRYPTION_WORKER_ACTION_NAME.DECRYPT, item.blobURI);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const workerClientBus = new WorkerClientBus<DECRYPTION_WORKER_ACTION_NAME>(workerClient);
|
export const workerClientBus = new WorkerClientBus<DECRYPTION_WORKER_ACTION_NAME>(workerClient);
|
||||||
export const decryptionQueue = new DecryptionQueue(workerClientBus);
|
export const decryptionQueue = new DecryptionQueue(workerClientBus);
|
||||||
|
13
src/util/DecryptionQueue.ts
Normal file
13
src/util/DecryptionQueue.ts
Normal file
@ -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<DECRYPTION_WORKER_ACTION_NAME>, maxQueue?: number) {
|
||||||
|
super(maxQueue);
|
||||||
|
}
|
||||||
|
|
||||||
|
async handler(item: { id: string; blobURI: string }): Promise<void> {
|
||||||
|
return this.workerClientBus.request(DECRYPTION_WORKER_ACTION_NAME.DECRYPT, item.blobURI);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user