zhou zhou
15 小时以前 40905cbd04c2e332cd4bc2b9e0c5b3e1da9cccfa
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
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import path from 'node:path'
import test from 'node:test'
 
const projectRoot = path.resolve(import.meta.dirname, '..')
 
async function readProjectFile(relativePath) {
  return readFile(path.join(projectRoot, relativePath), 'utf8')
}
 
test('development env routes API requests through the rsf-server context path', async () => {
  const envContent = await readProjectFile('.env.development')
 
  assert.match(envContent, /VITE_API_URL\s*=\s*\/rsf-server\b/)
  assert.match(envContent, /VITE_API_PROXY_URL\s*=\s*http:\/\/127\.0\.0\.1:8085\b/)
})
 
test('production env keeps the rsf-server context path as the API base', async () => {
  const envContent = await readProjectFile('.env.production')
 
  assert.match(envContent, /VITE_API_URL\s*=\s*\/rsf-server\b/)
})
 
test('vite dev server proxies the rsf-server context path to the backend target', async () => {
  const viteConfig = await readProjectFile('vite.config.js')
 
  assert.match(viteConfig, /'\/rsf-server'\s*:\s*\{/)
  assert.match(viteConfig, /target:\s*VITE_API_PROXY_URL/)
})