H-162: serve built frontend from Go image (#34)
Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const dist = fileURLToPath(new URL('../dist/', import.meta.url));
|
||||
const html = readFileSync(
|
||||
new URL('../dist/index.html', import.meta.url),
|
||||
'utf8'
|
||||
);
|
||||
const assets = [...html.matchAll(/(?:href|src)="(\/assets\/[^"]+)"/g)].map(
|
||||
match => match[1]
|
||||
);
|
||||
|
||||
assert.match(html, /<div id="app"><\/div>/);
|
||||
assert.match(html, /<script src="\/runtime-config\.js"><\/script>/);
|
||||
assert.ok(
|
||||
assets.some(asset => asset.endsWith('.js')),
|
||||
'missing JS asset'
|
||||
);
|
||||
assert.ok(
|
||||
assets.some(asset => asset.endsWith('.css')),
|
||||
'missing CSS asset'
|
||||
);
|
||||
assert.ok(!/<script(?![^>]*\bsrc=)[^>]*>/i.test(html), 'inline script found');
|
||||
assets.forEach(asset => assert.ok(existsSync(dist + asset.slice(1)), asset));
|
||||
Reference in New Issue
Block a user