-
richard.petersen authoredrichard.petersen authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
startup_test.js 1.73 KiB
import { generateSimpleViteManifest, mockApp, mockConfig, mockFetch } from './util.js'
import { expect } from 'chai'
import * as td from 'testdouble'
import { Response } from 'node-fetch'
describe('Service startup', function () {
before(async function () {
mockConfig({ urls: ['http://ui-server/'] })
})
after(function () {
td.reset()
})
it('only fetches all files once', async function () {
const counters = {
'/example.js': 0,
'/test.txt': 0,
'/index.html.js': 0,
'/index.html': 0
}
mockFetch({
'http://ui-server': {
'/manifest.json': generateSimpleViteManifest({
'example.js': { imports: ['test.txt'] },
'test.txt': { },
'index.html': {
file: 'index.html.js',
isEntry: true,
imports: ['example.js']
}
}),
'/example.js': () => {
counters['/example.js']++
return new Response('this is example', { headers: { 'content-type': 'application/javascript' } })
},
'/test.txt': () => {
counters['/test.txt']++
return new Response('this is test', { headers: { 'content-type': 'text/plain' } })
},
'/index.html.js': () => {
counters['/index.html.js']++
return new Response('this is index.html.js', { headers: { 'content-type': 'application/javascript' } })
},
'/index.html': () => {
counters['/index.html']++
return new Response('<html><head></head><body>it\'s me</body></html>', { headers: { 'content-type': 'text/html' } })
}
}
})
await mockApp()
Object.entries(counters).forEach(([key, value]) => {
expect(value, `${key}`).to.equal(1)
})
})
})