1
This commit is contained in:
2
Makefile
2
Makefile
@@ -928,7 +928,7 @@ docker:
|
||||
.PHONY: e2e-test
|
||||
e2e-test:
|
||||
@echo "正在启动E2E-TEST..."
|
||||
@./tests/e2e/run-e2e-tests.sh
|
||||
@TARGET_URL=$(TARGET_URL) ./tests/e2e/run-e2e-tests.sh
|
||||
|
||||
|
||||
# This endif closes the if at the top of the file
|
||||
|
||||
@@ -4,15 +4,17 @@ import type { PlaywrightTestConfig } from '@playwright/test';
|
||||
|
||||
const BASE_URL = env.DEVSTAR_URL?.replace?.(/\/$/g, '') || 'http://localhost:3000';
|
||||
|
||||
export default {
|
||||
const config: PlaywrightTestConfig = {
|
||||
testDir: './specs',
|
||||
testMatch: /specs\/.*\.ts/,
|
||||
testMatch: /specs\/.*\.ts/,
|
||||
|
||||
timeout: 500000,
|
||||
expect: {
|
||||
timeout: 15000,
|
||||
},
|
||||
forbidOnly: Boolean(env.CI),
|
||||
retries: env.CI ? 2 : 0,
|
||||
|
||||
reporter: env.CI ? 'list' : [['list'], ['html', {
|
||||
outputFolder: 'playwright-report/html',
|
||||
open: 'never'
|
||||
@@ -37,6 +39,13 @@ export default {
|
||||
],
|
||||
outputDir: 'playwright-report/test-artifacts/',
|
||||
snapshotDir: 'playwright-report/test-snapshots/',
|
||||
globalSetup: require.resolve('./global-setup.ts'),
|
||||
};
|
||||
|
||||
} satisfies PlaywrightTestConfig;
|
||||
if (BASE_URL.includes('http://devstar:3000')) {
|
||||
console.log(' 已启用安装');
|
||||
config.globalSetup = require.resolve('./global-setup.ts');
|
||||
} else {
|
||||
console.log(` 已跳过 安装`);
|
||||
}
|
||||
|
||||
export default config satisfies PlaywrightTestConfig;
|
||||
|
||||
@@ -34,12 +34,9 @@ services:
|
||||
build:
|
||||
context: .
|
||||
# 等待 devstar 的 "healthcheck" 通过后,才启动
|
||||
depends_on:
|
||||
devstar:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
# 将 DevStar 的 URL 传给 Playwright
|
||||
- DEVSTAR_URL=http://devstar:3000
|
||||
- DEVSTAR_URL=${DEVSTAR_URL:-http://devstar:3000}
|
||||
volumes:
|
||||
# 也挂载 Docker Socket
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
|
||||
@@ -39,13 +39,33 @@ echo "正在构建 runtime-container 基础镜像..."
|
||||
docker build -t devstar.cn/devstar/devstar-runtime-container:latest -f docker/Dockerfile.runtimeContainer .
|
||||
|
||||
echo "===== [4/5] 启动并运行测试... ====="
|
||||
# --build: 确保 test-runner 镜像是最新的
|
||||
# --abort-on-container-exit: 如果 devstar 挂了, 测试立即停止
|
||||
# --exit-code-from test-runner: 运行结束后,将 test-runner 的退出码(0=成功, 1=失败)作为本命令的退出码
|
||||
docker compose -f ./tests/e2e/docker-compose.test.yml up \
|
||||
--build \
|
||||
--abort-on-container-exit \
|
||||
--exit-code-from test-runner
|
||||
|
||||
# 检查从 Makefile 传来的 TARGET_URL 变量是否为空
|
||||
if [ -n "$TARGET_URL" ]; then
|
||||
# --- [A] URL 模式 ---
|
||||
echo "URL模式"
|
||||
|
||||
# 1. 将目标 URL 导出为 DEVSTAR_URL, 供 docker-compose.yml 读取
|
||||
export DEVSTAR_URL=$TARGET_URL
|
||||
# 2. [关键] 只启动 test-runner 服务
|
||||
# 我们不需要 devstar, 也不需要 --abort-on-container-exit
|
||||
docker compose -f tests/e2e/docker-compose.test.yml up \
|
||||
--build \
|
||||
--exit-code-from test-runner \
|
||||
test-runner
|
||||
else
|
||||
# --- [B] 构建模式 ---
|
||||
echo "==> 模式: [构建模式]. 正在本地启动 devstar..."
|
||||
|
||||
# 1. 导出内部 URL (这会成为 compose 里的默认值)
|
||||
export DEVSTAR_URL="http://devstar:3000"
|
||||
echo "即将执行: docker compose -f tests/e2e/docker-compose.test.yml up --build --wait --exit-code-from test-runner"
|
||||
# 2. [关键] 运行你原来的命令, 启动所有服务
|
||||
docker compose -f tests/e2e/docker-compose.test.yml up \
|
||||
--build \
|
||||
--wait \
|
||||
--exit-code-from test-runner
|
||||
fi
|
||||
|
||||
# 捕获 test-runner 的退出码
|
||||
EXIT_CODE=$?
|
||||
|
||||
Reference in New Issue
Block a user