Skip to content

Commit

Permalink
Merge pull request #17 from dorny/jest-junit
Browse files Browse the repository at this point in the history
MVP: Support for jest-junit
  • Loading branch information
dorny authored Nov 18, 2020
2 parents 76d2223 + 94e768f commit 3e8db1a
Show file tree
Hide file tree
Showing 29 changed files with 14,340 additions and 139 deletions.
14 changes: 8 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"project": "./tsconfig.json"
},
"rules": {
"camelcase": "off",
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"no-shadow": "off",
"prefer-template": "off",
"semi": [ "error", "never"],
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"camelcase": "off",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
"@typescript-eslint/func-call-spacing": ["error", "never"],
Expand All @@ -29,9 +29,12 @@
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
Expand All @@ -41,7 +44,6 @@
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
Expand All @@ -51,4 +53,4 @@
"es6": true,
"jest/globals": true
}
}
}
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist/** -diff linguist-generated=true
* text=auto eol=lf
dist/** -diff linguist-generated=true
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'build-test'
on:
pull_request:
paths-ignore: [ 'README.md' ]
push:
paths-ignore: [ 'README.md' ]
branches:
- main
workflow_dispatch:

jobs:
build-test:
name: 'Build & Test'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm ci
- run: npm run build
- run: npm run format-check
- run: npm run lint
- run: npm test
continue-on-error: true
- name: 'Evaluate test results'
uses: ./
with:
name: 'JEST Tests'
path: '__tests__/__results__/jest-junit.xml'
reporter: 'jest-junit'
- name: 'Sanity check' # re-run tests in case this action failed to detect failing test
run: npm test
20 changes: 0 additions & 20 deletions .github/workflows/test.yml

This file was deleted.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,8 @@ Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
lib/**/*

# Project specific
__tests__/__outputs__
__tests__/__results__
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dist/
lib/
node_modules/
node_modules/
__tests__/__outputs__
__tests__/__snapshots__
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 80,
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": false,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Goal of this project is to create [Github Action](/~https://github.com/features/ac
that could presents test results from popular testing frameworks as Github check run with code annotation in places where test failed.

Support for following test reports are planned for initial release:
- [ ] dotnet-trx: [`dotnet test --logger "trx;LogFileName=test-results.trx"`](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#examples)
- [ ] dart-json: [`dart test --file-reporter=\"json:test-results.json`](https://pub.dev/packages/test)
- [ ] dotnet-trx: [`dotnet test --logger "trx;LogFileName=test-results.trx"`](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#examples)
- [ ] flutter-machine: [`flutter test --machine > test-results.json`](https://flutter.dev/docs/cookbook/testing/unit/introduction)
- [ ] jest-junit: [`jest --ci --reporters=jest-junit`](/~https://github.com/jest-community/jest-junit#readme)
40 changes: 40 additions & 0 deletions __tests__/__snapshots__/jest-junit.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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 |
"
`;
45 changes: 23 additions & 22 deletions __tests__/fixtures/jest-junit.xml
Original file line number Diff line number Diff line change
@@ -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.&lt;anonymous&gt; (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 (&lt;anonymous&gt;)
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.&lt;anonymous&gt; (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 (&lt;anonymous&gt;)
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.&lt;anonymous&gt; (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 (&lt;anonymous&gt;)
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)
Expand All @@ -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>
Expand Down
18 changes: 18 additions & 0 deletions __tests__/jest-junit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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.mkdirSync(path.dirname(outputPath), {recursive: true})
fs.writeFileSync(outputPath, result?.output?.summary ?? '')

expect(result.success).toBeFalsy()
expect(result?.output?.summary).toMatchSnapshot()
})
})
3 changes: 0 additions & 3 deletions __tests__/main.test.ts

This file was deleted.

11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ description: |
author: 'Michal Dorner <dorner.michal@gmail.com>'
inputs:
fail-on-error:
description: 'Set this action as failed if test report contains any failed test'
required: true
default: 'true'
name:
description: 'Name of the check run'
required: true
Expand All @@ -17,6 +21,7 @@ inputs:
reporter:
description: |
Format of test report. Supported options:
- dart-json
- dotnet-trx
- flutter-machine
- jest-junit
Expand All @@ -25,6 +30,12 @@ inputs:
description: 'GitHub Access Token'
required: false
default: ${{ github.token }}
outputs:
conclusion:
description: |
Final conclusion of the created check run:
- 'success' if no failed tests was found
- 'failure' if any failed test was found
runs:
using: 'node12'
main: 'dist/index.js'
Loading

0 comments on commit 3e8db1a

Please sign in to comment.