Files
client-web/src/deployment/nginxConfig.test.mjs
T

55 lines
2.6 KiB
JavaScript
Raw Normal View History

2026-08-04 14:15:24 +08:00
import assert from 'node:assert/strict'
2026-09-29 18:47:46 +08:00
import { readFileSync, existsSync } from 'node:fs'
2026-08-04 14:15:24 +08:00
import test from 'node:test'
2026-09-29 18:47:46 +08:00
const root = new URL('../../', import.meta.url)
const config = readFileSync(new URL('nginx/default.conf.template', root), 'utf8')
const compose = readFileSync(new URL('docker-compose.test.yml', root), 'utf8')
const jenkins = readFileSync(new URL('Jenkinsfile', root), 'utf8')
const vite = readFileSync(new URL('vite.config.ts', root), 'utf8')
2026-08-04 14:15:24 +08:00
2026-09-29 18:47:46 +08:00
test('all business traffic uses one Gateway without rewriting API paths', () => {
assert.match(config, /location \/api\//)
assert.match(config, /proxy_pass \$\{API_UPSTREAM\};/)
assert.doesNotMatch(config, /overseas-api|OVERSEAS_API_UPSTREAM|rewrite/)
assert.match(config, /client_max_body_size 55m;/)
2026-08-27 10:44:14 +08:00
assert.match(config, /proxy_set_header Host \$proxy_host;/)
2026-09-29 18:47:46 +08:00
assert.doesNotMatch(vite, /OVERSEAS_API|AUTH_API_PROXY_TARGET|IAM_API_PROXY_TARGET|WAREHOUSE_API_PROXY_TARGET/)
2026-08-27 10:44:14 +08:00
})
2026-09-29 18:47:46 +08:00
test('test deployment requires an explicit shared network, Gateway and version', () => {
for (const key of ['IMAGE_TAG']) {
assert.ok(compose.includes('${' + key + ':?'))
}
assert.ok(compose.includes('${API_UPSTREAM:-http://gateway:9000}'))
assert.ok(compose.includes('${TEST_NETWORK:-firstleg-test-network}'))
assert.match(compose, /external: true/)
assert.match(compose, /127\.0\.0\.1:/)
assert.doesNotMatch(compose, /overseas|host\.docker\.internal|production|development/)
assert.match(jenkins, /label 'java-test'/)
assert.match(jenkins, /docker compose -f docker-compose\.test\.yml config --quiet/)
assert.match(jenkins, /docker network inspect/)
assert.doesNotMatch(jenkins, /docker-compose\.(production|development)|deploy-production|sshUserPrivateKey/)
for (const file of ['docker-compose.production.yml', 'docker-compose.development.yml', 'scripts/deploy-production.sh']) {
assert.equal(existsSync(new URL(file, root)), false)
}
})
2026-09-29 18:47:46 +08:00
test('application shell is revalidated and missing chunks remain 404', () => {
assert.match(config, /location = \/index\.html/)
assert.match(config, /no-store/)
assert.match(config, /max-age=31536000, immutable/)
assert.match(config, /try_files \$uri =404;/)
assert.match(config, /try_files \$uri \$uri\/ \/index\.html;/)
})
2026-09-29 18:47:46 +08:00
test('container build excludes local environment values and waits for Nginx health', () => {
const ignore = readFileSync(new URL('.dockerignore', root), 'utf8')
assert.match(ignore, /^\.env$/m)
assert.match(ignore, /^\.env\.\*$/m)
assert.match(compose, /healthcheck:/)
assert.match(compose, /http:\/\/127\.0\.0\.1\/healthz/)
assert.match(jenkins, /up -d --wait --wait-timeout 120/)
})