|
1 | 1 | import fs from 'node:fs' |
2 | 2 | import path from 'node:path' |
3 | 3 | import { fileURLToPath } from 'node:url' |
4 | | -import { expect, test } from 'vitest' |
5 | | -import { isBuild, isWindows, page, testDir, viteTestUrl } from '~utils' |
| 4 | +import { describe, expect, test } from 'vitest' |
| 5 | +import { isBuild, isServe, isWindows, page, testDir, viteTestUrl } from '~utils' |
6 | 6 |
|
7 | 7 | test('bom import', async () => { |
8 | 8 | expect(await page.textContent('.utf8-bom')).toMatch('[success]') |
@@ -263,3 +263,26 @@ test.runIf(isBuild)('sideEffects field glob pattern is respected', async () => { |
263 | 263 | ) |
264 | 264 | expect(sideEffectValues).toStrictEqual(['success']) |
265 | 265 | }) |
| 266 | + |
| 267 | +describe.runIf(isServe)('HEAD request handling', () => { |
| 268 | + test('HEAD request to JS file returns correct Content-Type', async () => { |
| 269 | + const response = await fetch(new URL('/absolute.js', viteTestUrl), { |
| 270 | + method: 'HEAD', |
| 271 | + }) |
| 272 | + expect(response.headers.get('content-type')).toBe('text/javascript') |
| 273 | + expect(response.status).toBe(200) |
| 274 | + const text = await response.text() |
| 275 | + expect(text).toBe('') |
| 276 | + }) |
| 277 | + |
| 278 | + test('HEAD request to CSS file returns correct Content-Type', async () => { |
| 279 | + const response = await fetch(new URL('/style.css', viteTestUrl), { |
| 280 | + method: 'HEAD', |
| 281 | + headers: { |
| 282 | + Accept: 'text/css', |
| 283 | + }, |
| 284 | + }) |
| 285 | + expect(response.headers.get('content-type')).toBe('text/css') |
| 286 | + expect(response.status).toBe(200) |
| 287 | + }) |
| 288 | +}) |
0 commit comments