Skip to content

Commit 192f4c1

Browse files
committed
test: Add tap-xunit and flatten results for junit output
This change tests `tap-xunit` as a way to generate a junit report. `tap-xunit` does not parse failures on subtests properly, so flatten them in order to see the full failure details which are important. The `tap-mocha-reporter`, which we normally use, does not properly include the failure details, so `tap-xunit` is a viable replacement. Semver: patch
1 parent 8a5027a commit 192f4c1

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

Jenkinsfile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,18 @@ pipeline {
6363
npm.auth token: "${GITHUB_PACKAGES_TOKEN}"
6464
}
6565

66-
sh """
67-
npm install
68-
"""
66+
sh 'npm install'
6967
}
7068
}
7169

7270
stage('Test') {
7371
steps {
74-
sh 'node -v'
75-
sh 'npm -v'
76-
sh 'npm test'
72+
sh 'npm run test:ci'
7773
}
7874

7975
post {
8076
always {
81-
sh 'cat .tap-output | ./node_modules/.bin/tap-mocha-reporter xunit > coverage/test.xml'
82-
83-
junit 'coverage/test.xml'
77+
junit checksName: 'Test Results', testResults: 'coverage/*.xml'
8478

8579
publishHTML target: [
8680
allowMissing: false,

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "A node.js version of unix's `tail -f` command",
55
"main": "index.js",
66
"scripts": {
7+
"test:ci": "tools/test-ci.sh",
78
"test": "tap",
89
"lint": "eslint ./",
910
"pretest": "npm run lint"
@@ -51,7 +52,8 @@
5152
"eslint": "^7.10.0",
5253
"eslint-config-logdna": "^2.0.0",
5354
"husky": "^4.3.0",
54-
"tap": "^14.10.7"
55+
"tap": "^14.10.7",
56+
"tap-xunit": "^2.4.1"
5557
},
5658
"tap": {
5759
"100": true,
@@ -75,7 +77,7 @@
7577
"files": [
7678
"test/**/*.js"
7779
],
78-
"output-file": ".tap-output"
80+
"output-file": "coverage/.tap-output"
7981
},
8082
"husky": {
8183
"hooks": {

tools/test-ci.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
export PATH="./node_modules/.bin:$PATH"
4+
5+
mkdir -p coverage
6+
7+
npm run test
8+
9+
code=$?
10+
11+
# tap-mocha-reporter is buggy and does not include all test results. Use tap-xunit,
12+
# however it has a bug with subtests as well. @isaacs has offered a solution
13+
# by flattening: https://github.com/aghassemi/tap-xunit/issues/23#issuecomment-520480836
14+
15+
cat coverage/.tap-output | tap-parser -t -f | tap-xunit > coverage/test.xml
16+
17+
exit $code

0 commit comments

Comments
 (0)