-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathbuild-asset-paths.test.js
More file actions
45 lines (39 loc) · 1.49 KB
/
Copy pathbuild-asset-paths.test.js
File metadata and controls
45 lines (39 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { describe, it, expect } from 'vitest';
import { readFileSync, existsSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
const repoRoot = resolve(__dirname, '..');
const dist = resolve(repoRoot, 'dist');
const HAS_DIST = existsSync(dist);
// Guards against the regression where /style.css 404'd in production
// because public/* HTML rollup inputs collide with the public-dir copy.
// If you see this fail, the deployed site is likely about to break the
// same way studio did on 2026-04-27.
describe.skipIf(!HAS_DIST)('build asset paths', () => {
it('serves /style.css from dist root', () => {
expect(existsSync(resolve(dist, 'style.css'))).toBe(true);
});
const pagesReferencingStyleCss = [
'studio/index.html',
'discover/index.html',
'widgets-gallery/index.html',
'docs-widgets.html',
];
for (const rel of pagesReferencingStyleCss) {
it(`${rel} references a resolvable stylesheet`, () => {
const file = resolve(dist, rel);
if (!existsSync(file)) return; // page may not exist in this build target
const html = readFileSync(file, 'utf8');
const refs = [...html.matchAll(/href="([^"]+\.css)"/g)].map((m) => m[1]);
for (const href of refs) {
if (!href.startsWith('/')) continue;
const local = resolve(dist, href.slice(1));
expect(
existsSync(local),
`${rel} references ${href} which is not present in dist/`,
).toBe(true);
}
});
}
});