diff --git a/.workflow/branch-pipeline.yml b/.workflow/branch-pipeline.yml index ce2fb18d79ae18f8b318857b9050f528af13136d..e5c999d7ba0c784faed4898aa028b09a9a3541cd 100644 --- a/.workflow/branch-pipeline.yml +++ b/.workflow/branch-pipeline.yml @@ -23,11 +23,11 @@ stages: - '# 设置NPM源,提升安装速度' - npm config set registry https://registry.npmmirror.com - '# 在这里输入测试命令' - - ls + - npm install && npm run test report: - path: . - file: junit.xml - index: junit.xml + path: mochawesome-report + file: mochawesome.html + index: mochawesome.html checkpoints: [] caches: - ~/.npm diff --git a/.workflow/pr-pipeline.yml b/.workflow/pr-pipeline.yml index 1a05dd09da0d84882c5ce61eb1215564a251de6c..82901bf1643119c0058addaa2acbc43fac35e21f 100644 --- a/.workflow/pr-pipeline.yml +++ b/.workflow/pr-pipeline.yml @@ -1,36 +1,42 @@ version: '1.0' name: pr-pipeline displayName: PRPipeline -stages: - - stage: - name: compile - displayName: 编译 - steps: - - step: build@nodejs - name: build_nodejs - displayName: Nodejs 构建 - # 支持8.16.2、10.17.0、12.16.1、14.16.0、15.12.0五个版本 - nodeVersion: 14.16.0 - # 构建命令:安装依赖 -> 清除上次打包产物残留 -> 执行构建 【请根据项目实际产出进行填写】 - commands: - - npm install && rm -rf ./dist && npm run build - # 非必填字段,开启后表示将构建产物暂存,但不会上传到制品库中,7天后自动清除 - artifacts: - # 构建产物名字,作为产物的唯一标识可向下传递,支持自定义,默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址 - - name: BUILD_ARTIFACT - # 构建产物获取路径,是指代码编译完毕之后构建物的所在路径 - path: - - ./dist - - step: publish@general_artifacts - name: publish_general_artifacts - displayName: 上传制品 - # 上游构建任务定义的产物名,默认BUILD_ARTIFACT - dependArtifact: BUILD_ARTIFACT - # 上传到制品库时的制品命名,默认output - artifactName: output - dependsOn: build_nodejs triggers: + trigger: auto pr: branches: include: - master +variables: + global: + - token +stages: + - name: test + displayName: test + strategy: naturally + trigger: auto + steps: + - step: ut@nodejs + name: unit_test_nodejs + displayName: Nodejs 单元测试 + nodeVersion: 21.5.0 + commands: + - '# 设置NPM源,提升安装速度' + - npm config set registry https://registry.npmmirror.com + - npm install && npm run test + - ls + - '# 在这里输入测试命令' + - export test_result=`jq -r '"{pass:\(.stats.passes),fail:\(.stats.failures),total:\(.stats.tests)}"' ./mochawesome-report/mochawesome.json` + - echo $test_result + - curl -X POST -H 'Content-Type:application/json' 'https://gitee.com/api/v5/repos/${GITEE_REPO}/pulls/${GITEE_PULL_ID}/comments' -d "{\"access_token\":\"${token}\",\"body\":\"$test_result\"}" + report: + path: mochawesome-report + file: mochawesome.json + index: mochawesome.html + checkpoints: [] + caches: + - ~/.npm + - ~/.yarn + notify: [] + strategy: + retry: '0' diff --git a/junit.xml b/junit.xml new file mode 100644 index 0000000000000000000000000000000000000000..a7f8d3b162424dc5006577a791b66c878d368b87 --- /dev/null +++ b/junit.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/package.json b/package.json index e868a8c2732d8e98eb0c2fe11f4fecbb0d74777f..134c84e7e77b1629fd6d18780bb1076be4dc1bab 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "build": "webpack", "start": "npm run build && opn index.html", - "test": "mocha --require @babel/register --reporter mocha-junit-reporter --reporter-options mochaFile=junit.xml --exit" + "test": "mocha --require @babel/register --reporter mochawesome --exit" }, "directories": { "lib": "./lib",