| 1 | import test from 'node:test' ; |
| 2 | import assert from 'node:assert/strict' ; |
| 3 | import { existsSync } from 'node:fs' ; |
| 4 | |
| 5 | test('playground server serves only the demo and public module' , async () => { |
| 6 | assert.ok(existsSync(new URL('../server.js' , import.meta.url)), 'Playground server must exist' ); |
| 7 | const { createServer } = await import('../server.js' ); |
| 8 | const server = createServer(); |
| 9 | await new Promise(resolve => server.listen(0, '127.0.0.1' , resolve)); |
| 10 | const base = `http://127.0.0.1:${server.address().port}` ; |
| 11 | try { |
| 12 | const page = await fetch(base + '/' ); |
| 13 | assert.equal(page.status, 200); |
| 14 | assert.match(page.headers.get('content-type' ), /text\/html/); |
| 15 | const html = await page.text(); |
| 16 | for (const id of ['seed' , 'gallery' , 'chat' , 'selected' , 'copy-svg' , 'download-svg' ]) assert.ok(html.includes(`id="${id}"` ), id); |
| 17 | assert.equal((await fetch(base + '/demo/demo.js' )).status, 200); |
| 18 | assert.equal((await fetch(base + '/demo/style.css' )).status, 200); |
| 19 | for (const path of ['/package.json' , '/README.md' , '/.git/config' , '/missing' , '/demo/%2e%2e/server.js' ]) assert.equal((await fetch(base + path)).status, 404, path); |
| 20 | } finally { await new Promise(resolve => server.close(resolve)); } |
| 21 | }); |