Skip to content

Commit

Permalink
cleanup manifest/image worker tests (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
incognitojam authored Feb 19, 2025
1 parent 471966f commit 6e3a276
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions src/utils/manifest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@ import * as Comlink from 'comlink'
import config from '../config'
import { getManifest } from './manifest'

async function getImageWorker() {
let imageWorker
const imageWorkerFileHandler = {
getFile: vi.fn(),
createWritable: vi.fn().mockImplementation(() => ({
write: vi.fn(),
close: vi.fn(),
})),
}

vi.mock('comlink')
vi.mocked(Comlink.expose).mockImplementation(worker => {
imageWorker = worker
imageWorker.init()
})
globalThis.navigator = {
storage: {
getDirectory: () => ({
getFileHandle: () => imageWorkerFileHandler,
})
}
}

vi.resetModules() // this makes the import be reevaluated on each call
await import('./../workers/image.worker')
let imageWorker

return imageWorker
}
vi.mock('comlink')
vi.mocked(Comlink.expose).mockImplementation(worker => {
imageWorker = worker
imageWorker.init()
})

vi.resetModules() // this makes the import be reevaluated on each call
await import('./../workers/image.worker')

for (const [branch, manifestUrl] of Object.entries(config.manifests)) {
describe(`${branch} manifest`, async () => {
Expand Down Expand Up @@ -48,31 +60,12 @@ for (const [branch, manifestUrl] of Object.entries(config.manifests)) {
})

test('image and checksum', async () => {
const imageWorkerFileHandler = {
getFile: vi.fn(),
createWritable: vi.fn().mockImplementation(() => ({
write: vi.fn(),
close: vi.fn(),
})),
}

globalThis.navigator = {
storage: {
getDirectory: () => ({
getFileHandle: () => imageWorkerFileHandler,
})
}
}

imageWorkerFileHandler.getFile.mockImplementation(async () => {
const response = await fetch(image.archiveUrl)
expect(response.ok, 'to be uploaded').toBe(true)

return response.blob()
})

const imageWorker = await getImageWorker()

await imageWorker.unpackImage(image)
}, { skip: image.name === 'system', timeout: 8 * 1000 })
})
Expand Down

0 comments on commit 6e3a276

Please sign in to comment.