Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
DC-TOM
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘照晖
DC-TOM
Commits
2dc8968a
Commit
2dc8968a
authored
Aug 29, 2025
by
Cai Wei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(ci): 修复ci语法错误
parent
d811f16b
Pipeline
#1307
canceled with stages
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
278 deletions
+47
-278
.gitlab-ci.yml
.gitlab-ci.yml
+47
-278
No files found.
.gitlab-ci.yml
View file @
2dc8968a
# GitLab CI配置文件 - DC-TOM项目Cypress测试集成
# 项目: dctomproject
# 分支: projects
# GitLab版本: 12.0.3 兼容配置
stages
:
stages
:
-
build
-
install
-
lint
-
test
-
test
-
reports
-
build
-
deploy
variables
:
NODE_VERSION
:
"
18"
CYPRESS_CACHE_FOLDER
:
"
$CI_PROJECT_DIR/cache/Cypress"
npm_config_cache
:
"
$CI_PROJECT_DIR/cache/npm"
VITE_PORT
:
"
3000"
CYPRESS_baseUrl
:
"
http://localhost:3000"
# 缓存配置 - 提高构建效率
cache
:
key
:
"
${CI_COMMIT_REF_SLUG}"
paths
:
-
cache/Cypress/
-
cache/npm/
-
node_modules/
# 构建阶段
# 1. 安装依赖
build
:
install
:
stage
:
build
stage
:
install
image
:
node:18-alpine
image
:
node:14
before_script
:
-
echo "开始构建dc-tom项目..."
-
node --version
-
npm --version
script
:
script
:
-
npm ci --cache $npm_config_cache --prefer-offline
-
npm install
-
npm run build
-
echo "构建完成,生成dist目录"
artifacts
:
artifacts
:
paths
:
paths
:
-
dist/
-
node_modules/
# 保持依赖缓存供后续阶段使用
-
node_modules/
expire_in
:
1h
expire_in
:
2 hours
only
:
-
web
-
projects
-
merge_requests
#
基础测试 - 核心功能验证
#
2. 代码检查
cypress-basic-tests
:
lint
:
stage
:
tes
t
stage
:
lin
t
image
:
cypress/browsers:node16.14.2-slim-chrome103-ff102
image
:
node:14
dependencies
:
dependencies
:
-
build
-
install
before_script
:
-
echo "准备运行Cypress基础测试..."
-
npm ci --cache $npm_config_cache --prefer-offline
# 启动应用服务器
-
npm run preview -- --host 0.0.0.0 --port $VITE_PORT &
-
echo "等待应用服务器启动..."
-
sleep 15
# 健康检查
-
curl --retry 15 --retry-connrefused --retry-delay 3 http://localhost:$VITE_PORT || (echo "应用启动失败" && exit 1)
-
echo "应用服务器启动成功"
script
:
script
:
-
echo "开始运行基础测试用例..."
-
npm run lint
# 运行核心功能测试:登录、仪表盘、导航
-
npx cypress run
--browser chrome
--headless
--spec "cypress/e2e/{login,dashboard,navigation}.cy.js"
--config video=true,screenshotOnRunFailure=true
--reporter mochawesome
--reporter-options "reportDir=cypress/reports/basic,overwrite=false,html=true,json=true,timestamp=mmddyyyy_HHMMss"
after_script
:
-
echo "基础测试完成"
-
ls -la cypress/reports/basic/ || echo "报告目录为空"
-
ls -la cypress/videos/ || echo "视频目录为空"
-
ls -la cypress/screenshots/ || echo "截图目录为空"
artifacts
:
when
:
always
paths
:
-
cypress/screenshots/
-
cypress/videos/
-
cypress/reports/basic/
reports
:
junit
:
cypress/reports/basic/*.xml
expire_in
:
1 week
only
:
-
web
-
projects
-
merge_requests
#
完整测试套件 - 手动触发
#
3. 单元测试
cypress-full-tests
:
unit_test
:
stage
:
test
stage
:
test
image
:
cypress/browsers:node16.14.2-slim-chrome103-ff102
image
:
node:14
dependencies
:
dependencies
:
-
build
-
install
before_script
:
-
echo "准备运行Cypress完整测试套件..."
-
npm ci --cache $npm_config_cache --prefer-offline
-
npm run preview -- --host 0.0.0.0 --port $VITE_PORT &
-
sleep 15
-
curl --retry 15 --retry-connrefused --retry-delay 3 http://localhost:$VITE_PORT
-
echo "应用服务器准备就绪"
script
:
script
:
-
echo "开始运行完整测试套件..."
-
npm run test:unit
# 运行所有测试用例
-
npx cypress run
--browser chrome
--headless
--spec "cypress/e2e/*.cy.js"
--config video=true,screenshotOnRunFailure=true
--reporter mochawesome
--reporter-options "reportDir=cypress/reports/full,overwrite=false,html=true,json=true,timestamp=mmddyyyy_HHMMss"
after_script
:
-
echo "完整测试套件执行完成"
-
find cypress/reports/full/ -name "*.json" -o -name "*.html" | head -10
artifacts
:
artifacts
:
when
:
always
when
:
always
paths
:
-
cypress/screenshots/
-
cypress/videos/
-
cypress/reports/full/
reports
:
reports
:
junit
:
cypress/reports/full/*.xml
junit
:
junit.xml
expire_in
:
1 week
when
:
manual
only
:
-
web
#
并行测试组1 - 业务功能模块
#
4. Cypress E2E 测试
cypress-business-tests
:
e2e_test
:
stage
:
test
stage
:
test
image
:
cypress/
browsers:node16.14.2-slim-chrome103-ff102
image
:
cypress/
included:12.7.0
# 内置 Cypress + 浏览器环境
dependencies
:
dependencies
:
-
build
-
install
before_script
:
-
echo "准备运行业务功能测试..."
-
npm ci --cache $npm_config_cache --prefer-offline
-
npm run preview -- --host 0.0.0.0 --port $VITE_PORT &
-
sleep 15
-
curl --retry 15 --retry-connrefused --retry-delay 3 http://localhost:$VITE_PORT
script
:
script
:
-
echo "运行业务功能测试用例..."
-
npm run build
# 先打包前端
# 业务核心功能:除尘器概览、设备管理、监控
-
npx http-server ./dist -p 8080 &
# 启动测试服务
-
npx cypress run
-
npx wait-on http://localhost:8080
--browser chrome
-
npx cypress run --browser chrome
--headless
--spec "cypress/e2e/{dust-overview,device-management,monitor}.cy.js"
--config video=true,screenshotOnRunFailure=true
--reporter mochawesome
--reporter-options "reportDir=cypress/reports/business,overwrite=false,html=true,json=true,timestamp=mmddyyyy_HHMMss"
artifacts
:
artifacts
:
when
:
always
when
:
always
paths
:
paths
:
-
cypress/screenshots/
-
cypress/videos
-
cypress/videos/
-
cypress/screenshots
-
cypress/reports/business/
reports
:
junit
:
cypress/reports/business/*.xml
expire_in
:
1 week
when
:
manual
only
:
-
web
# 并行测试组2 - 数据管理模块
# 5. 构建产物
cypress-data-tests
:
build
:
stage
:
test
stage
:
build
image
:
cypress/browsers:node16.14.2-slim-chrome103-ff102
image
:
node:14
dependencies
:
-
build
before_script
:
-
echo "准备运行数据管理测试..."
-
npm ci --cache $npm_config_cache --prefer-offline
-
npm run preview -- --host 0.0.0.0 --port $VITE_PORT &
-
sleep 15
-
curl --retry 15 --retry-connrefused --retry-delay 3 http://localhost:$VITE_PORT
script
:
-
echo "运行数据管理测试用例..."
# 数据相关功能:采集器、闭环管理、告警
-
npx cypress run
--browser chrome
--headless
--spec "cypress/e2e/{collector-list,my-loop,alerts}.cy.js"
--config video=true,screenshotOnRunFailure=true
--reporter mochawesome
--reporter-options "reportDir=cypress/reports/data,overwrite=false,html=true,json=true,timestamp=mmddyyyy_HHMMss"
artifacts
:
when
:
always
paths
:
-
cypress/screenshots/
-
cypress/videos/
-
cypress/reports/data/
reports
:
junit
:
cypress/reports/data/*.xml
expire_in
:
1 week
when
:
manual
only
:
-
web
# 测试报告汇总
generate-test-reports
:
stage
:
reports
image
:
node:16-alpine
dependencies
:
dependencies
:
-
cypress-basic-tests
-
install
-
cypress-full-tests
-
cypress-business-tests
-
cypress-data-tests
before_script
:
-
echo "准备生成测试报告..."
-
npm install -g mochawesome-merge mochawesome-report-generator
script
:
script
:
-
echo "开始合并测试报告..."
-
npm run build
-
mkdir -p public/reports
-
mkdir -p public/assets
# 检查报告文件
-
find cypress/reports -name "*.json" | head -10
# 合并所有测试报告
-
mochawesome-merge "cypress/reports/**/*.json" > public/reports/merged-report.json || echo "报告合并失败,使用空报告"
# 生成HTML报告
-
marge public/reports/merged-report.json --reportDir public/reports --inline --reportTitle "DC-TOM Cypress 测试报告" || echo "HTML报告生成失败"
# 复制媒体文件
-
cp -r cypress/videos public/assets/ 2>/dev/null || echo "无视频文件"
-
cp -r cypress/screenshots public/assets/ 2>/dev/null || echo "无截图文件"
# 生成索引页面
-
|
cat > public/index.html << 'EOF'
<!DOCTYPE html>
<html>
<head>
<title>DC-TOM 测试报告</title>
<meta charset="utf-8">
<style>
body { font-family: Arial, sans-serif; margin: 40px; background-color: #f5f5f5; }
.header { text-align: center; margin-bottom: 30px; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.container { max-width: 800px; margin: 0 auto; }
.links { list-style: none; padding: 0; }
.links li { margin: 15px 0; background: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.links a { text-decoration: none; color: #007cba; font-size: 18px; display: block; padding: 20px; border-radius: 8px; transition: background-color 0.2s; }
.links a:hover { background-color: #f0f8ff; text-decoration: none; }
.icon { margin-right: 10px; font-size: 20px; }
.description { color: #666; font-size: 14px; margin-top: 5px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🧪 DC-TOM Cypress 测试报告</h1>
<p><strong>项目:</strong> dctomproject | <strong>分支:</strong> projects</p>
<p><strong>构建时间:</strong> $(date '+%Y-%m-%d %H:%M:%S')</p>
</div>
<ul class="links">
<li>
<a href="reports/merged-report.html">
<span class="icon">📊</span>完整测试报告
<div class="description">查看详细的测试执行结果、通过率统计和失败原因分析</div>
</a>
</li>
<li>
<a href="assets/videos/">
<span class="icon">🎥</span>测试执行视频
<div class="description">观看完整的测试执行过程录像</div>
</a>
</li>
<li>
<a href="assets/screenshots/">
<span class="icon">📸</span>失败截图
<div class="description">查看测试失败时的页面截图,便于问题定位</div>
</a>
</li>
</ul>
</div>
</body>
</html>
EOF
-
echo "测试报告生成完成"
-
ls -la public/
artifacts
:
artifacts
:
paths
:
paths
:
-
public/
-
dist/
expire_in
:
1 month
only
:
-
web
-
projects
-
merge_requests
# Pages部署 - 展示测试报告
# 6. 部署
pages
:
deploy
:
stage
:
reports
stage
:
deploy
image
:
alpine:latest
dependencies
:
dependencies
:
-
generate-test-reports
-
build
script
:
script
:
-
echo '部署测试报告到GitLab Pages...'
-
echo "Deploying..."
-
echo '访问地址 https://liuzhaohui.gitlab.io/dctomproject/'
# 这里替换成实际的部署命令
artifacts
:
paths
:
-
public/
expire_in
:
1 month
only
:
-
web
-
projects
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment