27 lines
962 B
TypeScript
27 lines
962 B
TypeScript
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'")
|
|
})
|
|
})
|