|
1 | 1 | import assert from 'node:assert'; |
2 | | -import { randomUUID } from 'node:crypto'; |
3 | | -import { mkdir, rm, writeFile } from 'node:fs/promises'; |
4 | | -import { ngServe, updateJsonFile } from '../../../utils/project'; |
| 2 | +import { ngServe } from '../../../utils/project'; |
5 | 3 | import { getGlobalVariable } from '../../../utils/env'; |
6 | 4 |
|
7 | 5 | export default async function () { |
8 | | - const outsideDirectoryName = `../outside-${randomUUID()}`; |
| 6 | + const port = await ngServe(); |
9 | 7 |
|
10 | | - await updateJsonFile('angular.json', (json) => { |
11 | | - // Ensure assets located outside the workspace root work with the dev server |
12 | | - json.projects['test-project'].architect.build.options.assets.push({ |
13 | | - 'input': outsideDirectoryName, |
14 | | - 'glob': '**/*', |
15 | | - 'output': './outside', |
16 | | - }); |
17 | | - }); |
18 | | - |
19 | | - await mkdir(outsideDirectoryName); |
20 | | - try { |
21 | | - await writeFile(`${outsideDirectoryName}/some-asset.xyz`, 'XYZ'); |
22 | | - |
23 | | - const port = await ngServe(); |
24 | | - |
25 | | - let response = await fetch(`http://localhost:${port}/favicon.ico`); |
26 | | - assert.strictEqual(response.status, 200, 'favicon.ico response should be ok'); |
27 | | - |
28 | | - response = await fetch(`http://localhost:${port}/outside/some-asset.xyz`); |
29 | | - assert.strictEqual(response.status, 200, 'outside/some-asset.xyz response should be ok'); |
30 | | - assert.strictEqual(await response.text(), 'XYZ', 'outside/some-asset.xyz content is wrong'); |
| 8 | + let response = await fetch(`http://localhost:${port}/favicon.ico`); |
| 9 | + assert.strictEqual(response.status, 200, 'favicon.ico response should be ok'); |
31 | 10 |
|
32 | | - // A non-existent HTML file request with accept header should fallback to the index HTML |
33 | | - response = await fetch(`http://localhost:${port}/does-not-exist.html`, { |
34 | | - headers: { accept: 'text/html' }, |
35 | | - }); |
36 | | - assert.strictEqual( |
37 | | - response.status, |
38 | | - 200, |
39 | | - 'non-existent file response should fallback and be ok', |
40 | | - ); |
41 | | - assert.match( |
42 | | - await response.text(), |
43 | | - /<app-root/, |
44 | | - 'non-existent file response should fallback and contain html', |
45 | | - ); |
46 | | - |
47 | | - // Vite will incorrectly fallback in all non-existent cases so skip last test case |
48 | | - // TODO: Remove conditional when Vite handles this case |
49 | | - if (getGlobalVariable('argv')['esbuild']) { |
50 | | - return; |
51 | | - } |
52 | | - |
53 | | - // A non-existent file without an html accept header should not be found. |
54 | | - response = await fetch(`http://localhost:${port}/does-not-exist.png`); |
55 | | - assert.strictEqual(response.status, 404, 'non-existent file response should be not found'); |
56 | | - } finally { |
57 | | - await rm(outsideDirectoryName, { force: true, recursive: true }); |
| 11 | + // A non-existent HTML file request with accept header should fallback to the index HTML |
| 12 | + response = await fetch(`http://localhost:${port}/does-not-exist.html`, { |
| 13 | + headers: { accept: 'text/html' }, |
| 14 | + }); |
| 15 | + assert.strictEqual(response.status, 200, 'non-existent file response should fallback and be ok'); |
| 16 | + assert.match( |
| 17 | + await response.text(), |
| 18 | + /<app-root/, |
| 19 | + 'non-existent file response should fallback and contain html', |
| 20 | + ); |
| 21 | + |
| 22 | + // Vite will incorrectly fallback in all non-existent cases so skip last test case |
| 23 | + // TODO: Remove conditional when Vite handles this case |
| 24 | + if (getGlobalVariable('argv')['esbuild']) { |
| 25 | + return; |
58 | 26 | } |
| 27 | + |
| 28 | + // A non-existent file without an html accept header should not be found. |
| 29 | + response = await fetch(`http://localhost:${port}/does-not-exist.png`); |
| 30 | + assert.strictEqual(response.status, 404, 'non-existent file response should be not found'); |
59 | 31 | } |
0 commit comments