feat: pwa manifest, icon and minimal service worker
This commit is contained in:
26
web/test/pwa.test.ts
Normal file
26
web/test/pwa.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
const pub = path.resolve(__dirname, '../public')
|
||||
|
||||
describe('PWA assets', () => {
|
||||
it('manifest has required fields and the icon exists', () => {
|
||||
const manifest = JSON.parse(readFileSync(path.join(pub, 'manifest.webmanifest'), 'utf8')) as {
|
||||
name: string
|
||||
display: string
|
||||
start_url: string
|
||||
icons: { src: string; sizes: string; type: string }[]
|
||||
}
|
||||
expect(manifest.name).toContain('record-shop')
|
||||
expect(manifest.display).toBe('standalone')
|
||||
expect(manifest.start_url).toBe('/')
|
||||
expect(manifest.icons.some((i) => i.src === '/icon.svg')).toBe(true)
|
||||
expect(() => readFileSync(path.join(pub, 'icon.svg'))).not.toThrow()
|
||||
})
|
||||
|
||||
it('service worker registers a fetch handler', () => {
|
||||
const sw = readFileSync(path.join(pub, 'sw.js'), 'utf8')
|
||||
expect(sw).toContain("addEventListener('fetch'")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user