mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 13:57:09 +01:00
Implements jest-junit report parsing
This commit is contained in:
parent
7bda3b9f6f
commit
bc706859ad
11 changed files with 381 additions and 34 deletions
40
__tests__/__snapshots__/jest-junit.test.ts.snap
Normal file
40
__tests__/__snapshots__/jest-junit.test.ts.snap
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`jest-junit tests matches report snapshot 1`] = `
|
||||
"# jest tests ❌
|
||||
**6** tests were completed in **1.360s** with **1** passed, **1** skipped and **4** failed.
|
||||
| Result | Suite | Tests | Time | Passed ✔️ | Failed ❌ | Skipped ✖️ |
|
||||
| :---: | :--- | ---: | ---: | ---: | ---: | ---: |
|
||||
| ❌ | [__tests__\\\\main.test.js](#testsmaintestjs-) | 4 | 0.486s | 1 | 3 | 0 |
|
||||
| ❌ | [__tests__\\\\second.test.js](#testssecondtestjs-) | 2 | 0.082s | 0 | 1 | 1 |
|
||||
## Test Suites
|
||||
|
||||
### __tests__\\\\main.test.js ❌
|
||||
|
||||
#### Test 1
|
||||
|
||||
| Result | Test | Time | Details |
|
||||
| :---: | :--- | ---: | --- |
|
||||
| ✔️ | Passing test | 1ms | |
|
||||
|
||||
#### Test 1 › Test 1.1
|
||||
|
||||
| Result | Test | Time | Details |
|
||||
| :---: | :--- | ---: | --- |
|
||||
| ❌ | Failing test | 2ms | <details><summary>Error: expect(received).toBeTruthy()</summary><pre>Received: false<br> at Object.<anonymous> (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\__tests__\\\\main.test.js:10:21)<br> at Object.asyncJestTest (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmineAsyncInstall.js:106:37)<br> at C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:45:12<br> at new Promise (<anonymous>)<br> at mapper (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:28:19)<br> at C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:75:41<br> at processTicksAndRejections (internal/process/task_queues.js:97:5)</pre></details> |
|
||||
| ❌ | Exception in target unit | 0ms | <details><summary>Error: Some error</summary><pre> at Object.throwError (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\lib\\\\main.js:2:9)<br> at Object.<anonymous> (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\__tests__\\\\main.test.js:14:11)<br> at Object.asyncJestTest (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmineAsyncInstall.js:106:37)<br> at C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:45:12<br> at new Promise (<anonymous>)<br> at mapper (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:28:19)<br> at C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:75:41<br> at processTicksAndRejections (internal/process/task_queues.js:97:5)</pre></details> |
|
||||
|
||||
#### Test 2
|
||||
|
||||
| Result | Test | Time | Details |
|
||||
| :---: | :--- | ---: | --- |
|
||||
| ❌ | Exception in test | 0ms | <details><summary>Error: Some error</summary><pre> at Object.<anonymous> (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\__tests__\\\\main.test.js:21:11)<br> at Object.asyncJestTest (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmineAsyncInstall.js:106:37)<br> at C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:45:12<br> at new Promise (<anonymous>)<br> at mapper (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:28:19)<br> at C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\queueRunner.js:75:41<br> at processTicksAndRejections (internal/process/task_queues.js:97:5)</pre></details> |
|
||||
|
||||
### __tests__\\\\second.test.js ❌
|
||||
|
||||
| Result | Test | Time | Details |
|
||||
| :---: | :--- | ---: | --- |
|
||||
| ❌ | Timeout test | 4ms | <details><summary>: Timeout - Async callback was not invoked within the 1 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 1 ms timeout specified by jest.setTimeout.Error:</summary><pre> at new Spec (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmine\\\\Spec.js:116:22)<br> at new Spec (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\setup_jest_globals.js:78:9)<br> at specFactory (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmine\\\\Env.js:523:24)<br> at Env.it (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmine\\\\Env.js:592:24)<br> at Env.it (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmineAsyncInstall.js:134:23)<br> at it (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\jasmine\\\\jasmineLight.js:100:21)<br> at Object.<anonymous> (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\__tests__\\\\second.test.js:1:34)<br> at Runtime._execModule (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-runtime\\\\build\\\\index.js:1245:24)<br> at Runtime._loadModule (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-runtime\\\\build\\\\index.js:844:12)<br> at Runtime.requireModule (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-runtime\\\\build\\\\index.js:694:10)<br> at jasmine2 (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-jasmine2\\\\build\\\\index.js:230:13)<br> at runTestInternal (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-runner\\\\build\\\\runTest.js:380:22)<br> at runTest (C:\\\\Users\\\\Michal\\\\Workspace\\\\dorny\\\\test-check\\\\reports\\\\jest\\\\node_modules\\\\jest-runner\\\\build\\\\runTest.js:472:34)</pre></details> |
|
||||
| ✖️ | Skipped test | 0ms | Skipped |
|
||||
"
|
||||
`;
|
||||
|
|
@ -1,44 +1,44 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites name="jest tests" tests="6" failures="4" errors="0" time="1.349">
|
||||
<testsuite name="Test 1" errors="0" failures="3" skipped="0" timestamp="2020-10-18T19:07:47" time="0.487" tests="4">
|
||||
<testcase classname="Test 1 Passing test" name="Test 1 Passing test" time="0.002">
|
||||
<testsuites name="jest tests" tests="6" failures="4" errors="0" time="1.36">
|
||||
<testsuite name="__tests__\main.test.js" errors="0" failures="3" skipped="0" timestamp="2020-10-27T21:39:41" time="0.486" tests="4">
|
||||
<testcase classname="Test 1" name="Passing test" time="0.001">
|
||||
</testcase>
|
||||
<testcase classname="Test 1 Test 1.1 Failing test" name="Test 1 Test 1.1 Failing test" time="0.001">
|
||||
<testcase classname="Test 1 › Test 1.1" name="Failing test" time="0.002">
|
||||
<failure>Error: expect(received).toBeTruthy()
|
||||
|
||||
Received: false
|
||||
at Object.test (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\__tests__\main.test.js:10:21)
|
||||
at Object.<anonymous> (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\__tests__\main.test.js:10:21)
|
||||
at Object.asyncJestTest (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\jasmineAsyncInstall.js:106:37)
|
||||
at resolve (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:45:12)
|
||||
at C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:45:12
|
||||
at new Promise (<anonymous>)
|
||||
at mapper (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:28:19)
|
||||
at promise.then (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:75:41)
|
||||
at process._tickCallback (internal/process/next_tick.js:68:7)</failure>
|
||||
at C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:75:41
|
||||
at processTicksAndRejections (internal/process/task_queues.js:97:5)</failure>
|
||||
</testcase>
|
||||
<testcase classname="Test 1 Test 1.1 Exception in target unit" name="Test 1 Test 1.1 Exception in target unit" time="0.001">
|
||||
<testcase classname="Test 1 › Test 1.1" name="Exception in target unit" time="0">
|
||||
<failure>Error: Some error
|
||||
at Object.throwError (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\lib\main.js:2:9)
|
||||
at Object.test (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\__tests__\main.test.js:14:11)
|
||||
at Object.<anonymous> (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\__tests__\main.test.js:14:11)
|
||||
at Object.asyncJestTest (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\jasmineAsyncInstall.js:106:37)
|
||||
at resolve (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:45:12)
|
||||
at C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:45:12
|
||||
at new Promise (<anonymous>)
|
||||
at mapper (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:28:19)
|
||||
at promise.then (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:75:41)
|
||||
at process._tickCallback (internal/process/next_tick.js:68:7)</failure>
|
||||
at C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:75:41
|
||||
at processTicksAndRejections (internal/process/task_queues.js:97:5)</failure>
|
||||
</testcase>
|
||||
<testcase classname="Test 2 Exception in test" name="Test 2 Exception in test" time="0">
|
||||
<testcase classname="Test 2" name="Exception in test" time="0">
|
||||
<failure>Error: Some error
|
||||
at Object.test (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\__tests__\main.test.js:21:11)
|
||||
at Object.<anonymous> (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\__tests__\main.test.js:21:11)
|
||||
at Object.asyncJestTest (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\jasmineAsyncInstall.js:106:37)
|
||||
at resolve (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:45:12)
|
||||
at C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:45:12
|
||||
at new Promise (<anonymous>)
|
||||
at mapper (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:28:19)
|
||||
at promise.then (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:75:41)
|
||||
at process._tickCallback (internal/process/next_tick.js:68:7)</failure>
|
||||
at C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\queueRunner.js:75:41
|
||||
at processTicksAndRejections (internal/process/task_queues.js:97:5)</failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="undefined" errors="0" failures="1" skipped="1" timestamp="2020-10-18T19:07:47" time="0.089" tests="2">
|
||||
<testcase classname=" Timeout test" name=" Timeout test" time="0.002">
|
||||
<testsuite name="__tests__\second.test.js" errors="0" failures="1" skipped="1" timestamp="2020-10-27T21:39:41" time="0.082" tests="2">
|
||||
<testcase classname="" name="Timeout test" time="0.004">
|
||||
<failure>: Timeout - Async callback was not invoked within the 1 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 1 ms timeout specified by jest.setTimeout.Error:
|
||||
at new Spec (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\jasmine\Spec.js:116:22)
|
||||
at new Spec (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\setup_jest_globals.js:78:9)
|
||||
|
|
@ -51,9 +51,10 @@ Received: false
|
|||
at Runtime._loadModule (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-runtime\build\index.js:844:12)
|
||||
at Runtime.requireModule (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-runtime\build\index.js:694:10)
|
||||
at jasmine2 (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-jasmine2\build\index.js:230:13)
|
||||
at runTestInternal (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-runner\build\runTest.js:380:22)</failure>
|
||||
at runTestInternal (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-runner\build\runTest.js:380:22)
|
||||
at runTest (C:\Users\Michal\Workspace\dorny\test-check\reports\jest\node_modules\jest-runner\build\runTest.js:472:34)</failure>
|
||||
</testcase>
|
||||
<testcase classname=" Skipped test" name=" Skipped test" time="0">
|
||||
<testcase classname="" name="Skipped test" time="0">
|
||||
<skipped/>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
|
|
|
|||
17
__tests__/jest-junit.test.ts
Normal file
17
__tests__/jest-junit.test.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
|
||||
import {parseJestJunit} from '../src/parsers/jest-junit/jest-junit-parser'
|
||||
|
||||
const xmlFixture = fs.readFileSync(path.join(__dirname, 'fixtures', 'jest-junit.xml'), {encoding: 'utf8'})
|
||||
const outputPath = __dirname + '/__outputs__/jest-junit.md'
|
||||
|
||||
describe('jest-junit tests', () => {
|
||||
it('matches report snapshot', async () => {
|
||||
const result = await parseJestJunit(xmlFixture)
|
||||
fs.writeFileSync(outputPath, result?.output?.summary ?? '')
|
||||
|
||||
expect(result.success).toBeFalsy()
|
||||
expect(result?.output?.summary).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
test('TODO', async () => {
|
||||
await expect(true).toBeTruthy()
|
||||
})
|
||||
70
package-lock.json
generated
70
package-lock.json
generated
|
|
@ -1363,6 +1363,15 @@
|
|||
"fastq": "^1.6.0"
|
||||
}
|
||||
},
|
||||
"@octokit/types": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-5.5.0.tgz",
|
||||
"integrity": "sha512-UZ1pErDue6bZNjYOotCNveTXArOMZQFG6hKJfOnGnulVCMcVVi7YIIuuR4WfBhjo7zgpmzn/BkPDnUXtNx+PcQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": ">= 8"
|
||||
}
|
||||
},
|
||||
"@sinonjs/commons": {
|
||||
"version": "1.8.1",
|
||||
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.1.tgz",
|
||||
|
|
@ -1422,6 +1431,12 @@
|
|||
"@babel/types": "^7.3.0"
|
||||
}
|
||||
},
|
||||
"@types/github-slugger": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/github-slugger/-/github-slugger-1.3.0.tgz",
|
||||
"integrity": "sha512-J/rMZa7RqiH/rT29TEVZO4nBoDP9XJOjnbbIofg7GQKs4JIduEO3WLpte+6WeUz/TcrXKlY+bM7FYrp8yFB+3g==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/graceful-fs": {
|
||||
"version": "4.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.4.tgz",
|
||||
|
|
@ -1632,6 +1647,15 @@
|
|||
"integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/xml2js": {
|
||||
"version": "0.4.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/xml2js/-/xml2js-0.4.5.tgz",
|
||||
"integrity": "sha512-yohU3zMn0fkhlape1nxXG2bLEGZRc1FeqF80RoHaYXJN7uibaauXfhzhOJr1Xh36sn+/tx21QAOf07b/xYVk1w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/yargs": {
|
||||
"version": "13.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.3.tgz",
|
||||
|
|
@ -4492,6 +4516,21 @@
|
|||
"assert-plus": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"github-slugger": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/github-slugger/-/github-slugger-1.3.0.tgz",
|
||||
"integrity": "sha512-gwJScWVNhFYSRDvURk/8yhcFBee6aFjye2a7Lhb2bUyRulpIoek9p0I9Kt7PT67d/nUlZbFu8L9RLiA0woQN8Q==",
|
||||
"requires": {
|
||||
"emoji-regex": ">=6.0.0 <=6.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"emoji-regex": {
|
||||
"version": "6.1.1",
|
||||
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-6.1.1.tgz",
|
||||
"integrity": "sha1-xs0OwbBkLio8Z6ETfvxeeW2k+I4="
|
||||
}
|
||||
}
|
||||
},
|
||||
"glob": {
|
||||
"version": "7.1.6",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
|
||||
|
|
@ -4645,12 +4684,6 @@
|
|||
"whatwg-encoding": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"html-escaper": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz",
|
||||
"integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==",
|
||||
"dev": true
|
||||
},
|
||||
"http-signature": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
|
||||
|
|
@ -5100,6 +5133,14 @@
|
|||
"dev": true,
|
||||
"requires": {
|
||||
"html-escaper": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"html-escaper": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz",
|
||||
"integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"jest": {
|
||||
|
|
@ -8323,8 +8364,7 @@
|
|||
"sax": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
|
||||
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==",
|
||||
"dev": true
|
||||
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
|
||||
},
|
||||
"saxes": {
|
||||
"version": "5.0.1",
|
||||
|
|
@ -9391,6 +9431,20 @@
|
|||
"integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==",
|
||||
"dev": true
|
||||
},
|
||||
"xml2js": {
|
||||
"version": "0.4.23",
|
||||
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz",
|
||||
"integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==",
|
||||
"requires": {
|
||||
"sax": ">=0.6.0",
|
||||
"xmlbuilder": "~11.0.0"
|
||||
}
|
||||
},
|
||||
"xmlbuilder": {
|
||||
"version": "11.0.1",
|
||||
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
|
||||
"integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA=="
|
||||
},
|
||||
"xmlchars": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
|
||||
|
|
|
|||
|
|
@ -29,11 +29,16 @@
|
|||
"author": "Michal Dorner <dorner.michal@gmail.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6"
|
||||
"@actions/core": "^1.2.6",
|
||||
"github-slugger": "^1.3.0",
|
||||
"xml2js": "^0.4.23"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@octokit/types": "^5.5.0",
|
||||
"@types/github-slugger": "^1.3.0",
|
||||
"@types/jest": "^26.0.15",
|
||||
"@types/node": "^14.14.6",
|
||||
"@types/xml2js": "^0.4.5",
|
||||
"@typescript-eslint/eslint-plugin": "^4.7.0",
|
||||
"@typescript-eslint/parser": "^4.7.0",
|
||||
"@vercel/ncc": "^0.24.1",
|
||||
|
|
|
|||
121
src/parsers/jest-junit/jest-junit-parser.ts
Normal file
121
src/parsers/jest-junit/jest-junit-parser.ts
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
import {TestResult} from '../test-parser'
|
||||
import {parseStringPromise} from 'xml2js'
|
||||
import GithubSlugger from 'github-slugger'
|
||||
|
||||
import {JunitReport, TestCase, TestSuite, TestSuites} from './jest-junit-types'
|
||||
import {Align, Icon, link, table, exceptionCell} from '../../utils/markdown-utils'
|
||||
import {parseAttribute} from '../../utils/xml-utils'
|
||||
|
||||
export async function parseJestJunit(content: string): Promise<TestResult> {
|
||||
const junit = (await parseStringPromise(content, {
|
||||
attrValueProcessors: [parseAttribute]
|
||||
})) as JunitReport
|
||||
const testsuites = junit.testsuites
|
||||
|
||||
const slugger = new GithubSlugger()
|
||||
const success = !(testsuites.$?.failures > 0 || testsuites.$?.errors > 0)
|
||||
|
||||
return {
|
||||
success,
|
||||
output: {
|
||||
title: junit.testsuites.$.name,
|
||||
summary: getSummary(success, junit, slugger)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getSummary(success: boolean, junit: JunitReport, slugger: GithubSlugger): string {
|
||||
const stats = junit.testsuites.$
|
||||
|
||||
const icon = success ? Icon.success : Icon.fail
|
||||
const time = `${stats.time.toFixed(3)}s`
|
||||
|
||||
const skipped = getSkippedCount(junit.testsuites)
|
||||
const failed = stats.errors + stats.failures
|
||||
const passed = stats.tests - failed - skipped
|
||||
|
||||
const heading = `# ${stats.name} ${icon}`
|
||||
const headingLine = `**${stats.tests}** tests were completed in **${time}** with **${passed}** passed, **${skipped}** skipped and **${failed}** failed.`
|
||||
|
||||
const suitesSummary = junit.testsuites.testsuite.map(ts => {
|
||||
const skip = ts.$.skipped
|
||||
const fail = ts.$.errors + ts.$.failures
|
||||
const pass = ts.$.tests - fail - skip
|
||||
const tm = `${ts.$.time.toFixed(3)}s`
|
||||
const result = success ? Icon.success : Icon.fail
|
||||
const slug = slugger.slug(`${ts.$.name} ${result}`).replace(/_/g, '')
|
||||
const tsAddr = `#${slug}`
|
||||
const name = link(ts.$.name, tsAddr)
|
||||
return [result, name, ts.$.tests, tm, pass, fail, skip]
|
||||
})
|
||||
|
||||
const summary = table(
|
||||
['Result', 'Suite', 'Tests', 'Time', `Passed ${Icon.success}`, `Failed ${Icon.fail}`, `Skipped ${Icon.skip}`],
|
||||
[Align.Center, Align.Left, Align.Right, Align.Right, Align.Right, Align.Right, Align.Right],
|
||||
...suitesSummary
|
||||
)
|
||||
|
||||
const suites = junit.testsuites?.testsuite?.map(ts => getSuiteSummary(ts)).join('\n')
|
||||
const suitesSection = `## Test Suites\n\n${suites}`
|
||||
|
||||
return `${heading}\n${headingLine}\n${summary}\n${suitesSection}`
|
||||
}
|
||||
|
||||
function getSkippedCount(suites: TestSuites): number {
|
||||
return suites.testsuite.reduce((sum, suite) => sum + suite.$.skipped, 0)
|
||||
}
|
||||
|
||||
function getSuiteSummary(suite: TestSuite): string {
|
||||
const success = !(suite.$?.failures > 0 || suite.$?.errors > 0)
|
||||
const icon = success ? Icon.success : Icon.fail
|
||||
|
||||
const groups: {describe: string; tests: TestCase[]}[] = []
|
||||
for (const tc of suite.testcase) {
|
||||
let grp = groups.find(g => g.describe === tc.$.classname)
|
||||
if (grp === undefined) {
|
||||
grp = {describe: tc.$.classname, tests: []}
|
||||
groups.push(grp)
|
||||
}
|
||||
grp.tests.push(tc)
|
||||
}
|
||||
|
||||
const content = groups
|
||||
.map(grp => {
|
||||
const header = grp.describe !== '' ? `#### ${grp.describe}\n\n` : ''
|
||||
const tests = table(
|
||||
['Result', 'Test', 'Time', 'Details'],
|
||||
[Align.Center, Align.Left, Align.Right, Align.None],
|
||||
...grp.tests.map(tc => {
|
||||
const name = tc.$.name
|
||||
const time = `${Math.round(tc.$.time * 1000)}ms`
|
||||
const result = getTestCaseIcon(tc)
|
||||
const ex = getTestCaseDetails(tc)
|
||||
return [result, name, time, ex]
|
||||
})
|
||||
)
|
||||
|
||||
return `${header}${tests}\n`
|
||||
})
|
||||
.join('\n')
|
||||
|
||||
return `### ${suite.$.name} ${icon}\n\n${content}`
|
||||
}
|
||||
|
||||
function getTestCaseIcon(test: TestCase): string {
|
||||
if (test.failure) return Icon.fail
|
||||
if (test.skipped) return Icon.skip
|
||||
return Icon.success
|
||||
}
|
||||
|
||||
function getTestCaseDetails(test: TestCase): string {
|
||||
if (test.skipped !== undefined) {
|
||||
return 'Skipped'
|
||||
}
|
||||
|
||||
if (test.failure !== undefined) {
|
||||
const failure = test.failure.join('\n')
|
||||
return exceptionCell(failure)
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
38
src/parsers/jest-junit/jest-junit-types.ts
Normal file
38
src/parsers/jest-junit/jest-junit-types.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
export interface JunitReport {
|
||||
testsuites: TestSuites
|
||||
}
|
||||
|
||||
export interface TestSuites {
|
||||
$: {
|
||||
name: string
|
||||
tests: number
|
||||
failures: number // assertion failed
|
||||
errors: number // unhandled exception during test execution
|
||||
time: number
|
||||
}
|
||||
testsuite: TestSuite[]
|
||||
}
|
||||
|
||||
export interface TestSuite {
|
||||
$: {
|
||||
name: string
|
||||
tests: number
|
||||
errors: number
|
||||
failures: number
|
||||
skipped: number
|
||||
time: number
|
||||
timestamp?: Date
|
||||
}
|
||||
testcase: TestCase[]
|
||||
}
|
||||
|
||||
export interface TestCase {
|
||||
$: {
|
||||
classname: string
|
||||
file?: string
|
||||
name: string
|
||||
time: number
|
||||
}
|
||||
failure?: string[]
|
||||
skipped?: string[]
|
||||
}
|
||||
10
src/parsers/test-parser.ts
Normal file
10
src/parsers/test-parser.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import {Endpoints} from '@octokit/types'
|
||||
|
||||
type OutputParameters = Endpoints['POST /repos/:owner/:repo/check-runs']['parameters']['output']
|
||||
|
||||
export type ParseTestResult = (content: string) => Promise<TestResult>
|
||||
|
||||
export interface TestResult {
|
||||
success: boolean
|
||||
output: OutputParameters
|
||||
}
|
||||
52
src/utils/markdown-utils.ts
Normal file
52
src/utils/markdown-utils.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
export enum Align {
|
||||
Left = ':---',
|
||||
Center = ':---:',
|
||||
Right = '---:',
|
||||
None = '---'
|
||||
}
|
||||
|
||||
export const Icon = {
|
||||
skip: '✖️', // ':heavy_multiplication_x:'
|
||||
success: '✔️', // ':heavy_check_mark:'
|
||||
fail: '❌' // ':x:'
|
||||
}
|
||||
|
||||
export function details(summary: string, content: string): string {
|
||||
return `<details><summary>${summary}</summary>${content}</details>`
|
||||
}
|
||||
|
||||
export function link(title: string, address: string): string {
|
||||
return `[${title}](${address})`
|
||||
}
|
||||
|
||||
type ToString = string | number | boolean | Date
|
||||
export function table(headers: ToString[], align: ToString[], ...rows: ToString[][]): string {
|
||||
const headerRow = `| ${headers.join(' | ')} |`
|
||||
const alignRow = `| ${align.join(' | ')} |`
|
||||
const contentRows = rows.map(row => `| ${row.join(' | ')} |`).join('\n')
|
||||
return [headerRow, alignRow, contentRows].join('\n')
|
||||
}
|
||||
|
||||
export function exceptionCell(ex: string): string {
|
||||
const lines = ex.split(/\r?\n/)
|
||||
if (lines.length === 0) {
|
||||
return ''
|
||||
}
|
||||
|
||||
const summary = tableEscape(lines.shift()?.trim() || '')
|
||||
const emptyLine = /^\s*$/
|
||||
const firstNonEmptyLine = lines.findIndex(l => !emptyLine.test(l))
|
||||
|
||||
if (firstNonEmptyLine === -1) {
|
||||
return summary
|
||||
}
|
||||
|
||||
const contentLines = firstNonEmptyLine > 0 ? lines.slice(firstNonEmptyLine) : lines
|
||||
|
||||
const content = '<pre>' + tableEscape(contentLines.join('<br>')) + '</pre>'
|
||||
return details(summary, content)
|
||||
}
|
||||
|
||||
export function tableEscape(content: string): string {
|
||||
return content.replace('|', '\\|')
|
||||
}
|
||||
12
src/utils/xml-utils.ts
Normal file
12
src/utils/xml-utils.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
export function parseAttribute(str: string | undefined): string | number | undefined {
|
||||
if (str === '' || str === undefined) {
|
||||
return str
|
||||
}
|
||||
|
||||
const num = parseFloat(str)
|
||||
if (isNaN(num)) {
|
||||
return str
|
||||
}
|
||||
|
||||
return num
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue