2026-07-28 18:04:21 +08:00
|
|
|
/** Bare Vite must fail before it can present a bootless shell as a working GUI. */
|
|
|
|
|
|
|
|
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
|
import { join } from 'node:path'
|
2026-07-28 22:12:00 +08:00
|
|
|
import { createServer } from 'node:net'
|
2026-07-28 18:04:21 +08:00
|
|
|
import { execa } from 'execa'
|
|
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
|
|
|
|
|
|
const WEB_ROOT = fileURLToPath(new URL('..', import.meta.url))
|
|
|
|
|
|
2026-07-28 22:12:00 +08:00
|
|
|
/** Reserve an available loopback port, then release it for the child invocation. */
|
|
|
|
|
async function freePort(): Promise<number> {
|
|
|
|
|
const server = createServer()
|
|
|
|
|
await new Promise<void>((resolve, reject) => {
|
|
|
|
|
server.once('error', reject)
|
|
|
|
|
server.listen(0, '127.0.0.1', resolve)
|
|
|
|
|
})
|
|
|
|
|
const address = server.address()
|
|
|
|
|
if (address === null || typeof address === 'string') throw new Error('port probe returned no address')
|
|
|
|
|
await new Promise<void>((resolve, reject) => server.close((error) => {
|
|
|
|
|
if (error === undefined) resolve()
|
|
|
|
|
else reject(error)
|
|
|
|
|
}))
|
|
|
|
|
return address.port
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-28 18:04:21 +08:00
|
|
|
describe('Web development entry', () => {
|
|
|
|
|
it('rejects the package dev alias with the full-host correction', async () => {
|
|
|
|
|
const result = await execa('pnpm', ['run', 'dev'], { cwd: WEB_ROOT, reject: false })
|
|
|
|
|
expect(result.exitCode).not.toBe(0)
|
|
|
|
|
expect(result.stderr).toContain('apps/web is build-only')
|
|
|
|
|
expect(result.stderr).toContain('dsh web')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('rejects the standalone Vite server with the full-host correction', async () => {
|
2026-07-28 22:12:00 +08:00
|
|
|
const port = await freePort()
|
|
|
|
|
const result = await execa(join(WEB_ROOT, 'node_modules/.bin/vite'), ['--host', '127.0.0.1', '--port', String(port)], {
|
2026-07-28 18:04:21 +08:00
|
|
|
cwd: WEB_ROOT,
|
|
|
|
|
reject: false,
|
2026-07-28 22:12:00 +08:00
|
|
|
timeout: 10_000,
|
2026-07-28 18:04:21 +08:00
|
|
|
})
|
2026-07-28 22:12:00 +08:00
|
|
|
expect(result.timedOut).toBe(false)
|
2026-07-28 18:04:21 +08:00
|
|
|
expect(result.exitCode).not.toBe(0)
|
|
|
|
|
expect(result.stderr).toContain('apps/web is not a standalone application')
|
|
|
|
|
expect(result.stderr).toContain('dsh web')
|
|
|
|
|
expect(result.stderr).toContain('window.__DSH_BOOT__')
|
2026-07-28 22:12:00 +08:00
|
|
|
await expect(new Promise<void>((resolve, reject) => {
|
|
|
|
|
const probe = createServer()
|
|
|
|
|
probe.once('error', reject)
|
|
|
|
|
probe.listen(port, '127.0.0.1', () => probe.close((error) => {
|
|
|
|
|
if (error === undefined) resolve()
|
|
|
|
|
else reject(error)
|
|
|
|
|
}))
|
|
|
|
|
})).resolves.toBeUndefined()
|
2026-07-28 18:04:21 +08:00
|
|
|
})
|
|
|
|
|
})
|