mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 14:27:10 +01:00
Refactoring & cleanup of whole codebase
Improves report summary and annotations
This commit is contained in:
parent
07a0223ee3
commit
60b35d601a
20 changed files with 38784 additions and 33667 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|[DotnetTests.XUnitTests.CalculatorTests](#r0s0)|3✔️|3❌|1✖️|110ms|
|
|[DotnetTests.XUnitTests.CalculatorTests](#r0s0)|3✔️|3❌|1✖️|110ms|
|
||||||
### <a id="user-content-r0s0" href="#r0s0">DotnetTests.XUnitTests.CalculatorTests</a> ❌
|
### <a id="user-content-r0s0" href="#r0s0">DotnetTests.XUnitTests.CalculatorTests</a> ❌
|
||||||
**7** tests were completed in **109.5761ms** with **3** passed, **3** failed and **1** skipped.
|
**7** tests were completed in **110ms** with **3** passed, **3** failed and **1** skipped.
|
||||||
|
|
||||||
|Result|Test|Time|
|
|Result|Test|Time|
|
||||||
|:---:|:---|---:|
|
|:---:|:---|---:|
|
||||||
|
|
|
||||||
|
|
@ -404,7 +404,7 @@
|
||||||
|packages/pretty-format/src/__tests__/react.test.tsx|55✔️|||325ms|
|
|packages/pretty-format/src/__tests__/react.test.tsx|55✔️|||325ms|
|
||||||
|packages/pretty-format/src/__tests__/ReactElement.test.ts|3✔️|||64ms|
|
|packages/pretty-format/src/__tests__/ReactElement.test.ts|3✔️|||64ms|
|
||||||
### <a id="user-content-r0s75" href="#r0s75">e2e/__tests__/jestChangedFiles.test.ts</a> ❌
|
### <a id="user-content-r0s75" href="#r0s75">e2e/__tests__/jestChangedFiles.test.ts</a> ❌
|
||||||
**10** tests were completed in **9045ms** with **9** passed, **1** failed and **0** skipped.
|
**10** tests were completed in **9.045s** with **9** passed, **1** failed and **0** skipped.
|
||||||
|
|
||||||
|Result|Test|Time|
|
|Result|Test|Time|
|
||||||
|:---:|:---|---:|
|
|:---:|:---|---:|
|
||||||
|
|
@ -419,7 +419,7 @@
|
||||||
|✔️|monitors only root paths for hg|281ms|
|
|✔️|monitors only root paths for hg|281ms|
|
||||||
|✔️|handles a bad revision for "changedSince", for hg|949ms|
|
|✔️|handles a bad revision for "changedSince", for hg|949ms|
|
||||||
### <a id="user-content-r0s98" href="#r0s98">e2e/__tests__/onlyChanged.test.ts</a> ❌
|
### <a id="user-content-r0s98" href="#r0s98">e2e/__tests__/onlyChanged.test.ts</a> ❌
|
||||||
**9** tests were completed in **22281ms** with **8** passed, **1** failed and **0** skipped.
|
**9** tests were completed in **22.281s** with **8** passed, **1** failed and **0** skipped.
|
||||||
|
|
||||||
|Result|Test|Time|
|
|Result|Test|Time|
|
||||||
|:---:|:---|---:|
|
|:---:|:---|---:|
|
||||||
|
|
|
||||||
|
|
@ -1,58 +1,6 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`dart-json tests matches report snapshot 1`] = `
|
exports[`dart-json tests matches report snapshot 1`] = `
|
||||||
Object {
|
|
||||||
"annotations": Array [
|
|
||||||
Object {
|
|
||||||
"annotation_level": "failure",
|
|
||||||
"end_line": 13,
|
|
||||||
"message": "Expected: <2>
|
|
||||||
Actual: <1>
|
|
||||||
|
|
||||||
|
|
||||||
package:test_api expect
|
|
||||||
test\\\\main_test.dart 13:9 main.<fn>.<fn>.<fn>
|
|
||||||
",
|
|
||||||
"path": "test/main_test.dart",
|
|
||||||
"start_line": 13,
|
|
||||||
"title": "[test\\\\main_test.dart] Test 1 Test 1.1 Failing test",
|
|
||||||
},
|
|
||||||
Object {
|
|
||||||
"annotation_level": "failure",
|
|
||||||
"end_line": 2,
|
|
||||||
"message": "Exception: Some error
|
|
||||||
|
|
||||||
package:darttest/main.dart 2:3 throwError
|
|
||||||
test\\\\main_test.dart 17:9 main.<fn>.<fn>.<fn>
|
|
||||||
",
|
|
||||||
"path": "lib/main.dart",
|
|
||||||
"start_line": 2,
|
|
||||||
"title": "[test\\\\main_test.dart] Test 1 Test 1.1 Exception in target unit",
|
|
||||||
},
|
|
||||||
Object {
|
|
||||||
"annotation_level": "failure",
|
|
||||||
"end_line": 24,
|
|
||||||
"message": "Exception: Some error
|
|
||||||
|
|
||||||
test\\\\main_test.dart 24:7 main.<fn>.<fn>
|
|
||||||
",
|
|
||||||
"path": "test/main_test.dart",
|
|
||||||
"start_line": 24,
|
|
||||||
"title": "[test\\\\main_test.dart] Test 2 Exception in test",
|
|
||||||
},
|
|
||||||
Object {
|
|
||||||
"annotation_level": "failure",
|
|
||||||
"end_line": 5,
|
|
||||||
"message": "TimeoutException after 0:00:00.000001: Test timed out after 0 seconds.
|
|
||||||
|
|
||||||
dart:isolate _RawReceivePortImpl._handleMessage
|
|
||||||
",
|
|
||||||
"path": "test/second_test.dart",
|
|
||||||
"start_line": 5,
|
|
||||||
"title": "[test\\\\second_test.dart] Timeout test",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"testRuns": Array [
|
|
||||||
TestRunResult {
|
TestRunResult {
|
||||||
"path": "fixtures/dart-json.json",
|
"path": "fixtures/dart-json.json",
|
||||||
"suites": Array [
|
"suites": Array [
|
||||||
|
|
@ -62,6 +10,7 @@ dart:isolate _RawReceivePortImpl._handleMessage
|
||||||
"name": "Test 1",
|
"name": "Test 1",
|
||||||
"tests": Array [
|
"tests": Array [
|
||||||
TestCaseResult {
|
TestCaseResult {
|
||||||
|
"error": undefined,
|
||||||
"name": "Test 1 Passing test",
|
"name": "Test 1 Passing test",
|
||||||
"result": "success",
|
"result": "success",
|
||||||
"time": 36,
|
"time": 36,
|
||||||
|
|
@ -72,11 +21,29 @@ dart:isolate _RawReceivePortImpl._handleMessage
|
||||||
"name": "Test 1 Test 1.1",
|
"name": "Test 1 Test 1.1",
|
||||||
"tests": Array [
|
"tests": Array [
|
||||||
TestCaseResult {
|
TestCaseResult {
|
||||||
|
"error": Object {
|
||||||
|
"line": 13,
|
||||||
|
"message": "Expected: <2>
|
||||||
|
Actual: <1>
|
||||||
|
",
|
||||||
|
"path": "test/main_test.dart",
|
||||||
|
"stackTrace": "package:test_api expect
|
||||||
|
test\\\\main_test.dart 13:9 main.<fn>.<fn>.<fn>
|
||||||
|
",
|
||||||
|
},
|
||||||
"name": "Test 1 Test 1.1 Failing test",
|
"name": "Test 1 Test 1.1 Failing test",
|
||||||
"result": "failed",
|
"result": "failed",
|
||||||
"time": 20,
|
"time": 20,
|
||||||
},
|
},
|
||||||
TestCaseResult {
|
TestCaseResult {
|
||||||
|
"error": Object {
|
||||||
|
"line": 2,
|
||||||
|
"message": "Exception: Some error",
|
||||||
|
"path": "lib/main.dart",
|
||||||
|
"stackTrace": "package:darttest/main.dart 2:3 throwError
|
||||||
|
test\\\\main_test.dart 17:9 main.<fn>.<fn>.<fn>
|
||||||
|
",
|
||||||
|
},
|
||||||
"name": "Test 1 Test 1.1 Exception in target unit",
|
"name": "Test 1 Test 1.1 Exception in target unit",
|
||||||
"result": "failed",
|
"result": "failed",
|
||||||
"time": 6,
|
"time": 6,
|
||||||
|
|
@ -87,6 +54,13 @@ dart:isolate _RawReceivePortImpl._handleMessage
|
||||||
"name": "Test 2",
|
"name": "Test 2",
|
||||||
"tests": Array [
|
"tests": Array [
|
||||||
TestCaseResult {
|
TestCaseResult {
|
||||||
|
"error": Object {
|
||||||
|
"line": 24,
|
||||||
|
"message": "Exception: Some error",
|
||||||
|
"path": "test/main_test.dart",
|
||||||
|
"stackTrace": "test\\\\main_test.dart 24:7 main.<fn>.<fn>
|
||||||
|
",
|
||||||
|
},
|
||||||
"name": "Test 2 Exception in test",
|
"name": "Test 2 Exception in test",
|
||||||
"result": "failed",
|
"result": "failed",
|
||||||
"time": 12,
|
"time": 12,
|
||||||
|
|
@ -103,11 +77,19 @@ dart:isolate _RawReceivePortImpl._handleMessage
|
||||||
"name": null,
|
"name": null,
|
||||||
"tests": Array [
|
"tests": Array [
|
||||||
TestCaseResult {
|
TestCaseResult {
|
||||||
|
"error": Object {
|
||||||
|
"line": 5,
|
||||||
|
"message": "TimeoutException after 0:00:00.000001: Test timed out after 0 seconds.",
|
||||||
|
"path": "test/second_test.dart",
|
||||||
|
"stackTrace": "dart:isolate _RawReceivePortImpl._handleMessage
|
||||||
|
",
|
||||||
|
},
|
||||||
"name": "Timeout test",
|
"name": "Timeout test",
|
||||||
"result": "failed",
|
"result": "failed",
|
||||||
"time": 37,
|
"time": 37,
|
||||||
},
|
},
|
||||||
TestCaseResult {
|
TestCaseResult {
|
||||||
|
"error": undefined,
|
||||||
"name": "Skipped test",
|
"name": "Skipped test",
|
||||||
"result": "skipped",
|
"result": "skipped",
|
||||||
"time": 14,
|
"time": 14,
|
||||||
|
|
@ -120,7 +102,5 @@ dart:isolate _RawReceivePortImpl._handleMessage
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"totalTime": 3760,
|
"totalTime": 3760,
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,30 +1,29 @@
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
|
||||||
import {parseDartJson} from '../src/parsers/dart-json/dart-json-parser'
|
import {DartJsonParser} from '../src/parsers/dart-json/dart-json-parser'
|
||||||
import {ParseOptions} from '../src/parsers/parser-types'
|
import {ParseOptions} from '../src/test-parser'
|
||||||
import {getReport} from '../src/report/get-report'
|
import {getReport} from '../src/report/get-report'
|
||||||
import {normalizeFilePath} from '../src/utils/file-utils'
|
import {normalizeFilePath} from '../src/utils/file-utils'
|
||||||
|
|
||||||
const fixturePath = path.join(__dirname, 'fixtures', 'dart-json.json')
|
|
||||||
const outputPath = path.join(__dirname, '__outputs__', 'dart-json.md')
|
|
||||||
const xmlFixture = {
|
|
||||||
path: normalizeFilePath(path.relative(__dirname, fixturePath)),
|
|
||||||
content: fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('dart-json tests', () => {
|
describe('dart-json tests', () => {
|
||||||
it('matches report snapshot', async () => {
|
it('matches report snapshot', async () => {
|
||||||
const opts: ParseOptions = {
|
const opts: ParseOptions = {
|
||||||
annotations: true,
|
parseErrors: true,
|
||||||
trackedFiles: ['lib/main.dart', 'test/main_test.dart', 'test/second_test.dart'],
|
trackedFiles: ['lib/main.dart', 'test/main_test.dart', 'test/second_test.dart'],
|
||||||
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dart/'
|
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dart/'
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await parseDartJson([xmlFixture], opts)
|
const fixturePath = path.join(__dirname, 'fixtures', 'dart-json.json')
|
||||||
|
const outputPath = path.join(__dirname, '__outputs__', 'dart-json.md')
|
||||||
|
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||||
|
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||||
|
|
||||||
|
const parser = new DartJsonParser(opts)
|
||||||
|
const result = await parser.parse(filePath, fileContent)
|
||||||
expect(result).toMatchSnapshot()
|
expect(result).toMatchSnapshot()
|
||||||
|
|
||||||
const report = getReport(result.testRuns)
|
const report = getReport([result])
|
||||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||||
fs.writeFileSync(outputPath, report)
|
fs.writeFileSync(outputPath, report)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
|
||||||
import {parseDotnetTrx} from '../src/parsers/dotnet-trx/dotnet-trx-parser'
|
import {DotnetTrxParser} from '../src/parsers/dotnet-trx/dotnet-trx-parser'
|
||||||
import {ParseOptions} from '../src/parsers/parser-types'
|
import {ParseOptions} from '../src/test-parser'
|
||||||
import {getReport} from '../src/report/get-report'
|
import {getReport} from '../src/report/get-report'
|
||||||
import {normalizeFilePath} from '../src/utils/file-utils'
|
import {normalizeFilePath} from '../src/utils/file-utils'
|
||||||
|
|
||||||
|
|
@ -10,21 +10,20 @@ describe('dotnet-trx tests', () => {
|
||||||
it('matches report snapshot', async () => {
|
it('matches report snapshot', async () => {
|
||||||
const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-trx.trx')
|
const fixturePath = path.join(__dirname, 'fixtures', 'dotnet-trx.trx')
|
||||||
const outputPath = path.join(__dirname, '__outputs__', 'dotnet-trx.md')
|
const outputPath = path.join(__dirname, '__outputs__', 'dotnet-trx.md')
|
||||||
const xmlFixture = {
|
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||||
path: normalizeFilePath(path.relative(__dirname, fixturePath)),
|
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||||
content: fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
|
||||||
}
|
|
||||||
|
|
||||||
const opts: ParseOptions = {
|
const opts: ParseOptions = {
|
||||||
annotations: true,
|
parseErrors: true,
|
||||||
trackedFiles: ['DotnetTests.Unit/Calculator.cs', 'DotnetTests.XUnitTests/CalculatorTests.cs'],
|
trackedFiles: ['DotnetTests.Unit/Calculator.cs', 'DotnetTests.XUnitTests/CalculatorTests.cs'],
|
||||||
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dotnet/'
|
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dotnet/'
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await parseDotnetTrx([xmlFixture], opts)
|
const parser = new DotnetTrxParser(opts)
|
||||||
|
const result = await parser.parse(filePath, fileContent)
|
||||||
expect(result).toMatchSnapshot()
|
expect(result).toMatchSnapshot()
|
||||||
|
|
||||||
const report = getReport(result.testRuns)
|
const report = getReport([result])
|
||||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||||
fs.writeFileSync(outputPath, report)
|
fs.writeFileSync(outputPath, report)
|
||||||
})
|
})
|
||||||
|
|
@ -32,21 +31,20 @@ describe('dotnet-trx tests', () => {
|
||||||
it('report from FluentValidation test results matches snapshot', async () => {
|
it('report from FluentValidation test results matches snapshot', async () => {
|
||||||
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'FluentValidation.Tests.trx')
|
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'FluentValidation.Tests.trx')
|
||||||
const outputPath = path.join(__dirname, '__outputs__', 'fluent-validation-test-results.md')
|
const outputPath = path.join(__dirname, '__outputs__', 'fluent-validation-test-results.md')
|
||||||
const xmlFixture = {
|
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||||
path: normalizeFilePath(path.relative(__dirname, fixturePath)),
|
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||||
content: fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
|
||||||
}
|
|
||||||
|
|
||||||
const opts: ParseOptions = {
|
const opts: ParseOptions = {
|
||||||
trackedFiles: [],
|
trackedFiles: [],
|
||||||
annotations: true,
|
parseErrors: true,
|
||||||
workDir: ''
|
workDir: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await parseDotnetTrx([xmlFixture], opts)
|
const parser = new DotnetTrxParser(opts)
|
||||||
|
const result = await parser.parse(filePath, fileContent)
|
||||||
expect(result).toMatchSnapshot()
|
expect(result).toMatchSnapshot()
|
||||||
|
|
||||||
const report = getReport(result.testRuns, {listTests: 'failed'})
|
const report = getReport([result], {listTests: 'failed'})
|
||||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||||
fs.writeFileSync(outputPath, report)
|
fs.writeFileSync(outputPath, report)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
|
||||||
import {parseJestJunit} from '../src/parsers/jest-junit/jest-junit-parser'
|
import {JestJunitParser} from '../src/parsers/jest-junit/jest-junit-parser'
|
||||||
import {ParseOptions} from '../src/parsers/parser-types'
|
import {ParseOptions} from '../src/test-parser'
|
||||||
import {getReport} from '../src/report/get-report'
|
import {getReport} from '../src/report/get-report'
|
||||||
import {normalizeFilePath} from '../src/utils/file-utils'
|
import {normalizeFilePath} from '../src/utils/file-utils'
|
||||||
|
|
||||||
|
|
@ -10,45 +10,43 @@ describe('jest-junit tests', () => {
|
||||||
it('report from ./reports/jest test results matches snapshot', async () => {
|
it('report from ./reports/jest test results matches snapshot', async () => {
|
||||||
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
|
const fixturePath = path.join(__dirname, 'fixtures', 'jest-junit.xml')
|
||||||
const outputPath = path.join(__dirname, '__outputs__', 'jest-junit.md')
|
const outputPath = path.join(__dirname, '__outputs__', 'jest-junit.md')
|
||||||
const xmlFixture = {
|
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||||
path: normalizeFilePath(path.relative(__dirname, fixturePath)),
|
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||||
content: fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
|
||||||
}
|
|
||||||
|
|
||||||
const opts: ParseOptions = {
|
const opts: ParseOptions = {
|
||||||
annotations: true,
|
parseErrors: true,
|
||||||
trackedFiles: ['__tests__/main.test.js', '__tests__/second.test.js', 'lib/main.js'],
|
trackedFiles: ['__tests__/main.test.js', '__tests__/second.test.js', 'lib/main.js'],
|
||||||
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/jest/'
|
workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/jest/'
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await parseJestJunit([xmlFixture], opts)
|
const parser = new JestJunitParser(opts)
|
||||||
|
const result = await parser.parse(filePath, fileContent)
|
||||||
expect(result).toMatchSnapshot()
|
expect(result).toMatchSnapshot()
|
||||||
|
|
||||||
const report = getReport(result.testRuns)
|
const report = getReport([result])
|
||||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||||
fs.writeFileSync(outputPath, report)
|
fs.writeFileSync(outputPath, report)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('report from facebook/jest test results matches snapshot', async () => {
|
it('report from facebook/jest test results matches snapshot', async () => {
|
||||||
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'jest', 'jest-test-results.xml')
|
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'jest', 'jest-test-results.xml')
|
||||||
const filesPath = path.join(__dirname, 'fixtures', 'external', 'jest', 'files.txt')
|
const trackedFilesPath = path.join(__dirname, 'fixtures', 'external', 'jest', 'files.txt')
|
||||||
const outputPath = path.join(__dirname, '__outputs__', 'jest-test-results.md')
|
const outputPath = path.join(__dirname, '__outputs__', 'jest-test-results.md')
|
||||||
const xmlFixture = {
|
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||||
path: normalizeFilePath(path.relative(__dirname, fixturePath)),
|
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||||
content: fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
|
||||||
}
|
|
||||||
|
|
||||||
const trackedFiles = fs.readFileSync(filesPath, {encoding: 'utf8'}).split(/\n\r?/g)
|
const trackedFiles = fs.readFileSync(trackedFilesPath, {encoding: 'utf8'}).split(/\n\r?/g)
|
||||||
const opts: ParseOptions = {
|
const opts: ParseOptions = {
|
||||||
|
parseErrors: true,
|
||||||
trackedFiles,
|
trackedFiles,
|
||||||
annotations: true,
|
|
||||||
workDir: '/home/dorny/dorny/jest/'
|
workDir: '/home/dorny/dorny/jest/'
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await parseJestJunit([xmlFixture], opts)
|
const parser = new JestJunitParser(opts)
|
||||||
|
const result = await parser.parse(filePath, fileContent)
|
||||||
expect(result).toMatchSnapshot()
|
expect(result).toMatchSnapshot()
|
||||||
|
|
||||||
const report = getReport(result.testRuns, {listTests: 'failed'})
|
const report = getReport([result], {listTests: 'failed'})
|
||||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||||
fs.writeFileSync(outputPath, report)
|
fs.writeFileSync(outputPath, report)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
487
dist/index.js
generated
vendored
487
dist/index.js
generated
vendored
|
|
@ -35,10 +35,11 @@ const core = __importStar(__nccwpck_require__(2186));
|
||||||
const github = __importStar(__nccwpck_require__(5438));
|
const github = __importStar(__nccwpck_require__(5438));
|
||||||
const fs = __importStar(__nccwpck_require__(5747));
|
const fs = __importStar(__nccwpck_require__(5747));
|
||||||
const fast_glob_1 = __importDefault(__nccwpck_require__(3664));
|
const fast_glob_1 = __importDefault(__nccwpck_require__(3664));
|
||||||
|
const get_annotations_1 = __nccwpck_require__(5867);
|
||||||
|
const get_report_1 = __nccwpck_require__(3737);
|
||||||
const dart_json_parser_1 = __nccwpck_require__(4528);
|
const dart_json_parser_1 = __nccwpck_require__(4528);
|
||||||
const dotnet_trx_parser_1 = __nccwpck_require__(2664);
|
const dotnet_trx_parser_1 = __nccwpck_require__(2664);
|
||||||
const jest_junit_parser_1 = __nccwpck_require__(1113);
|
const jest_junit_parser_1 = __nccwpck_require__(1113);
|
||||||
const get_report_1 = __nccwpck_require__(3737);
|
|
||||||
const file_utils_1 = __nccwpck_require__(2711);
|
const file_utils_1 = __nccwpck_require__(2711);
|
||||||
const git_1 = __nccwpck_require__(9844);
|
const git_1 = __nccwpck_require__(9844);
|
||||||
const github_utils_1 = __nccwpck_require__(3522);
|
const github_utils_1 = __nccwpck_require__(3522);
|
||||||
|
|
@ -81,23 +82,32 @@ async function main() {
|
||||||
const octokit = github.getOctokit(token);
|
const octokit = github.getOctokit(token);
|
||||||
const sha = github_utils_1.getCheckRunSha();
|
const sha = github_utils_1.getCheckRunSha();
|
||||||
// We won't need tracked files if we are not going to create annotations
|
// We won't need tracked files if we are not going to create annotations
|
||||||
const annotations = maxAnnotations > 0;
|
const parseErrors = maxAnnotations > 0;
|
||||||
const trackedFiles = annotations ? await git_1.listFiles() : [];
|
const trackedFiles = parseErrors ? await git_1.listFiles() : [];
|
||||||
const opts = {
|
const options = {
|
||||||
trackedFiles,
|
trackedFiles,
|
||||||
workDir,
|
workDir,
|
||||||
annotations
|
parseErrors
|
||||||
};
|
};
|
||||||
const parser = getParser(reporter);
|
core.info(`Using test report parser '${reporter}'`);
|
||||||
|
const parser = getParser(reporter, options);
|
||||||
const files = await getFiles(path);
|
const files = await getFiles(path);
|
||||||
if (files.length === 0) {
|
if (files.length === 0) {
|
||||||
core.setFailed(`No file matches path '${path}'`);
|
core.setFailed(`No file matches path '${path}'`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
core.info(`Using test report parser '${reporter}'`);
|
const results = [];
|
||||||
const result = await parser(files, opts);
|
for (const file of files) {
|
||||||
github_utils_1.enforceCheckRunLimits(result, maxAnnotations);
|
core.info(`Processing test report ${file}`);
|
||||||
const isFailed = result.testRuns.some(tr => tr.result === 'failed');
|
const content = await fs.promises.readFile(file, { encoding: 'utf8' });
|
||||||
|
const tr = await parser.parse(file, content);
|
||||||
|
results.push(tr);
|
||||||
|
}
|
||||||
|
core.info('Creating report summary');
|
||||||
|
const summary = get_report_1.getReport(results, { listSuites, listTests });
|
||||||
|
core.info('Creating annotations');
|
||||||
|
const annotations = get_annotations_1.getAnnotations(results, maxAnnotations);
|
||||||
|
const isFailed = results.some(tr => tr.result === 'failed');
|
||||||
const conclusion = isFailed ? 'failure' : 'success';
|
const conclusion = isFailed ? 'failure' : 'success';
|
||||||
const icon = isFailed ? markdown_utils_1.Icon.fail : markdown_utils_1.Icon.success;
|
const icon = isFailed ? markdown_utils_1.Icon.fail : markdown_utils_1.Icon.success;
|
||||||
core.info(`Creating check run '${name}' with conclusion '${conclusion}'`);
|
core.info(`Creating check run '${name}' with conclusion '${conclusion}'`);
|
||||||
|
|
@ -108,38 +118,42 @@ async function main() {
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
output: {
|
output: {
|
||||||
title: `${name} ${icon}`,
|
title: `${name} ${icon}`,
|
||||||
summary: get_report_1.getReport(result.testRuns, { listSuites, listTests }),
|
summary,
|
||||||
annotations: result.annotations
|
annotations
|
||||||
},
|
},
|
||||||
...github.context.repo
|
...github.context.repo
|
||||||
});
|
});
|
||||||
|
const passed = results.reduce((sum, tr) => sum + tr.passed, 0);
|
||||||
|
const failed = results.reduce((sum, tr) => sum + tr.failed, 0);
|
||||||
|
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0);
|
||||||
|
const time = results.reduce((sum, tr) => sum + tr.time, 0);
|
||||||
core.setOutput('conclusion', conclusion);
|
core.setOutput('conclusion', conclusion);
|
||||||
|
core.setOutput('passed', passed);
|
||||||
|
core.setOutput('failed', failed);
|
||||||
|
core.setOutput('skipped', skipped);
|
||||||
|
core.setOutput('time', time);
|
||||||
if (failOnError && isFailed) {
|
if (failOnError && isFailed) {
|
||||||
core.setFailed(`Failed test has been found and 'fail-on-error' option is set to ${failOnError}`);
|
core.setFailed(`Failed test has been found and 'fail-on-error' option is set to ${failOnError}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function getParser(reporter) {
|
function getParser(reporter, options) {
|
||||||
switch (reporter) {
|
switch (reporter) {
|
||||||
case 'dart-json':
|
case 'dart-json':
|
||||||
return dart_json_parser_1.parseDartJson;
|
return new dart_json_parser_1.DartJsonParser(options);
|
||||||
case 'dotnet-trx':
|
case 'dotnet-trx':
|
||||||
return dotnet_trx_parser_1.parseDotnetTrx;
|
return new dotnet_trx_parser_1.DotnetTrxParser(options);
|
||||||
case 'flutter-machine':
|
case 'flutter-machine':
|
||||||
return dart_json_parser_1.parseDartJson;
|
return new dart_json_parser_1.DartJsonParser(options);
|
||||||
case 'jest-junit':
|
case 'jest-junit':
|
||||||
return jest_junit_parser_1.parseJestJunit;
|
return new jest_junit_parser_1.JestJunitParser(options);
|
||||||
default:
|
default:
|
||||||
throw new Error(`Input variable 'reporter' is set to invalid value '${reporter}'`);
|
throw new Error(`Input variable 'reporter' is set to invalid value '${reporter}'`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function getFiles(pattern) {
|
async function getFiles(pattern) {
|
||||||
const paths = (await Promise.all(pattern.split(',').map(async (pat) => fast_glob_1.default(pat, { dot: true })))).flat();
|
const tasks = pattern.split(',').map(async (pat) => fast_glob_1.default(pat, { dot: true }));
|
||||||
const files = Promise.all(paths.map(async (path) => {
|
const paths = await Promise.all(tasks);
|
||||||
core.info(`Reading test report '${path}'`);
|
return paths.flat();
|
||||||
const content = await fs.promises.readFile(path, { encoding: 'utf8' });
|
|
||||||
return { path, content };
|
|
||||||
}));
|
|
||||||
return files;
|
|
||||||
}
|
}
|
||||||
exports.getFiles = getFiles;
|
exports.getFiles = getFiles;
|
||||||
run();
|
run();
|
||||||
|
|
@ -172,12 +186,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.parseDartJson = void 0;
|
exports.DartJsonParser = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const file_utils_1 = __nccwpck_require__(2711);
|
const file_utils_1 = __nccwpck_require__(2711);
|
||||||
const markdown_utils_1 = __nccwpck_require__(6482);
|
|
||||||
const dart_json_types_1 = __nccwpck_require__(7887);
|
const dart_json_types_1 = __nccwpck_require__(7887);
|
||||||
const test_results_1 = __nccwpck_require__(8407);
|
const test_results_1 = __nccwpck_require__(2768);
|
||||||
class TestRun {
|
class TestRun {
|
||||||
constructor(path, suites, success, time) {
|
constructor(path, suites, success, time) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
|
@ -220,16 +233,16 @@ class TestCase {
|
||||||
return this.testDone !== undefined ? this.testDone.time - this.testStart.time : 0;
|
return this.testDone !== undefined ? this.testDone.time - this.testStart.time : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function parseDartJson(files, options) {
|
class DartJsonParser {
|
||||||
const testRuns = files.map(f => getTestRun(f.path, f.content));
|
constructor(options) {
|
||||||
const testRunsResults = testRuns.map(getTestRunResult);
|
this.options = options;
|
||||||
return {
|
|
||||||
testRuns: testRunsResults,
|
|
||||||
annotations: options.annotations ? getAnnotations(testRuns, options.workDir, options.trackedFiles) : []
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
exports.parseDartJson = parseDartJson;
|
async parse(path, content) {
|
||||||
function getTestRun(path, content) {
|
const tr = this.getTestRun(path, content);
|
||||||
|
const result = this.getTestRunResult(tr);
|
||||||
|
return Promise.resolve(result);
|
||||||
|
}
|
||||||
|
getTestRun(path, content) {
|
||||||
core.info(`Parsing content of '${path}'`);
|
core.info(`Parsing content of '${path}'`);
|
||||||
const lines = content.split(/\n\r?/g);
|
const lines = content.split(/\n\r?/g);
|
||||||
const events = lines
|
const events = lines
|
||||||
|
|
@ -277,63 +290,55 @@ function getTestRun(path, content) {
|
||||||
}
|
}
|
||||||
return new TestRun(path, Object.values(suites), success, totalTime);
|
return new TestRun(path, Object.values(suites), success, totalTime);
|
||||||
}
|
}
|
||||||
function getTestRunResult(tr) {
|
getTestRunResult(tr) {
|
||||||
const suites = tr.suites.map(s => {
|
const suites = tr.suites.map(s => {
|
||||||
return new test_results_1.TestSuiteResult(s.suite.path, getGroups(s));
|
return new test_results_1.TestSuiteResult(s.suite.path, this.getGroups(s));
|
||||||
});
|
});
|
||||||
return new test_results_1.TestRunResult(tr.path, suites, tr.time);
|
return new test_results_1.TestRunResult(tr.path, suites, tr.time);
|
||||||
}
|
}
|
||||||
function getGroups(suite) {
|
getGroups(suite) {
|
||||||
const groups = Object.values(suite.groups).filter(grp => grp.tests.length > 0);
|
const groups = Object.values(suite.groups).filter(grp => grp.tests.length > 0);
|
||||||
groups.sort((a, b) => { var _a, _b; return ((_a = a.group.line) !== null && _a !== void 0 ? _a : 0) - ((_b = b.group.line) !== null && _b !== void 0 ? _b : 0); });
|
groups.sort((a, b) => { var _a, _b; return ((_a = a.group.line) !== null && _a !== void 0 ? _a : 0) - ((_b = b.group.line) !== null && _b !== void 0 ? _b : 0); });
|
||||||
return groups.map(group => {
|
return groups.map(group => {
|
||||||
group.tests.sort((a, b) => { var _a, _b; return ((_a = a.testStart.test.line) !== null && _a !== void 0 ? _a : 0) - ((_b = b.testStart.test.line) !== null && _b !== void 0 ? _b : 0); });
|
group.tests.sort((a, b) => { var _a, _b; return ((_a = a.testStart.test.line) !== null && _a !== void 0 ? _a : 0) - ((_b = b.testStart.test.line) !== null && _b !== void 0 ? _b : 0); });
|
||||||
const tests = group.tests.map(t => new test_results_1.TestCaseResult(t.testStart.test.name, t.result, t.time));
|
const tests = group.tests.map(t => this.getTest(t));
|
||||||
return new test_results_1.TestGroupResult(group.group.name, tests);
|
return new test_results_1.TestGroupResult(group.group.name, tests);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getAnnotations(testRuns, workDir, trackedFiles) {
|
getTest(tc) {
|
||||||
const annotations = [];
|
const error = this.getError(tc);
|
||||||
for (const tr of testRuns) {
|
return new test_results_1.TestCaseResult(tc.testStart.test.name, tc.result, tc.time, error);
|
||||||
for (const suite of tr.suites) {
|
|
||||||
for (const group of Object.values(suite.groups)) {
|
|
||||||
for (const test of group.tests) {
|
|
||||||
if (test.error) {
|
|
||||||
const err = getAnnotation(test, suite, workDir, trackedFiles);
|
|
||||||
if (err !== null) {
|
|
||||||
annotations.push(err);
|
|
||||||
}
|
}
|
||||||
}
|
getError(test) {
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return annotations;
|
|
||||||
}
|
|
||||||
function getAnnotation(test, testSuite, workDir, trackedFiles) {
|
|
||||||
var _a, _b, _c, _d, _e, _f;
|
var _a, _b, _c, _d, _e, _f;
|
||||||
const stack = (_b = (_a = test.error) === null || _a === void 0 ? void 0 : _a.stackTrace) !== null && _b !== void 0 ? _b : '';
|
if (!this.options.parseErrors || !test.error) {
|
||||||
let src = exceptionThrowSource(stack, trackedFiles);
|
return undefined;
|
||||||
if (src === null) {
|
|
||||||
const file = getRelativePathFromUrl((_c = test.testStart.test.url) !== null && _c !== void 0 ? _c : '', workDir);
|
|
||||||
if (!trackedFiles.includes(file)) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
src = {
|
const { workDir, trackedFiles } = this.options;
|
||||||
file,
|
const message = (_b = (_a = test.error) === null || _a === void 0 ? void 0 : _a.error) !== null && _b !== void 0 ? _b : '';
|
||||||
line: (_d = test.testStart.test.line) !== null && _d !== void 0 ? _d : 0
|
const stackTrace = (_d = (_c = test.error) === null || _c === void 0 ? void 0 : _c.stackTrace) !== null && _d !== void 0 ? _d : '';
|
||||||
};
|
const src = this.exceptionThrowSource(stackTrace, trackedFiles);
|
||||||
|
let path;
|
||||||
|
let line;
|
||||||
|
if (src !== undefined) {
|
||||||
|
;
|
||||||
|
(path = src.path), (line = src.line);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const testStartPath = this.getRelativePathFromUrl((_e = test.testStart.test.url) !== null && _e !== void 0 ? _e : '', workDir);
|
||||||
|
if (trackedFiles.includes(testStartPath)) {
|
||||||
|
path = testStartPath;
|
||||||
|
}
|
||||||
|
line = (_f = test.testStart.test.line) !== null && _f !== void 0 ? _f : undefined;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
annotation_level: 'failure',
|
path,
|
||||||
start_line: src.line,
|
line,
|
||||||
end_line: src.line,
|
message,
|
||||||
path: src.file,
|
stackTrace
|
||||||
message: `${markdown_utils_1.fixEol((_e = test.error) === null || _e === void 0 ? void 0 : _e.error)}\n\n${markdown_utils_1.fixEol((_f = test.error) === null || _f === void 0 ? void 0 : _f.stackTrace)}`,
|
|
||||||
title: `[${testSuite.suite.path}] ${test.testStart.test.name}`
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function exceptionThrowSource(ex, trackedFiles) {
|
exceptionThrowSource(ex, trackedFiles) {
|
||||||
// imports from package which is tested are listed in stack traces as 'package:xyz/' which maps to relative path 'lib/'
|
// imports from package which is tested are listed in stack traces as 'package:xyz/' which maps to relative path 'lib/'
|
||||||
const packageRe = /^package:[a-zA-z0-9_$]+\//;
|
const packageRe = /^package:[a-zA-z0-9_$]+\//;
|
||||||
const lines = ex.split(/\r?\n/).map(str => str.replace(packageRe, 'lib/'));
|
const lines = ex.split(/\r?\n/).map(str => str.replace(packageRe, 'lib/'));
|
||||||
|
|
@ -342,26 +347,27 @@ function exceptionThrowSource(ex, trackedFiles) {
|
||||||
for (const str of lines) {
|
for (const str of lines) {
|
||||||
const match = str.match(re);
|
const match = str.match(re);
|
||||||
if (match !== null) {
|
if (match !== null) {
|
||||||
const [_, fileStr, lineStr] = match;
|
const [_, pathStr, lineStr] = match;
|
||||||
const file = file_utils_1.normalizeFilePath(fileStr);
|
const path = file_utils_1.normalizeFilePath(pathStr);
|
||||||
if (trackedFiles.includes(file)) {
|
if (trackedFiles.includes(path)) {
|
||||||
const line = parseInt(lineStr);
|
const line = parseInt(lineStr);
|
||||||
return { file, line };
|
return { path, line };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
function getRelativePathFromUrl(file, workdir) {
|
getRelativePathFromUrl(file, workDir) {
|
||||||
const prefix = 'file:///';
|
const prefix = 'file:///';
|
||||||
if (file.startsWith(prefix)) {
|
if (file.startsWith(prefix)) {
|
||||||
file = file.substr(prefix.length);
|
file = file.substr(prefix.length);
|
||||||
}
|
}
|
||||||
if (file.startsWith(workdir)) {
|
if (file.startsWith(workDir)) {
|
||||||
file = file.substr(workdir.length);
|
file = file.substr(workDir.length);
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
exports.DartJsonParser = DartJsonParser;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
@ -427,13 +433,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.exceptionThrowSource = exports.parseDotnetTrx = void 0;
|
exports.DotnetTrxParser = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const xml2js_1 = __nccwpck_require__(6189);
|
const xml2js_1 = __nccwpck_require__(6189);
|
||||||
const file_utils_1 = __nccwpck_require__(2711);
|
const file_utils_1 = __nccwpck_require__(2711);
|
||||||
const markdown_utils_1 = __nccwpck_require__(6482);
|
|
||||||
const parse_utils_1 = __nccwpck_require__(7811);
|
const parse_utils_1 = __nccwpck_require__(7811);
|
||||||
const test_results_1 = __nccwpck_require__(8407);
|
const test_results_1 = __nccwpck_require__(2768);
|
||||||
class TestClass {
|
class TestClass {
|
||||||
constructor(name) {
|
constructor(name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
@ -458,42 +463,26 @@ class Test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function parseDotnetTrx(files, options) {
|
class DotnetTrxParser {
|
||||||
const testRuns = [];
|
constructor(options) {
|
||||||
const testClasses = [];
|
this.options = options;
|
||||||
for (const file of files) {
|
|
||||||
const trx = await getTrxReport(file);
|
|
||||||
const tc = getTestClasses(trx);
|
|
||||||
const tr = getTestRunResult(file.path, trx, tc);
|
|
||||||
testRuns.push(tr);
|
|
||||||
testClasses.push(...tc);
|
|
||||||
}
|
}
|
||||||
return {
|
async parse(path, content) {
|
||||||
testRuns,
|
const trx = await this.getTrxReport(path, content);
|
||||||
annotations: options.annotations ? getAnnotations(testClasses, options.workDir, options.trackedFiles) : []
|
const tc = this.getTestClasses(trx);
|
||||||
};
|
const tr = this.getTestRunResult(path, trx, tc);
|
||||||
|
return tr;
|
||||||
}
|
}
|
||||||
exports.parseDotnetTrx = parseDotnetTrx;
|
async getTrxReport(path, content) {
|
||||||
async function getTrxReport(file) {
|
core.info(`Parsing content of '${path}'`);
|
||||||
core.info(`Parsing content of '${file.path}'`);
|
|
||||||
try {
|
try {
|
||||||
return (await xml2js_1.parseStringPromise(file.content));
|
return (await xml2js_1.parseStringPromise(content));
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
throw new Error(`Invalid XML at ${file.path}\n\n${e}`);
|
throw new Error(`Invalid XML at ${path}\n\n${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function getTestRunResult(path, trx, testClasses) {
|
getTestClasses(trx) {
|
||||||
const times = trx.TestRun.Times[0].$;
|
|
||||||
const totalTime = parse_utils_1.parseIsoDate(times.finish).getTime() - parse_utils_1.parseIsoDate(times.start).getTime();
|
|
||||||
const suites = testClasses.map(tc => {
|
|
||||||
const tests = tc.tests.map(t => new test_results_1.TestCaseResult(t.name, t.result, t.duration));
|
|
||||||
const group = new test_results_1.TestGroupResult(null, tests);
|
|
||||||
return new test_results_1.TestSuiteResult(tc.name, [group]);
|
|
||||||
});
|
|
||||||
return new test_results_1.TestRunResult(path, suites, totalTime);
|
|
||||||
}
|
|
||||||
function getTestClasses(trx) {
|
|
||||||
var _a;
|
var _a;
|
||||||
const unitTests = {};
|
const unitTests = {};
|
||||||
for (const td of trx.TestRun.TestDefinitions) {
|
for (const td of trx.TestRun.TestDefinitions) {
|
||||||
|
|
@ -525,31 +514,43 @@ function getTestClasses(trx) {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
function getAnnotations(testClasses, workDir, trackedFiles) {
|
getTestRunResult(path, trx, testClasses) {
|
||||||
const annotations = [];
|
const times = trx.TestRun.Times[0].$;
|
||||||
for (const tc of testClasses) {
|
const totalTime = parse_utils_1.parseIsoDate(times.finish).getTime() - parse_utils_1.parseIsoDate(times.start).getTime();
|
||||||
for (const t of tc.tests) {
|
const suites = testClasses.map(testClass => {
|
||||||
if (t.error) {
|
const tests = testClass.tests.map(test => {
|
||||||
const src = exceptionThrowSource(t.error.StackTrace[0], workDir, trackedFiles);
|
const error = this.getError(test);
|
||||||
if (src === null) {
|
return new test_results_1.TestCaseResult(test.name, test.result, test.duration, error);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
annotations.push({
|
|
||||||
annotation_level: 'failure',
|
|
||||||
start_line: src.line,
|
|
||||||
end_line: src.line,
|
|
||||||
path: src.file,
|
|
||||||
message: markdown_utils_1.fixEol(t.error.Message[0]),
|
|
||||||
title: `[${tc.name}] ${t.name}`
|
|
||||||
});
|
});
|
||||||
|
const group = new test_results_1.TestGroupResult(null, tests);
|
||||||
|
return new test_results_1.TestSuiteResult(testClass.name, [group]);
|
||||||
|
});
|
||||||
|
return new test_results_1.TestRunResult(path, suites, totalTime);
|
||||||
}
|
}
|
||||||
|
getError(test) {
|
||||||
|
if (!this.options.parseErrors || !test.error) {
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
const message = test.error.Message[0];
|
||||||
|
const stackTrace = test.error.StackTrace[0];
|
||||||
|
let path;
|
||||||
|
let line;
|
||||||
|
const src = this.exceptionThrowSource(stackTrace);
|
||||||
|
if (src) {
|
||||||
|
path = src.path;
|
||||||
|
line = src.line;
|
||||||
}
|
}
|
||||||
return annotations;
|
return {
|
||||||
|
path,
|
||||||
|
line,
|
||||||
|
message,
|
||||||
|
stackTrace: `${message}\n${stackTrace}`
|
||||||
|
};
|
||||||
}
|
}
|
||||||
function exceptionThrowSource(ex, workDir, trackedFiles) {
|
exceptionThrowSource(stackTrace) {
|
||||||
const lines = ex.split(/\r*\n/);
|
const lines = stackTrace.split(/\r*\n/);
|
||||||
const re = / in (.+):line (\d+)$/;
|
const re = / in (.+):line (\d+)$/;
|
||||||
|
const { workDir, trackedFiles } = this.options;
|
||||||
for (const str of lines) {
|
for (const str of lines) {
|
||||||
const match = str.match(re);
|
const match = str.match(re);
|
||||||
if (match !== null) {
|
if (match !== null) {
|
||||||
|
|
@ -558,13 +559,13 @@ function exceptionThrowSource(ex, workDir, trackedFiles) {
|
||||||
const file = filePath.startsWith(workDir) ? filePath.substr(workDir.length) : filePath;
|
const file = filePath.startsWith(workDir) ? filePath.substr(workDir.length) : filePath;
|
||||||
if (trackedFiles.includes(file)) {
|
if (trackedFiles.includes(file)) {
|
||||||
const line = parseInt(lineStr);
|
const line = parseInt(lineStr);
|
||||||
return { file, line };
|
return { path: file, line };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
exports.exceptionThrowSource = exceptionThrowSource;
|
}
|
||||||
|
exports.DotnetTrxParser = DotnetTrxParser;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
@ -594,47 +595,39 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.exceptionThrowSource = exports.parseJestJunit = void 0;
|
exports.JestJunitParser = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const xml2js_1 = __nccwpck_require__(6189);
|
const xml2js_1 = __nccwpck_require__(6189);
|
||||||
const markdown_utils_1 = __nccwpck_require__(6482);
|
|
||||||
const file_utils_1 = __nccwpck_require__(2711);
|
const file_utils_1 = __nccwpck_require__(2711);
|
||||||
const test_results_1 = __nccwpck_require__(8407);
|
const test_results_1 = __nccwpck_require__(2768);
|
||||||
async function parseJestJunit(files, options) {
|
class JestJunitParser {
|
||||||
const junit = [];
|
constructor(options) {
|
||||||
const testRuns = [];
|
this.options = options;
|
||||||
for (const file of files) {
|
|
||||||
const ju = await getJunitReport(file);
|
|
||||||
const tr = getTestRunResult(file.path, ju);
|
|
||||||
junit.push(ju);
|
|
||||||
testRuns.push(tr);
|
|
||||||
}
|
}
|
||||||
return {
|
async parse(path, content) {
|
||||||
testRuns,
|
const ju = await this.getJunitReport(path, content);
|
||||||
annotations: options.annotations ? getAnnotations(junit, options.workDir, options.trackedFiles) : []
|
return this.getTestRunResult(path, ju);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
exports.parseJestJunit = parseJestJunit;
|
async getJunitReport(path, content) {
|
||||||
async function getJunitReport(file) {
|
core.info(`Parsing content of '${path}'`);
|
||||||
core.info(`Parsing content of '${file.path}'`);
|
|
||||||
try {
|
try {
|
||||||
return (await xml2js_1.parseStringPromise(file.content));
|
return (await xml2js_1.parseStringPromise(content));
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
throw new Error(`Invalid XML at ${file.path}\n\n${e}`);
|
throw new Error(`Invalid XML at ${path}\n\n${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function getTestRunResult(path, junit) {
|
getTestRunResult(path, junit) {
|
||||||
const suites = junit.testsuites.testsuite.map(ts => {
|
const suites = junit.testsuites.testsuite.map(ts => {
|
||||||
const name = ts.$.name.trim();
|
const name = ts.$.name.trim();
|
||||||
const time = parseFloat(ts.$.time) * 1000;
|
const time = parseFloat(ts.$.time) * 1000;
|
||||||
const sr = new test_results_1.TestSuiteResult(name, getGroups(ts), time);
|
const sr = new test_results_1.TestSuiteResult(name, this.getGroups(ts), time);
|
||||||
return sr;
|
return sr;
|
||||||
});
|
});
|
||||||
const time = parseFloat(junit.testsuites.$.time) * 1000;
|
const time = parseFloat(junit.testsuites.$.time) * 1000;
|
||||||
return new test_results_1.TestRunResult(path, suites, time);
|
return new test_results_1.TestRunResult(path, suites, time);
|
||||||
}
|
}
|
||||||
function getGroups(suite) {
|
getGroups(suite) {
|
||||||
const groups = [];
|
const groups = [];
|
||||||
for (const tc of suite.testcase) {
|
for (const tc of suite.testcase) {
|
||||||
let grp = groups.find(g => g.describe === tc.$.classname);
|
let grp = groups.find(g => g.describe === tc.$.classname);
|
||||||
|
|
@ -647,66 +640,149 @@ function getGroups(suite) {
|
||||||
return groups.map(grp => {
|
return groups.map(grp => {
|
||||||
const tests = grp.tests.map(tc => {
|
const tests = grp.tests.map(tc => {
|
||||||
const name = tc.$.name.trim();
|
const name = tc.$.name.trim();
|
||||||
const result = getTestCaseResult(tc);
|
const result = this.getTestCaseResult(tc);
|
||||||
const time = parseFloat(tc.$.time) * 1000;
|
const time = parseFloat(tc.$.time) * 1000;
|
||||||
return new test_results_1.TestCaseResult(name, result, time);
|
const error = this.getTestCaseError(tc);
|
||||||
|
return new test_results_1.TestCaseResult(name, result, time, error);
|
||||||
});
|
});
|
||||||
return new test_results_1.TestGroupResult(grp.describe, tests);
|
return new test_results_1.TestGroupResult(grp.describe, tests);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getTestCaseResult(test) {
|
getTestCaseResult(test) {
|
||||||
if (test.failure)
|
if (test.failure)
|
||||||
return 'failed';
|
return 'failed';
|
||||||
if (test.skipped)
|
if (test.skipped)
|
||||||
return 'skipped';
|
return 'skipped';
|
||||||
return 'success';
|
return 'success';
|
||||||
}
|
}
|
||||||
function getAnnotations(junitReports, workDir, trackedFiles) {
|
getTestCaseError(tc) {
|
||||||
const annotations = [];
|
if (!this.options.parseErrors || !tc.failure) {
|
||||||
for (const junit of junitReports) {
|
return undefined;
|
||||||
for (const suite of junit.testsuites.testsuite) {
|
}
|
||||||
for (const tc of suite.testcase) {
|
const stackTrace = tc.failure[0];
|
||||||
if (!tc.failure) {
|
let path;
|
||||||
|
let line;
|
||||||
|
const src = this.exceptionThrowSource(stackTrace);
|
||||||
|
if (src) {
|
||||||
|
path = src.path;
|
||||||
|
line = src.line;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
path,
|
||||||
|
line,
|
||||||
|
stackTrace
|
||||||
|
};
|
||||||
|
}
|
||||||
|
exceptionThrowSource(stackTrace) {
|
||||||
|
const lines = stackTrace.split(/\r?\n/);
|
||||||
|
const re = /\((.*):(\d+):\d+\)$/;
|
||||||
|
const { workDir, trackedFiles } = this.options;
|
||||||
|
for (const str of lines) {
|
||||||
|
const match = str.match(re);
|
||||||
|
if (match !== null) {
|
||||||
|
const [_, fileStr, lineStr] = match;
|
||||||
|
const filePath = file_utils_1.normalizeFilePath(fileStr);
|
||||||
|
const path = filePath.startsWith(workDir) ? filePath.substr(workDir.length) : filePath;
|
||||||
|
if (trackedFiles.includes(path)) {
|
||||||
|
const line = parseInt(lineStr);
|
||||||
|
return { path, line };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.JestJunitParser = JestJunitParser;
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 5867:
|
||||||
|
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
|
exports.getAnnotations = void 0;
|
||||||
|
const markdown_utils_1 = __nccwpck_require__(6482);
|
||||||
|
function getAnnotations(results, maxCount) {
|
||||||
|
var _a, _b, _c, _d;
|
||||||
|
if (maxCount === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
// Collect errors from TestRunResults
|
||||||
|
// Merge duplicates if there are more test results files processed
|
||||||
|
const errors = [];
|
||||||
|
const mergeDup = results.length > 1;
|
||||||
|
for (const tr of results) {
|
||||||
|
for (const ts of tr.suites) {
|
||||||
|
for (const tg of ts.groups) {
|
||||||
|
for (const tc of tg.tests) {
|
||||||
|
const err = tc.error;
|
||||||
|
if (err === undefined) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (const ex of tc.failure) {
|
const path = (_a = err.path) !== null && _a !== void 0 ? _a : tr.path;
|
||||||
const src = exceptionThrowSource(ex, workDir, trackedFiles);
|
const line = (_b = err.line) !== null && _b !== void 0 ? _b : 0;
|
||||||
if (src === null) {
|
if (mergeDup) {
|
||||||
|
const dup = errors.find(e => path === e.path && line === e.line && err.stackTrace === e.stackTrace);
|
||||||
|
if (dup !== undefined) {
|
||||||
|
dup.testRunPaths.push(tr.path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
annotations.push({
|
}
|
||||||
annotation_level: 'failure',
|
errors.push({
|
||||||
start_line: src.line,
|
testRunPaths: [tr.path],
|
||||||
end_line: src.line,
|
suiteName: ts.name,
|
||||||
path: src.file,
|
testName: tc.name,
|
||||||
message: markdown_utils_1.fixEol(ex),
|
stackTrace: err.stackTrace,
|
||||||
title: `[${suite.$.name}] ${tc.$.name.trim()}`
|
message: (_d = (_c = err.message) !== null && _c !== void 0 ? _c : getFirstNonEmptyLine(err.stackTrace)) !== null && _d !== void 0 ? _d : 'Test failed',
|
||||||
|
path,
|
||||||
|
line
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Limit number of created annotations
|
||||||
|
errors.splice(maxCount + 1);
|
||||||
|
const annotations = errors.map(e => {
|
||||||
|
const message = [
|
||||||
|
'Failed test found in:',
|
||||||
|
e.testRunPaths.map(p => ` ${p}`).join('\n'),
|
||||||
|
'Error:',
|
||||||
|
ident(markdown_utils_1.fixEol(e.message), ' ')
|
||||||
|
].join('\n');
|
||||||
|
return enforceCheckRunLimits({
|
||||||
|
path: e.path,
|
||||||
|
start_line: e.line,
|
||||||
|
end_line: e.line,
|
||||||
|
annotation_level: 'failure',
|
||||||
|
title: `${e.suiteName} ► ${e.testName}`,
|
||||||
|
raw_details: markdown_utils_1.fixEol(e.stackTrace),
|
||||||
|
message
|
||||||
|
});
|
||||||
|
});
|
||||||
return annotations;
|
return annotations;
|
||||||
}
|
}
|
||||||
function exceptionThrowSource(ex, workDir, trackedFiles) {
|
exports.getAnnotations = getAnnotations;
|
||||||
const lines = ex.split(/\r?\n/);
|
function enforceCheckRunLimits(err) {
|
||||||
const re = /\((.*):(\d+):(\d+)\)$/;
|
err.title = markdown_utils_1.ellipsis(err.title || '', 255);
|
||||||
for (const str of lines) {
|
err.message = markdown_utils_1.ellipsis(err.message, 65535);
|
||||||
const match = str.match(re);
|
if (err.raw_details) {
|
||||||
if (match !== null) {
|
err.raw_details = markdown_utils_1.ellipsis(err.raw_details, 65535);
|
||||||
const [_, fileStr, lineStr, colStr] = match;
|
|
||||||
const filePath = file_utils_1.normalizeFilePath(fileStr);
|
|
||||||
const file = filePath.startsWith(workDir) ? filePath.substr(workDir.length) : filePath;
|
|
||||||
if (trackedFiles.includes(file)) {
|
|
||||||
const line = parseInt(lineStr);
|
|
||||||
const column = parseInt(colStr);
|
|
||||||
return { file, line, column };
|
|
||||||
}
|
}
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
function getFirstNonEmptyLine(stackTrace) {
|
||||||
|
const lines = stackTrace.split(/\r?\n/g);
|
||||||
|
return lines.find(str => !/^\s*$/.test(str));
|
||||||
}
|
}
|
||||||
return null;
|
function ident(text, prefix) {
|
||||||
|
return text
|
||||||
|
.split(/\n/g)
|
||||||
|
.map(line => prefix + line)
|
||||||
|
.join('\n');
|
||||||
}
|
}
|
||||||
exports.exceptionThrowSource = exceptionThrowSource;
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
@ -824,7 +900,7 @@ function getSuitesReport(tr, runIndex, options) {
|
||||||
const nameLink = `<a id="${trSlug.id}" href="${trSlug.link}">${tr.path}</a>`;
|
const nameLink = `<a id="${trSlug.id}" href="${trSlug.link}">${tr.path}</a>`;
|
||||||
const icon = getResultIcon(tr.result);
|
const icon = getResultIcon(tr.result);
|
||||||
sections.push(`## ${nameLink} ${icon}`);
|
sections.push(`## ${nameLink} ${icon}`);
|
||||||
const time = `${(tr.time / 1000).toFixed(3)}s`;
|
const time = markdown_utils_1.formatTime(tr.time);
|
||||||
const headingLine2 = `**${tr.tests}** tests were completed in **${time}** with **${tr.passed}** passed, **${tr.failed}** failed and **${tr.skipped}** skipped.`;
|
const headingLine2 = `**${tr.tests}** tests were completed in **${time}** with **${tr.passed}** passed, **${tr.failed}** failed and **${tr.skipped}** skipped.`;
|
||||||
sections.push(headingLine2);
|
sections.push(headingLine2);
|
||||||
const suites = options.listSuites === 'failed' ? tr.failedSuites : tr.suites;
|
const suites = options.listSuites === 'failed' ? tr.failedSuites : tr.suites;
|
||||||
|
|
@ -861,7 +937,8 @@ function getTestsReport(ts, runIndex, suiteIndex, options) {
|
||||||
const tsNameLink = `<a id="${tsSlug.id}" href="${tsSlug.link}">${tsName}</a>`;
|
const tsNameLink = `<a id="${tsSlug.id}" href="${tsSlug.link}">${tsName}</a>`;
|
||||||
const icon = getResultIcon(ts.result);
|
const icon = getResultIcon(ts.result);
|
||||||
sections.push(`### ${tsNameLink} ${icon}`);
|
sections.push(`### ${tsNameLink} ${icon}`);
|
||||||
const headingLine2 = `**${ts.tests}** tests were completed in **${ts.time}ms** with **${ts.passed}** passed, **${ts.failed}** failed and **${ts.skipped}** skipped.`;
|
const tsTime = markdown_utils_1.formatTime(ts.time);
|
||||||
|
const headingLine2 = `**${ts.tests}** tests were completed in **${tsTime}** with **${ts.passed}** passed, **${ts.failed}** failed and **${ts.skipped}** skipped.`;
|
||||||
sections.push(headingLine2);
|
sections.push(headingLine2);
|
||||||
for (const grp of groups) {
|
for (const grp of groups) {
|
||||||
const tests = options.listTests === 'failed' ? grp.failedTests : grp.tests;
|
const tests = options.listTests === 'failed' ? grp.failedTests : grp.tests;
|
||||||
|
|
@ -903,7 +980,7 @@ function getResultIcon(result) {
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 8407:
|
/***/ 2768:
|
||||||
/***/ ((__unused_webpack_module, exports) => {
|
/***/ ((__unused_webpack_module, exports) => {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
@ -996,10 +1073,11 @@ class TestGroupResult {
|
||||||
}
|
}
|
||||||
exports.TestGroupResult = TestGroupResult;
|
exports.TestGroupResult = TestGroupResult;
|
||||||
class TestCaseResult {
|
class TestCaseResult {
|
||||||
constructor(name, result, time) {
|
constructor(name, result, time, error) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.result = result;
|
this.result = result;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
|
this.error = error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.TestCaseResult = TestCaseResult;
|
exports.TestCaseResult = TestCaseResult;
|
||||||
|
|
@ -1140,9 +1218,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.enforceCheckRunLimits = exports.getCheckRunSha = void 0;
|
exports.getCheckRunSha = void 0;
|
||||||
const github = __importStar(__nccwpck_require__(5438));
|
const github = __importStar(__nccwpck_require__(5438));
|
||||||
const markdown_utils_1 = __nccwpck_require__(6482);
|
|
||||||
function getCheckRunSha() {
|
function getCheckRunSha() {
|
||||||
if (github.context.payload.pull_request) {
|
if (github.context.payload.pull_request) {
|
||||||
const pr = github.context.payload.pull_request;
|
const pr = github.context.payload.pull_request;
|
||||||
|
|
@ -1151,16 +1228,6 @@ function getCheckRunSha() {
|
||||||
return github.context.sha;
|
return github.context.sha;
|
||||||
}
|
}
|
||||||
exports.getCheckRunSha = getCheckRunSha;
|
exports.getCheckRunSha = getCheckRunSha;
|
||||||
function enforceCheckRunLimits(result, maxAnnotations) {
|
|
||||||
// Limit number of created annotations
|
|
||||||
result.annotations.splice(maxAnnotations + 1);
|
|
||||||
// Limit number of characters in annotation fields
|
|
||||||
for (const err of result.annotations) {
|
|
||||||
err.title = markdown_utils_1.ellipsis(err.title || '', 255);
|
|
||||||
err.message = markdown_utils_1.ellipsis(err.message, 65535);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.enforceCheckRunLimits = enforceCheckRunLimits;
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
|
||||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
86
src/main.ts
86
src/main.ts
|
|
@ -2,14 +2,19 @@ import * as core from '@actions/core'
|
||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import glob from 'fast-glob'
|
import glob from 'fast-glob'
|
||||||
import {parseDartJson} from './parsers/dart-json/dart-json-parser'
|
|
||||||
import {parseDotnetTrx} from './parsers/dotnet-trx/dotnet-trx-parser'
|
import {ParseOptions, TestParser} from './test-parser'
|
||||||
import {parseJestJunit} from './parsers/jest-junit/jest-junit-parser'
|
import {TestRunResult} from './test-results'
|
||||||
|
import {getAnnotations} from './report/get-annotations'
|
||||||
import {getReport} from './report/get-report'
|
import {getReport} from './report/get-report'
|
||||||
import {FileContent, ParseOptions, ParseTestResult} from './parsers/parser-types'
|
|
||||||
|
import {DartJsonParser} from './parsers/dart-json/dart-json-parser'
|
||||||
|
import {DotnetTrxParser} from './parsers/dotnet-trx/dotnet-trx-parser'
|
||||||
|
import {JestJunitParser} from './parsers/jest-junit/jest-junit-parser'
|
||||||
|
|
||||||
import {normalizeDirPath} from './utils/file-utils'
|
import {normalizeDirPath} from './utils/file-utils'
|
||||||
import {listFiles} from './utils/git'
|
import {listFiles} from './utils/git'
|
||||||
import {enforceCheckRunLimits, getCheckRunSha} from './utils/github-utils'
|
import {getCheckRunSha} from './utils/github-utils'
|
||||||
import {Icon} from './utils/markdown-utils'
|
import {Icon} from './utils/markdown-utils'
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
|
|
@ -56,28 +61,39 @@ async function main(): Promise<void> {
|
||||||
const sha = getCheckRunSha()
|
const sha = getCheckRunSha()
|
||||||
|
|
||||||
// We won't need tracked files if we are not going to create annotations
|
// We won't need tracked files if we are not going to create annotations
|
||||||
const annotations = maxAnnotations > 0
|
const parseErrors = maxAnnotations > 0
|
||||||
const trackedFiles = annotations ? await listFiles() : []
|
const trackedFiles = parseErrors ? await listFiles() : []
|
||||||
|
|
||||||
const opts: ParseOptions = {
|
const options: ParseOptions = {
|
||||||
trackedFiles,
|
trackedFiles,
|
||||||
workDir,
|
workDir,
|
||||||
annotations
|
parseErrors
|
||||||
}
|
}
|
||||||
|
|
||||||
const parser = getParser(reporter)
|
core.info(`Using test report parser '${reporter}'`)
|
||||||
const files = await getFiles(path)
|
const parser = getParser(reporter, options)
|
||||||
|
|
||||||
|
const files = await getFiles(path)
|
||||||
if (files.length === 0) {
|
if (files.length === 0) {
|
||||||
core.setFailed(`No file matches path '${path}'`)
|
core.setFailed(`No file matches path '${path}'`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`Using test report parser '${reporter}'`)
|
const results: TestRunResult[] = []
|
||||||
const result = await parser(files, opts)
|
for (const file of files) {
|
||||||
|
core.info(`Processing test report ${file}`)
|
||||||
|
const content = await fs.promises.readFile(file, {encoding: 'utf8'})
|
||||||
|
const tr = await parser.parse(file, content)
|
||||||
|
results.push(tr)
|
||||||
|
}
|
||||||
|
|
||||||
enforceCheckRunLimits(result, maxAnnotations)
|
core.info('Creating report summary')
|
||||||
const isFailed = result.testRuns.some(tr => tr.result === 'failed')
|
const summary = getReport(results, {listSuites, listTests})
|
||||||
|
|
||||||
|
core.info('Creating annotations')
|
||||||
|
const annotations = getAnnotations(results, maxAnnotations)
|
||||||
|
|
||||||
|
const isFailed = results.some(tr => tr.result === 'failed')
|
||||||
const conclusion = isFailed ? 'failure' : 'success'
|
const conclusion = isFailed ? 'failure' : 'success'
|
||||||
const icon = isFailed ? Icon.fail : Icon.success
|
const icon = isFailed ? Icon.fail : Icon.success
|
||||||
|
|
||||||
|
|
@ -89,45 +105,47 @@ async function main(): Promise<void> {
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
output: {
|
output: {
|
||||||
title: `${name} ${icon}`,
|
title: `${name} ${icon}`,
|
||||||
summary: getReport(result.testRuns, {listSuites, listTests}),
|
summary,
|
||||||
annotations: result.annotations
|
annotations
|
||||||
},
|
},
|
||||||
...github.context.repo
|
...github.context.repo
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const passed = results.reduce((sum, tr) => sum + tr.passed, 0)
|
||||||
|
const failed = results.reduce((sum, tr) => sum + tr.failed, 0)
|
||||||
|
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0)
|
||||||
|
const time = results.reduce((sum, tr) => sum + tr.time, 0)
|
||||||
|
|
||||||
core.setOutput('conclusion', conclusion)
|
core.setOutput('conclusion', conclusion)
|
||||||
|
core.setOutput('passed', passed)
|
||||||
|
core.setOutput('failed', failed)
|
||||||
|
core.setOutput('skipped', skipped)
|
||||||
|
core.setOutput('time', time)
|
||||||
|
|
||||||
if (failOnError && isFailed) {
|
if (failOnError && isFailed) {
|
||||||
core.setFailed(`Failed test has been found and 'fail-on-error' option is set to ${failOnError}`)
|
core.setFailed(`Failed test has been found and 'fail-on-error' option is set to ${failOnError}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getParser(reporter: string): ParseTestResult {
|
function getParser(reporter: string, options: ParseOptions): TestParser {
|
||||||
switch (reporter) {
|
switch (reporter) {
|
||||||
case 'dart-json':
|
case 'dart-json':
|
||||||
return parseDartJson
|
return new DartJsonParser(options)
|
||||||
case 'dotnet-trx':
|
case 'dotnet-trx':
|
||||||
return parseDotnetTrx
|
return new DotnetTrxParser(options)
|
||||||
case 'flutter-machine':
|
case 'flutter-machine':
|
||||||
return parseDartJson
|
return new DartJsonParser(options)
|
||||||
case 'jest-junit':
|
case 'jest-junit':
|
||||||
return parseJestJunit
|
return new JestJunitParser(options)
|
||||||
default:
|
default:
|
||||||
throw new Error(`Input variable 'reporter' is set to invalid value '${reporter}'`)
|
throw new Error(`Input variable 'reporter' is set to invalid value '${reporter}'`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getFiles(pattern: string): Promise<FileContent[]> {
|
export async function getFiles(pattern: string): Promise<string[]> {
|
||||||
const paths = (await Promise.all(pattern.split(',').map(async pat => glob(pat, {dot: true})))).flat()
|
const tasks = pattern.split(',').map(async pat => glob(pat, {dot: true}))
|
||||||
|
const paths = await Promise.all(tasks)
|
||||||
const files = Promise.all(
|
return paths.flat()
|
||||||
paths.map(async path => {
|
|
||||||
core.info(`Reading test report '${path}'`)
|
|
||||||
const content = await fs.promises.readFile(path, {encoding: 'utf8'})
|
|
||||||
return {path, content}
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
return files
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {Annotation, FileContent, ParseOptions, TestResult} from '../parser-types'
|
import {ParseOptions, TestParser} from '../../test-parser'
|
||||||
|
|
||||||
import {normalizeFilePath} from '../../utils/file-utils'
|
import {normalizeFilePath} from '../../utils/file-utils'
|
||||||
import {fixEol} from '../../utils/markdown-utils'
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ReportEvent,
|
ReportEvent,
|
||||||
|
|
@ -24,8 +23,9 @@ import {
|
||||||
TestRunResult,
|
TestRunResult,
|
||||||
TestSuiteResult,
|
TestSuiteResult,
|
||||||
TestGroupResult,
|
TestGroupResult,
|
||||||
TestCaseResult
|
TestCaseResult,
|
||||||
} from '../../report/test-results'
|
TestCaseError
|
||||||
|
} from '../../test-results'
|
||||||
|
|
||||||
class TestRun {
|
class TestRun {
|
||||||
constructor(readonly path: string, readonly suites: TestSuite[], readonly success: boolean, readonly time: number) {}
|
constructor(readonly path: string, readonly suites: TestSuite[], readonly success: boolean, readonly time: number) {}
|
||||||
|
|
@ -68,17 +68,16 @@ class TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function parseDartJson(files: FileContent[], options: ParseOptions): Promise<TestResult> {
|
export class DartJsonParser implements TestParser {
|
||||||
const testRuns = files.map(f => getTestRun(f.path, f.content))
|
constructor(readonly options: ParseOptions) {}
|
||||||
const testRunsResults = testRuns.map(getTestRunResult)
|
|
||||||
|
|
||||||
return {
|
async parse(path: string, content: string): Promise<TestRunResult> {
|
||||||
testRuns: testRunsResults,
|
const tr = this.getTestRun(path, content)
|
||||||
annotations: options.annotations ? getAnnotations(testRuns, options.workDir, options.trackedFiles) : []
|
const result = this.getTestRunResult(tr)
|
||||||
}
|
return Promise.resolve(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTestRun(path: string, content: string): TestRun {
|
private getTestRun(path: string, content: string): TestRun {
|
||||||
core.info(`Parsing content of '${path}'`)
|
core.info(`Parsing content of '${path}'`)
|
||||||
const lines = content.split(/\n\r?/g)
|
const lines = content.split(/\n\r?/g)
|
||||||
const events = lines
|
const events = lines
|
||||||
|
|
@ -124,75 +123,61 @@ function getTestRun(path: string, content: string): TestRun {
|
||||||
return new TestRun(path, Object.values(suites), success, totalTime)
|
return new TestRun(path, Object.values(suites), success, totalTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTestRunResult(tr: TestRun): TestRunResult {
|
private getTestRunResult(tr: TestRun): TestRunResult {
|
||||||
const suites = tr.suites.map(s => {
|
const suites = tr.suites.map(s => {
|
||||||
return new TestSuiteResult(s.suite.path, getGroups(s))
|
return new TestSuiteResult(s.suite.path, this.getGroups(s))
|
||||||
})
|
})
|
||||||
|
|
||||||
return new TestRunResult(tr.path, suites, tr.time)
|
return new TestRunResult(tr.path, suites, tr.time)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGroups(suite: TestSuite): TestGroupResult[] {
|
private getGroups(suite: TestSuite): TestGroupResult[] {
|
||||||
const groups = Object.values(suite.groups).filter(grp => grp.tests.length > 0)
|
const groups = Object.values(suite.groups).filter(grp => grp.tests.length > 0)
|
||||||
groups.sort((a, b) => (a.group.line ?? 0) - (b.group.line ?? 0))
|
groups.sort((a, b) => (a.group.line ?? 0) - (b.group.line ?? 0))
|
||||||
|
|
||||||
return groups.map(group => {
|
return groups.map(group => {
|
||||||
group.tests.sort((a, b) => (a.testStart.test.line ?? 0) - (b.testStart.test.line ?? 0))
|
group.tests.sort((a, b) => (a.testStart.test.line ?? 0) - (b.testStart.test.line ?? 0))
|
||||||
const tests = group.tests.map(t => new TestCaseResult(t.testStart.test.name, t.result, t.time))
|
const tests = group.tests.map(t => this.getTest(t))
|
||||||
return new TestGroupResult(group.group.name, tests)
|
return new TestGroupResult(group.group.name, tests)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAnnotations(testRuns: TestRun[], workDir: string, trackedFiles: string[]): Annotation[] {
|
private getTest(tc: TestCase): TestCaseResult {
|
||||||
const annotations: Annotation[] = []
|
const error = this.getError(tc)
|
||||||
for (const tr of testRuns) {
|
return new TestCaseResult(tc.testStart.test.name, tc.result, tc.time, error)
|
||||||
for (const suite of tr.suites) {
|
|
||||||
for (const group of Object.values(suite.groups)) {
|
|
||||||
for (const test of group.tests) {
|
|
||||||
if (test.error) {
|
|
||||||
const err = getAnnotation(test, suite, workDir, trackedFiles)
|
|
||||||
if (err !== null) {
|
|
||||||
annotations.push(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return annotations
|
private getError(test: TestCase): TestCaseError | undefined {
|
||||||
|
if (!this.options.parseErrors || !test.error) {
|
||||||
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAnnotation(
|
const {workDir, trackedFiles} = this.options
|
||||||
test: TestCase,
|
const message = test.error?.error ?? ''
|
||||||
testSuite: TestSuite,
|
const stackTrace = test.error?.stackTrace ?? ''
|
||||||
workDir: string,
|
const src = this.exceptionThrowSource(stackTrace, trackedFiles)
|
||||||
trackedFiles: string[]
|
let path
|
||||||
): Annotation | null {
|
let line
|
||||||
const stack = test.error?.stackTrace ?? ''
|
|
||||||
let src = exceptionThrowSource(stack, trackedFiles)
|
if (src !== undefined) {
|
||||||
if (src === null) {
|
;(path = src.path), (line = src.line)
|
||||||
const file = getRelativePathFromUrl(test.testStart.test.url ?? '', workDir)
|
} else {
|
||||||
if (!trackedFiles.includes(file)) {
|
const testStartPath = this.getRelativePathFromUrl(test.testStart.test.url ?? '', workDir)
|
||||||
return null
|
if (trackedFiles.includes(testStartPath)) {
|
||||||
}
|
path = testStartPath
|
||||||
src = {
|
|
||||||
file,
|
|
||||||
line: test.testStart.test.line ?? 0
|
|
||||||
}
|
}
|
||||||
|
line = test.testStart.test.line ?? undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
annotation_level: 'failure',
|
path,
|
||||||
start_line: src.line,
|
line,
|
||||||
end_line: src.line,
|
message,
|
||||||
path: src.file,
|
stackTrace
|
||||||
message: `${fixEol(test.error?.error)}\n\n${fixEol(test.error?.stackTrace)}`,
|
|
||||||
title: `[${testSuite.suite.path}] ${test.testStart.test.name}`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function exceptionThrowSource(ex: string, trackedFiles: string[]): {file: string; line: number} | null {
|
private exceptionThrowSource(ex: string, trackedFiles: string[]): {path: string; line: number} | undefined {
|
||||||
// imports from package which is tested are listed in stack traces as 'package:xyz/' which maps to relative path 'lib/'
|
// imports from package which is tested are listed in stack traces as 'package:xyz/' which maps to relative path 'lib/'
|
||||||
const packageRe = /^package:[a-zA-z0-9_$]+\//
|
const packageRe = /^package:[a-zA-z0-9_$]+\//
|
||||||
const lines = ex.split(/\r?\n/).map(str => str.replace(packageRe, 'lib/'))
|
const lines = ex.split(/\r?\n/).map(str => str.replace(packageRe, 'lib/'))
|
||||||
|
|
@ -202,25 +187,24 @@ function exceptionThrowSource(ex: string, trackedFiles: string[]): {file: string
|
||||||
for (const str of lines) {
|
for (const str of lines) {
|
||||||
const match = str.match(re)
|
const match = str.match(re)
|
||||||
if (match !== null) {
|
if (match !== null) {
|
||||||
const [_, fileStr, lineStr] = match
|
const [_, pathStr, lineStr] = match
|
||||||
const file = normalizeFilePath(fileStr)
|
const path = normalizeFilePath(pathStr)
|
||||||
if (trackedFiles.includes(file)) {
|
if (trackedFiles.includes(path)) {
|
||||||
const line = parseInt(lineStr)
|
const line = parseInt(lineStr)
|
||||||
return {file, line}
|
return {path, line}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
private getRelativePathFromUrl(file: string, workDir: string): string {
|
||||||
}
|
|
||||||
|
|
||||||
function getRelativePathFromUrl(file: string, workdir: string): string {
|
|
||||||
const prefix = 'file:///'
|
const prefix = 'file:///'
|
||||||
if (file.startsWith(prefix)) {
|
if (file.startsWith(prefix)) {
|
||||||
file = file.substr(prefix.length)
|
file = file.substr(prefix.length)
|
||||||
}
|
}
|
||||||
if (file.startsWith(workdir)) {
|
if (file.startsWith(workDir)) {
|
||||||
file = file.substr(workdir.length)
|
file = file.substr(workDir.length)
|
||||||
}
|
}
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {ErrorInfo, Outcome, TestMethod, TrxReport} from './dotnet-trx-types'
|
|
||||||
|
|
||||||
import {Annotation, FileContent, ParseOptions, TestResult} from '../parser-types'
|
|
||||||
import {parseStringPromise} from 'xml2js'
|
import {parseStringPromise} from 'xml2js'
|
||||||
|
|
||||||
|
import {ErrorInfo, Outcome, TestMethod, TrxReport} from './dotnet-trx-types'
|
||||||
|
import {ParseOptions, TestParser} from '../../test-parser'
|
||||||
|
|
||||||
import {normalizeFilePath} from '../../utils/file-utils'
|
import {normalizeFilePath} from '../../utils/file-utils'
|
||||||
import {fixEol} from '../../utils/markdown-utils'
|
|
||||||
import {parseIsoDate, parseNetDuration} from '../../utils/parse-utils'
|
import {parseIsoDate, parseNetDuration} from '../../utils/parse-utils'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
@ -13,8 +12,9 @@ import {
|
||||||
TestRunResult,
|
TestRunResult,
|
||||||
TestSuiteResult,
|
TestSuiteResult,
|
||||||
TestGroupResult,
|
TestGroupResult,
|
||||||
TestCaseResult
|
TestCaseResult,
|
||||||
} from '../../report/test-results'
|
TestCaseError
|
||||||
|
} from '../../test-results'
|
||||||
|
|
||||||
class TestClass {
|
class TestClass {
|
||||||
constructor(readonly name: string) {}
|
constructor(readonly name: string) {}
|
||||||
|
|
@ -41,47 +41,26 @@ class Test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function parseDotnetTrx(files: FileContent[], options: ParseOptions): Promise<TestResult> {
|
export class DotnetTrxParser implements TestParser {
|
||||||
const testRuns: TestRunResult[] = []
|
constructor(readonly options: ParseOptions) {}
|
||||||
const testClasses: TestClass[] = []
|
|
||||||
|
|
||||||
for (const file of files) {
|
async parse(path: string, content: string): Promise<TestRunResult> {
|
||||||
const trx = await getTrxReport(file)
|
const trx = await this.getTrxReport(path, content)
|
||||||
const tc = getTestClasses(trx)
|
const tc = this.getTestClasses(trx)
|
||||||
const tr = getTestRunResult(file.path, trx, tc)
|
const tr = this.getTestRunResult(path, trx, tc)
|
||||||
testRuns.push(tr)
|
return tr
|
||||||
testClasses.push(...tc)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
private async getTrxReport(path: string, content: string): Promise<TrxReport> {
|
||||||
testRuns,
|
core.info(`Parsing content of '${path}'`)
|
||||||
annotations: options.annotations ? getAnnotations(testClasses, options.workDir, options.trackedFiles) : []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getTrxReport(file: FileContent): Promise<TrxReport> {
|
|
||||||
core.info(`Parsing content of '${file.path}'`)
|
|
||||||
try {
|
try {
|
||||||
return (await parseStringPromise(file.content)) as TrxReport
|
return (await parseStringPromise(content)) as TrxReport
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Invalid XML at ${file.path}\n\n${e}`)
|
throw new Error(`Invalid XML at ${path}\n\n${e}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTestRunResult(path: string, trx: TrxReport, testClasses: TestClass[]): TestRunResult {
|
private getTestClasses(trx: TrxReport): TestClass[] {
|
||||||
const times = trx.TestRun.Times[0].$
|
|
||||||
const totalTime = parseIsoDate(times.finish).getTime() - parseIsoDate(times.start).getTime()
|
|
||||||
|
|
||||||
const suites = testClasses.map(tc => {
|
|
||||||
const tests = tc.tests.map(t => new TestCaseResult(t.name, t.result, t.duration))
|
|
||||||
const group = new TestGroupResult(null, tests)
|
|
||||||
return new TestSuiteResult(tc.name, [group])
|
|
||||||
})
|
|
||||||
|
|
||||||
return new TestRunResult(path, suites, totalTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTestClasses(trx: TrxReport): TestClass[] {
|
|
||||||
const unitTests: {[id: string]: TestMethod} = {}
|
const unitTests: {[id: string]: TestMethod} = {}
|
||||||
for (const td of trx.TestRun.TestDefinitions) {
|
for (const td of trx.TestRun.TestDefinitions) {
|
||||||
for (const ut of td.UnitTest) {
|
for (const ut of td.UnitTest) {
|
||||||
|
|
@ -117,36 +96,50 @@ function getTestClasses(trx: TrxReport): TestClass[] {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAnnotations(testClasses: TestClass[], workDir: string, trackedFiles: string[]): Annotation[] {
|
private getTestRunResult(path: string, trx: TrxReport, testClasses: TestClass[]): TestRunResult {
|
||||||
const annotations: Annotation[] = []
|
const times = trx.TestRun.Times[0].$
|
||||||
for (const tc of testClasses) {
|
const totalTime = parseIsoDate(times.finish).getTime() - parseIsoDate(times.start).getTime()
|
||||||
for (const t of tc.tests) {
|
|
||||||
if (t.error) {
|
const suites = testClasses.map(testClass => {
|
||||||
const src = exceptionThrowSource(t.error.StackTrace[0], workDir, trackedFiles)
|
const tests = testClass.tests.map(test => {
|
||||||
if (src === null) {
|
const error = this.getError(test)
|
||||||
continue
|
return new TestCaseResult(test.name, test.result, test.duration, error)
|
||||||
}
|
|
||||||
annotations.push({
|
|
||||||
annotation_level: 'failure',
|
|
||||||
start_line: src.line,
|
|
||||||
end_line: src.line,
|
|
||||||
path: src.file,
|
|
||||||
message: fixEol(t.error.Message[0]),
|
|
||||||
title: `[${tc.name}] ${t.name}`
|
|
||||||
})
|
})
|
||||||
}
|
const group = new TestGroupResult(null, tests)
|
||||||
}
|
return new TestSuiteResult(testClass.name, [group])
|
||||||
}
|
})
|
||||||
return annotations
|
|
||||||
|
return new TestRunResult(path, suites, totalTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function exceptionThrowSource(
|
private getError(test: Test): TestCaseError | undefined {
|
||||||
ex: string,
|
if (!this.options.parseErrors || !test.error) {
|
||||||
workDir: string,
|
return undefined
|
||||||
trackedFiles: string[]
|
}
|
||||||
): {file: string; line: number} | null {
|
|
||||||
const lines = ex.split(/\r*\n/)
|
const message = test.error.Message[0]
|
||||||
|
const stackTrace = test.error.StackTrace[0]
|
||||||
|
let path
|
||||||
|
let line
|
||||||
|
|
||||||
|
const src = this.exceptionThrowSource(stackTrace)
|
||||||
|
if (src) {
|
||||||
|
path = src.path
|
||||||
|
line = src.line
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
path,
|
||||||
|
line,
|
||||||
|
message,
|
||||||
|
stackTrace: `${message}\n${stackTrace}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private exceptionThrowSource(stackTrace: string): {path: string; line: number} | undefined {
|
||||||
|
const lines = stackTrace.split(/\r*\n/)
|
||||||
const re = / in (.+):line (\d+)$/
|
const re = / in (.+):line (\d+)$/
|
||||||
|
const {workDir, trackedFiles} = this.options
|
||||||
|
|
||||||
for (const str of lines) {
|
for (const str of lines) {
|
||||||
const match = str.match(re)
|
const match = str.match(re)
|
||||||
|
|
@ -156,10 +149,9 @@ export function exceptionThrowSource(
|
||||||
const file = filePath.startsWith(workDir) ? filePath.substr(workDir.length) : filePath
|
const file = filePath.startsWith(workDir) ? filePath.substr(workDir.length) : filePath
|
||||||
if (trackedFiles.includes(file)) {
|
if (trackedFiles.includes(file)) {
|
||||||
const line = parseInt(lineStr)
|
const line = parseInt(lineStr)
|
||||||
return {file, line}
|
return {path: file, line}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {Annotation, FileContent, ParseOptions, TestResult} from '../parser-types'
|
import {ParseOptions, TestParser} from '../../test-parser'
|
||||||
import {parseStringPromise} from 'xml2js'
|
import {parseStringPromise} from 'xml2js'
|
||||||
|
|
||||||
import {JunitReport, TestCase, TestSuite} from './jest-junit-types'
|
import {JunitReport, TestCase, TestSuite} from './jest-junit-types'
|
||||||
import {fixEol} from '../../utils/markdown-utils'
|
|
||||||
import {normalizeFilePath} from '../../utils/file-utils'
|
import {normalizeFilePath} from '../../utils/file-utils'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
@ -11,40 +10,32 @@ import {
|
||||||
TestRunResult,
|
TestRunResult,
|
||||||
TestSuiteResult,
|
TestSuiteResult,
|
||||||
TestGroupResult,
|
TestGroupResult,
|
||||||
TestCaseResult
|
TestCaseResult,
|
||||||
} from '../../report/test-results'
|
TestCaseError
|
||||||
|
} from '../../test-results'
|
||||||
|
|
||||||
export async function parseJestJunit(files: FileContent[], options: ParseOptions): Promise<TestResult> {
|
export class JestJunitParser implements TestParser {
|
||||||
const junit: JunitReport[] = []
|
constructor(readonly options: ParseOptions) {}
|
||||||
const testRuns: TestRunResult[] = []
|
|
||||||
|
|
||||||
for (const file of files) {
|
async parse(path: string, content: string): Promise<TestRunResult> {
|
||||||
const ju = await getJunitReport(file)
|
const ju = await this.getJunitReport(path, content)
|
||||||
const tr = getTestRunResult(file.path, ju)
|
return this.getTestRunResult(path, ju)
|
||||||
junit.push(ju)
|
|
||||||
testRuns.push(tr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
private async getJunitReport(path: string, content: string): Promise<JunitReport> {
|
||||||
testRuns,
|
core.info(`Parsing content of '${path}'`)
|
||||||
annotations: options.annotations ? getAnnotations(junit, options.workDir, options.trackedFiles) : []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getJunitReport(file: FileContent): Promise<JunitReport> {
|
|
||||||
core.info(`Parsing content of '${file.path}'`)
|
|
||||||
try {
|
try {
|
||||||
return (await parseStringPromise(file.content)) as JunitReport
|
return (await parseStringPromise(content)) as JunitReport
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Invalid XML at ${file.path}\n\n${e}`)
|
throw new Error(`Invalid XML at ${path}\n\n${e}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTestRunResult(path: string, junit: JunitReport): TestRunResult {
|
private getTestRunResult(path: string, junit: JunitReport): TestRunResult {
|
||||||
const suites = junit.testsuites.testsuite.map(ts => {
|
const suites = junit.testsuites.testsuite.map(ts => {
|
||||||
const name = ts.$.name.trim()
|
const name = ts.$.name.trim()
|
||||||
const time = parseFloat(ts.$.time) * 1000
|
const time = parseFloat(ts.$.time) * 1000
|
||||||
const sr = new TestSuiteResult(name, getGroups(ts), time)
|
const sr = new TestSuiteResult(name, this.getGroups(ts), time)
|
||||||
return sr
|
return sr
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -52,7 +43,7 @@ function getTestRunResult(path: string, junit: JunitReport): TestRunResult {
|
||||||
return new TestRunResult(path, suites, time)
|
return new TestRunResult(path, suites, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGroups(suite: TestSuite): TestGroupResult[] {
|
private getGroups(suite: TestSuite): TestGroupResult[] {
|
||||||
const groups: {describe: string; tests: TestCase[]}[] = []
|
const groups: {describe: string; tests: TestCase[]}[] = []
|
||||||
for (const tc of suite.testcase) {
|
for (const tc of suite.testcase) {
|
||||||
let grp = groups.find(g => g.describe === tc.$.classname)
|
let grp = groups.find(g => g.describe === tc.$.classname)
|
||||||
|
|
@ -66,69 +57,60 @@ function getGroups(suite: TestSuite): TestGroupResult[] {
|
||||||
return groups.map(grp => {
|
return groups.map(grp => {
|
||||||
const tests = grp.tests.map(tc => {
|
const tests = grp.tests.map(tc => {
|
||||||
const name = tc.$.name.trim()
|
const name = tc.$.name.trim()
|
||||||
const result = getTestCaseResult(tc)
|
const result = this.getTestCaseResult(tc)
|
||||||
const time = parseFloat(tc.$.time) * 1000
|
const time = parseFloat(tc.$.time) * 1000
|
||||||
return new TestCaseResult(name, result, time)
|
const error = this.getTestCaseError(tc)
|
||||||
|
return new TestCaseResult(name, result, time, error)
|
||||||
})
|
})
|
||||||
return new TestGroupResult(grp.describe, tests)
|
return new TestGroupResult(grp.describe, tests)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTestCaseResult(test: TestCase): TestExecutionResult {
|
private getTestCaseResult(test: TestCase): TestExecutionResult {
|
||||||
if (test.failure) return 'failed'
|
if (test.failure) return 'failed'
|
||||||
if (test.skipped) return 'skipped'
|
if (test.skipped) return 'skipped'
|
||||||
return 'success'
|
return 'success'
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAnnotations(junitReports: JunitReport[], workDir: string, trackedFiles: string[]): Annotation[] {
|
private getTestCaseError(tc: TestCase): TestCaseError | undefined {
|
||||||
const annotations: Annotation[] = []
|
if (!this.options.parseErrors || !tc.failure) {
|
||||||
for (const junit of junitReports) {
|
return undefined
|
||||||
for (const suite of junit.testsuites.testsuite) {
|
|
||||||
for (const tc of suite.testcase) {
|
|
||||||
if (!tc.failure) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for (const ex of tc.failure) {
|
|
||||||
const src = exceptionThrowSource(ex, workDir, trackedFiles)
|
|
||||||
if (src === null) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
annotations.push({
|
|
||||||
annotation_level: 'failure',
|
|
||||||
start_line: src.line,
|
|
||||||
end_line: src.line,
|
|
||||||
path: src.file,
|
|
||||||
message: fixEol(ex),
|
|
||||||
title: `[${suite.$.name}] ${tc.$.name.trim()}`
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return annotations
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function exceptionThrowSource(
|
const stackTrace = tc.failure[0]
|
||||||
ex: string,
|
let path
|
||||||
workDir: string,
|
let line
|
||||||
trackedFiles: string[]
|
|
||||||
): {file: string; line: number; column: number} | null {
|
|
||||||
const lines = ex.split(/\r?\n/)
|
|
||||||
const re = /\((.*):(\d+):(\d+)\)$/
|
|
||||||
|
|
||||||
|
const src = this.exceptionThrowSource(stackTrace)
|
||||||
|
if (src) {
|
||||||
|
path = src.path
|
||||||
|
line = src.line
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
path,
|
||||||
|
line,
|
||||||
|
stackTrace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private exceptionThrowSource(stackTrace: string): {path: string; line: number} | undefined {
|
||||||
|
const lines = stackTrace.split(/\r?\n/)
|
||||||
|
const re = /\((.*):(\d+):\d+\)$/
|
||||||
|
|
||||||
|
const {workDir, trackedFiles} = this.options
|
||||||
for (const str of lines) {
|
for (const str of lines) {
|
||||||
const match = str.match(re)
|
const match = str.match(re)
|
||||||
if (match !== null) {
|
if (match !== null) {
|
||||||
const [_, fileStr, lineStr, colStr] = match
|
const [_, fileStr, lineStr] = match
|
||||||
const filePath = normalizeFilePath(fileStr)
|
const filePath = normalizeFilePath(fileStr)
|
||||||
const file = filePath.startsWith(workDir) ? filePath.substr(workDir.length) : filePath
|
const path = filePath.startsWith(workDir) ? filePath.substr(workDir.length) : filePath
|
||||||
if (trackedFiles.includes(file)) {
|
if (trackedFiles.includes(path)) {
|
||||||
const line = parseInt(lineStr)
|
const line = parseInt(lineStr)
|
||||||
const column = parseInt(colStr)
|
|
||||||
return {file, line, column}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
return {path, line}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
import {TestRunResult} from '../report/test-results'
|
|
||||||
|
|
||||||
export type Annotation = {
|
|
||||||
path: string
|
|
||||||
start_line: number
|
|
||||||
end_line: number
|
|
||||||
start_column?: number
|
|
||||||
end_column?: number
|
|
||||||
annotation_level: 'notice' | 'warning' | 'failure'
|
|
||||||
message: string
|
|
||||||
title?: string
|
|
||||||
raw_details?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ParseTestResult = (files: FileContent[], options: ParseOptions) => Promise<TestResult>
|
|
||||||
|
|
||||||
export type FileContent = {path: string; content: string}
|
|
||||||
|
|
||||||
export interface ParseOptions {
|
|
||||||
annotations: boolean
|
|
||||||
workDir: string
|
|
||||||
trackedFiles: string[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TestResult {
|
|
||||||
testRuns: TestRunResult[]
|
|
||||||
annotations: Annotation[]
|
|
||||||
}
|
|
||||||
111
src/report/get-annotations.ts
Normal file
111
src/report/get-annotations.ts
Normal file
|
|
@ -0,0 +1,111 @@
|
||||||
|
import {ellipsis, fixEol} from '../utils/markdown-utils'
|
||||||
|
import {TestRunResult} from '../test-results'
|
||||||
|
|
||||||
|
type Annotation = {
|
||||||
|
path: string
|
||||||
|
start_line: number
|
||||||
|
end_line: number
|
||||||
|
start_column?: number
|
||||||
|
end_column?: number
|
||||||
|
annotation_level: 'notice' | 'warning' | 'failure'
|
||||||
|
message: string
|
||||||
|
title?: string
|
||||||
|
raw_details?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TestError {
|
||||||
|
testRunPaths: string[]
|
||||||
|
suiteName: string
|
||||||
|
testName: string
|
||||||
|
path: string
|
||||||
|
line: number
|
||||||
|
stackTrace: string
|
||||||
|
message: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAnnotations(results: TestRunResult[], maxCount: number): Annotation[] {
|
||||||
|
if (maxCount === 0) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect errors from TestRunResults
|
||||||
|
// Merge duplicates if there are more test results files processed
|
||||||
|
const errors: TestError[] = []
|
||||||
|
const mergeDup = results.length > 1
|
||||||
|
for (const tr of results) {
|
||||||
|
for (const ts of tr.suites) {
|
||||||
|
for (const tg of ts.groups) {
|
||||||
|
for (const tc of tg.tests) {
|
||||||
|
const err = tc.error
|
||||||
|
if (err === undefined) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const path = err.path ?? tr.path
|
||||||
|
const line = err.line ?? 0
|
||||||
|
if (mergeDup) {
|
||||||
|
const dup = errors.find(e => path === e.path && line === e.line && err.stackTrace === e.stackTrace)
|
||||||
|
if (dup !== undefined) {
|
||||||
|
dup.testRunPaths.push(tr.path)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
errors.push({
|
||||||
|
testRunPaths: [tr.path],
|
||||||
|
suiteName: ts.name,
|
||||||
|
testName: tc.name,
|
||||||
|
stackTrace: err.stackTrace,
|
||||||
|
message: err.message ?? getFirstNonEmptyLine(err.stackTrace) ?? 'Test failed',
|
||||||
|
path,
|
||||||
|
line
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit number of created annotations
|
||||||
|
errors.splice(maxCount + 1)
|
||||||
|
|
||||||
|
const annotations = errors.map(e => {
|
||||||
|
const message = [
|
||||||
|
'Failed test found in:',
|
||||||
|
e.testRunPaths.map(p => ` ${p}`).join('\n'),
|
||||||
|
'Error:',
|
||||||
|
ident(fixEol(e.message), ' ')
|
||||||
|
].join('\n')
|
||||||
|
|
||||||
|
return enforceCheckRunLimits({
|
||||||
|
path: e.path,
|
||||||
|
start_line: e.line,
|
||||||
|
end_line: e.line,
|
||||||
|
annotation_level: 'failure',
|
||||||
|
title: `${e.suiteName} ► ${e.testName}`,
|
||||||
|
raw_details: fixEol(e.stackTrace),
|
||||||
|
message
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return annotations
|
||||||
|
}
|
||||||
|
|
||||||
|
function enforceCheckRunLimits(err: Annotation): Annotation {
|
||||||
|
err.title = ellipsis(err.title || '', 255)
|
||||||
|
err.message = ellipsis(err.message, 65535)
|
||||||
|
if (err.raw_details) {
|
||||||
|
err.raw_details = ellipsis(err.raw_details, 65535)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFirstNonEmptyLine(stackTrace: string): string | undefined {
|
||||||
|
const lines = stackTrace.split(/\r?\n/g)
|
||||||
|
return lines.find(str => !/^\s*$/.test(str))
|
||||||
|
}
|
||||||
|
|
||||||
|
function ident(text: string, prefix: string): string {
|
||||||
|
return text
|
||||||
|
.split(/\n/g)
|
||||||
|
.map(line => prefix + line)
|
||||||
|
.join('\n')
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {TestExecutionResult, TestRunResult, TestSuiteResult} from './test-results'
|
import {TestExecutionResult, TestRunResult, TestSuiteResult} from '../test-results'
|
||||||
import {Align, formatTime, Icon, link, table} from '../utils/markdown-utils'
|
import {Align, formatTime, Icon, link, table} from '../utils/markdown-utils'
|
||||||
import {slug} from '../utils/slugger'
|
import {slug} from '../utils/slugger'
|
||||||
|
|
||||||
|
|
@ -112,7 +112,7 @@ function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOpt
|
||||||
const icon = getResultIcon(tr.result)
|
const icon = getResultIcon(tr.result)
|
||||||
sections.push(`## ${nameLink} ${icon}`)
|
sections.push(`## ${nameLink} ${icon}`)
|
||||||
|
|
||||||
const time = `${(tr.time / 1000).toFixed(3)}s`
|
const time = formatTime(tr.time)
|
||||||
const headingLine2 = `**${tr.tests}** tests were completed in **${time}** with **${tr.passed}** passed, **${tr.failed}** failed and **${tr.skipped}** skipped.`
|
const headingLine2 = `**${tr.tests}** tests were completed in **${time}** with **${tr.passed}** passed, **${tr.failed}** failed and **${tr.skipped}** skipped.`
|
||||||
sections.push(headingLine2)
|
sections.push(headingLine2)
|
||||||
|
|
||||||
|
|
@ -161,7 +161,8 @@ function getTestsReport(ts: TestSuiteResult, runIndex: number, suiteIndex: numbe
|
||||||
const icon = getResultIcon(ts.result)
|
const icon = getResultIcon(ts.result)
|
||||||
sections.push(`### ${tsNameLink} ${icon}`)
|
sections.push(`### ${tsNameLink} ${icon}`)
|
||||||
|
|
||||||
const headingLine2 = `**${ts.tests}** tests were completed in **${ts.time}ms** with **${ts.passed}** passed, **${ts.failed}** failed and **${ts.skipped}** skipped.`
|
const tsTime = formatTime(ts.time)
|
||||||
|
const headingLine2 = `**${ts.tests}** tests were completed in **${tsTime}** with **${ts.passed}** passed, **${ts.failed}** failed and **${ts.skipped}** skipped.`
|
||||||
sections.push(headingLine2)
|
sections.push(headingLine2)
|
||||||
|
|
||||||
for (const grp of groups) {
|
for (const grp of groups) {
|
||||||
|
|
|
||||||
11
src/test-parser.ts
Normal file
11
src/test-parser.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import {TestRunResult} from './test-results'
|
||||||
|
|
||||||
|
export interface ParseOptions {
|
||||||
|
parseErrors: boolean
|
||||||
|
workDir: string
|
||||||
|
trackedFiles: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TestParser {
|
||||||
|
parse(path: string, content: string): Promise<TestRunResult>
|
||||||
|
}
|
||||||
|
|
@ -83,7 +83,19 @@ export class TestGroupResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TestCaseResult {
|
export class TestCaseResult {
|
||||||
constructor(readonly name: string, readonly result: TestExecutionResult, readonly time: number) {}
|
constructor(
|
||||||
|
readonly name: string,
|
||||||
|
readonly result: TestExecutionResult,
|
||||||
|
readonly time: number,
|
||||||
|
readonly error?: TestCaseError
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TestExecutionResult = 'success' | 'skipped' | 'failed' | undefined
|
export type TestExecutionResult = 'success' | 'skipped' | 'failed' | undefined
|
||||||
|
|
||||||
|
export interface TestCaseError {
|
||||||
|
path?: string
|
||||||
|
line?: number
|
||||||
|
message?: string
|
||||||
|
stackTrace: string
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
import {EventPayloads} from '@octokit/webhooks'
|
import {EventPayloads} from '@octokit/webhooks'
|
||||||
|
|
||||||
import {TestResult} from '../parsers/parser-types'
|
|
||||||
import {ellipsis} from './markdown-utils'
|
|
||||||
|
|
||||||
export function getCheckRunSha(): string {
|
export function getCheckRunSha(): string {
|
||||||
if (github.context.payload.pull_request) {
|
if (github.context.payload.pull_request) {
|
||||||
const pr = github.context.payload.pull_request as EventPayloads.WebhookPayloadPullRequestPullRequest
|
const pr = github.context.payload.pull_request as EventPayloads.WebhookPayloadPullRequestPullRequest
|
||||||
|
|
@ -12,14 +9,3 @@ export function getCheckRunSha(): string {
|
||||||
|
|
||||||
return github.context.sha
|
return github.context.sha
|
||||||
}
|
}
|
||||||
|
|
||||||
export function enforceCheckRunLimits(result: TestResult, maxAnnotations: number): void {
|
|
||||||
// Limit number of created annotations
|
|
||||||
result.annotations.splice(maxAnnotations + 1)
|
|
||||||
|
|
||||||
// Limit number of characters in annotation fields
|
|
||||||
for (const err of result.annotations) {
|
|
||||||
err.title = ellipsis(err.title || '', 255)
|
|
||||||
err.message = ellipsis(err.message, 65535)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue