|
| 1 | +import { mkdir, rm, writeFile } from 'node:fs/promises'; |
| 2 | +import assert from 'assert'; |
| 3 | +import { ngServe, updateJsonFile } from '../../../utils/project'; |
| 4 | +import { randomUUID } from 'node:crypto'; |
| 5 | + |
| 6 | +export default async function () { |
| 7 | + const outsideDirectoryName = `../outside-${randomUUID()}`; |
| 8 | + |
| 9 | + await updateJsonFile('angular.json', (json) => { |
| 10 | + json.projects['test-project'].architect.build.options.assets = [ |
| 11 | + 'src/favicon.ico', |
| 12 | + 'src/assets', |
| 13 | + // Ensure assets located outside the workspace root work with the dev server |
| 14 | + { 'input': outsideDirectoryName, 'glob': '**/*', 'output': './outside' }, |
| 15 | + ]; |
| 16 | + }); |
| 17 | + |
| 18 | + await mkdir(outsideDirectoryName); |
| 19 | + try { |
| 20 | + await writeFile(`${outsideDirectoryName}/some-asset.xyz`, 'XYZ'); |
| 21 | + |
| 22 | + const port = await ngServe(); |
| 23 | + |
| 24 | + let response = await fetch(`http://localhost:${port}/favicon.ico`); |
| 25 | + assert.strictEqual(response.status, 200); |
| 26 | + |
| 27 | + response = await fetch(`http://localhost:${port}/outside/some-asset.xyz`); |
| 28 | + assert.strictEqual(response.status, 200); |
| 29 | + assert.strictEqual(await response.text(), 'XYZ'); |
| 30 | + |
| 31 | + // A non-existent file is assumed to be a potential route and will fallback to index.html |
| 32 | + response = await fetch(`http://localhost:${port}/does-not-exist.png`); |
| 33 | + assert.strictEqual(response.status, 200); |
| 34 | + assert.match(await response.text(), /<html/); |
| 35 | + } finally { |
| 36 | + await rm(outsideDirectoryName, { force: true, recursive: true }); |
| 37 | + } |
| 38 | +} |
0 commit comments