Skip to content

Commit

Permalink
chore: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sverben committed May 1, 2024
1 parent a2e30c8 commit 6fd148b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ function sendStatic(
) {
const staticHeaders = getStaticHeaders(file, stats)
if (server.headers) Object.assign(staticHeaders, server.headers)
console.log(server.headers, staticHeaders)

if (req.headers['if-none-match'] === staticHeaders['ETag']) {
res.writeHead(304)
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/vite.headers.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineConfig } from 'vite'
import { viteStaticCopy } from 'vite-plugin-static-copy'

export default defineConfig({
server: {
headers: {
"Cross-Origin-Embedder-Policy": "require-corp",
"Cross-Origin-Opener-Policy": "same-origin"
}
},
plugins: [
viteStaticCopy({
targets: [
{
src: 'foo.txt',
dest: 'fixture1'
}
]
})
]
})
18 changes: 18 additions & 0 deletions test/tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ describe('serve', () => {
expect(res.headers.get('Access-Control-Allow-Origin')).toBe('*')
})
})

describe('vite.headers.config.ts', () => {
let server: ViteDevServer
beforeAll(async () => {
server = await createServer(getConfig('vite.headers.config.ts'))
server = await server.listen()
})
afterAll(async () => {
await server.close()
})

test.concurrent('headers', async () => {
const res = await fetchFromServer(server, '/fixture1/foo.txt')
expect(res.status).toBe(200)
expect(res.headers.get('Cross-Origin-Embedder-Policy')).toBe('require-corp')
expect(res.headers.get('Cross-Origin-Opener-Policy')).toBe('same-origin')
})
})
})

describe('build', () => {
Expand Down

0 comments on commit 6fd148b

Please sign in to comment.