mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-17 06:47:09 +01:00
build new dist
This commit is contained in:
parent
1e6f7066d9
commit
484ed7ce5c
5 changed files with 3193 additions and 3306 deletions
|
|
@ -1,69 +1,69 @@
|
||||||
import * as fs from 'fs'
|
// import * as fs from 'fs'
|
||||||
import * as path from 'path'
|
// import * as path from 'path'
|
||||||
|
|
||||||
import {DartJsonParser} from '../src/parsers/dart-json/dart-json-parser'
|
// import {DartJsonParser} from '../src/parsers/dart-json/dart-json-parser'
|
||||||
import {ParseOptions} from '../src/test-parser'
|
// 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/path-utils'
|
// import {normalizeFilePath} from '../src/utils/path-utils'
|
||||||
|
|
||||||
describe('dart-json tests', () => {
|
// describe('dart-json tests', () => {
|
||||||
it('produces empty test run result when there are no test cases', async () => {
|
// it('produces empty test run result when there are no test cases', async () => {
|
||||||
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'dart-json.json')
|
// const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'dart-json.json')
|
||||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
// const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||||
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
// const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||||
|
|
||||||
const opts: ParseOptions = {
|
// const opts: ParseOptions = {
|
||||||
parseErrors: true,
|
// parseErrors: true,
|
||||||
trackedFiles: []
|
// trackedFiles: []
|
||||||
}
|
// }
|
||||||
|
|
||||||
const parser = new DartJsonParser(opts, 'dart')
|
// const parser = new DartJsonParser(opts, 'dart')
|
||||||
const result = await parser.parse(filePath, fileContent)
|
// const result = await parser.parse(filePath, fileContent)
|
||||||
expect(result.tests).toBe(0)
|
// expect(result.tests).toBe(0)
|
||||||
expect(result.result).toBe('success')
|
// expect(result.result).toBe('success')
|
||||||
})
|
// })
|
||||||
|
|
||||||
it('matches report snapshot', async () => {
|
// it('matches report snapshot', async () => {
|
||||||
const opts: ParseOptions = {
|
// const opts: ParseOptions = {
|
||||||
parseErrors: 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 fixturePath = path.join(__dirname, 'fixtures', 'dart-json.json')
|
// const fixturePath = path.join(__dirname, 'fixtures', 'dart-json.json')
|
||||||
const outputPath = path.join(__dirname, '__outputs__', 'dart-json.md')
|
// const outputPath = path.join(__dirname, '__outputs__', 'dart-json.md')
|
||||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
// const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||||
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
// const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||||
|
|
||||||
const parser = new DartJsonParser(opts, 'dart')
|
// const parser = new DartJsonParser(opts, 'dart')
|
||||||
const result = await parser.parse(filePath, fileContent)
|
// const result = await parser.parse(filePath, fileContent)
|
||||||
expect(result).toMatchSnapshot()
|
// expect(result).toMatchSnapshot()
|
||||||
|
|
||||||
const report = getReport([result])
|
// 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 rrousselGit/provider test results matches snapshot', async () => {
|
// it('report from rrousselGit/provider test results matches snapshot', async () => {
|
||||||
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'flutter', 'provider-test-results.json')
|
// const fixturePath = path.join(__dirname, 'fixtures', 'external', 'flutter', 'provider-test-results.json')
|
||||||
const trackedFilesPath = path.join(__dirname, 'fixtures', 'external', 'flutter', 'files.txt')
|
// const trackedFilesPath = path.join(__dirname, 'fixtures', 'external', 'flutter', 'files.txt')
|
||||||
const outputPath = path.join(__dirname, '__outputs__', 'provider-test-results.md')
|
// const outputPath = path.join(__dirname, '__outputs__', 'provider-test-results.md')
|
||||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
// const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||||
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
// const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||||
|
|
||||||
const trackedFiles = fs.readFileSync(trackedFilesPath, {encoding: 'utf8'}).split(/\n\r?/g)
|
// const trackedFiles = fs.readFileSync(trackedFilesPath, {encoding: 'utf8'}).split(/\n\r?/g)
|
||||||
const opts: ParseOptions = {
|
// const opts: ParseOptions = {
|
||||||
trackedFiles,
|
// trackedFiles,
|
||||||
parseErrors: true
|
// parseErrors: true
|
||||||
//workDir: '/__w/provider/provider/'
|
// //workDir: '/__w/provider/provider/'
|
||||||
}
|
// }
|
||||||
|
|
||||||
const parser = new DartJsonParser(opts, 'flutter')
|
// const parser = new DartJsonParser(opts, 'flutter')
|
||||||
const result = await parser.parse(filePath, fileContent)
|
// const result = await parser.parse(filePath, fileContent)
|
||||||
expect(result).toMatchSnapshot()
|
// expect(result).toMatchSnapshot()
|
||||||
|
|
||||||
const report = getReport([result])
|
// 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)
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
|
|
|
||||||
5892
dist/index.js
generated
vendored
5892
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
29
dist/licenses.txt
generated
vendored
29
dist/licenses.txt
generated
vendored
|
|
@ -378,16 +378,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
@vercel/ncc
|
|
||||||
MIT
|
|
||||||
Copyright 2018 ZEIT, Inc.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
adm-zip
|
adm-zip
|
||||||
MIT
|
MIT
|
||||||
MIT License
|
MIT License
|
||||||
|
|
@ -622,7 +612,7 @@ braces
|
||||||
MIT
|
MIT
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2014-2018, Jon Schlinkert.
|
Copyright (c) 2014-present, Jon Schlinkert.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
@ -1363,7 +1353,7 @@ sax
|
||||||
ISC
|
ISC
|
||||||
The ISC License
|
The ISC License
|
||||||
|
|
||||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
Copyright (c) 2010-2024 Isaac Z. Schlueter and Contributors
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|
@ -1382,7 +1372,7 @@ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
`String.fromCodePoint` by Mathias Bynens used according to terms of MIT
|
`String.fromCodePoint` by Mathias Bynens used according to terms of MIT
|
||||||
License, as follows:
|
License, as follows:
|
||||||
|
|
||||||
Copyright Mathias Bynens <https://mathiasbynens.be/>
|
Copyright (c) 2010-2024 Mathias Bynens <https://mathiasbynens.be/>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
|
@ -1490,19 +1480,6 @@ Permission to use, copy, modify, and/or distribute this software for any purpose
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
uuid
|
|
||||||
MIT
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2010-2020 Robert Kieffer and other contributors
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
|
|
||||||
wrappy
|
wrappy
|
||||||
ISC
|
ISC
|
||||||
The ISC License
|
The ISC License
|
||||||
|
|
|
||||||
10
src/main.ts
10
src/main.ts
|
|
@ -12,7 +12,7 @@ import {getAnnotations, Annotation} from './report/get-annotations'
|
||||||
import {UpdateChecksParametersWithOutput} from './report/patch-check'
|
import {UpdateChecksParametersWithOutput} from './report/patch-check'
|
||||||
import {getReport} from './report/get-report'
|
import {getReport} from './report/get-report'
|
||||||
|
|
||||||
import {DartJsonParser} from './parsers/dart-json/dart-json-parser'
|
// import {DartJsonParser} from './parsers/dart-json/dart-json-parser'
|
||||||
import {DotnetTrxParser} from './parsers/dotnet-trx/dotnet-trx-parser'
|
import {DotnetTrxParser} from './parsers/dotnet-trx/dotnet-trx-parser'
|
||||||
import {JavaJunitParser} from './parsers/java-junit/java-junit-parser'
|
import {JavaJunitParser} from './parsers/java-junit/java-junit-parser'
|
||||||
import {JestJunitParser} from './parsers/jest-junit/jest-junit-parser'
|
import {JestJunitParser} from './parsers/jest-junit/jest-junit-parser'
|
||||||
|
|
@ -236,12 +236,12 @@ class TestReporter {
|
||||||
|
|
||||||
getParser(reporter: string, options: ParseOptions): TestParser {
|
getParser(reporter: string, options: ParseOptions): TestParser {
|
||||||
switch (reporter) {
|
switch (reporter) {
|
||||||
case 'dart-json':
|
// case 'dart-json':
|
||||||
return new DartJsonParser(options, 'dart')
|
// return new DartJsonParser(options, 'dart')
|
||||||
case 'dotnet-trx':
|
case 'dotnet-trx':
|
||||||
return new DotnetTrxParser(options)
|
return new DotnetTrxParser(options)
|
||||||
case 'flutter-json':
|
// case 'flutter-json':
|
||||||
return new DartJsonParser(options, 'flutter')
|
// return new DartJsonParser(options, 'flutter')
|
||||||
case 'java-junit':
|
case 'java-junit':
|
||||||
return new JavaJunitParser(options)
|
return new JavaJunitParser(options)
|
||||||
case 'jest-junit':
|
case 'jest-junit':
|
||||||
|
|
|
||||||
|
|
@ -1,261 +1,261 @@
|
||||||
import {ParseOptions, TestParser} from '../../test-parser'
|
// import {ParseOptions, TestParser} from '../../test-parser'
|
||||||
|
|
||||||
import {getBasePath, normalizeFilePath} from '../../utils/path-utils'
|
// import {getBasePath, normalizeFilePath} from '../../utils/path-utils'
|
||||||
|
|
||||||
import {
|
// import {
|
||||||
ReportEvent,
|
// ReportEvent,
|
||||||
Suite,
|
// Suite,
|
||||||
Group,
|
// Group,
|
||||||
TestStartEvent,
|
// TestStartEvent,
|
||||||
TestDoneEvent,
|
// TestDoneEvent,
|
||||||
ErrorEvent,
|
// ErrorEvent,
|
||||||
isSuiteEvent,
|
// isSuiteEvent,
|
||||||
isGroupEvent,
|
// isGroupEvent,
|
||||||
isTestStartEvent,
|
// isTestStartEvent,
|
||||||
isTestDoneEvent,
|
// isTestDoneEvent,
|
||||||
isErrorEvent,
|
// isErrorEvent,
|
||||||
isDoneEvent,
|
// isDoneEvent,
|
||||||
isMessageEvent,
|
// isMessageEvent,
|
||||||
MessageEvent
|
// MessageEvent
|
||||||
} from './dart-json-types'
|
// } from './dart-json-types'
|
||||||
|
|
||||||
import {
|
// import {
|
||||||
TestExecutionResult,
|
// TestExecutionResult,
|
||||||
TestRunResult,
|
// TestRunResult,
|
||||||
TestSuiteResult,
|
// TestSuiteResult,
|
||||||
TestGroupResult,
|
// TestGroupResult,
|
||||||
TestCaseResult,
|
// TestCaseResult,
|
||||||
TestCaseError
|
// TestCaseError
|
||||||
} from '../../test-results'
|
// } from '../../test-results'
|
||||||
|
|
||||||
class TestRun {
|
// class TestRun {
|
||||||
constructor(
|
// constructor(
|
||||||
readonly path: string,
|
// readonly path: string,
|
||||||
readonly suites: TestSuite[],
|
// readonly suites: TestSuite[],
|
||||||
readonly success: boolean,
|
// readonly success: boolean,
|
||||||
readonly time: number
|
// readonly time: number
|
||||||
) {}
|
// ) {}
|
||||||
}
|
// }
|
||||||
|
|
||||||
class TestSuite {
|
// class TestSuite {
|
||||||
constructor(readonly suite: Suite) {}
|
// constructor(readonly suite: Suite) {}
|
||||||
readonly groups: {[id: number]: TestGroup} = {}
|
// readonly groups: {[id: number]: TestGroup} = {}
|
||||||
}
|
// }
|
||||||
|
|
||||||
class TestGroup {
|
// class TestGroup {
|
||||||
constructor(readonly group: Group) {}
|
// constructor(readonly group: Group) {}
|
||||||
readonly tests: TestCase[] = []
|
// readonly tests: TestCase[] = []
|
||||||
}
|
// }
|
||||||
|
|
||||||
class TestCase {
|
// class TestCase {
|
||||||
constructor(readonly testStart: TestStartEvent) {
|
// constructor(readonly testStart: TestStartEvent) {
|
||||||
this.groupId = testStart.test.groupIDs[testStart.test.groupIDs.length - 1]
|
// this.groupId = testStart.test.groupIDs[testStart.test.groupIDs.length - 1]
|
||||||
}
|
// }
|
||||||
readonly groupId: number
|
// readonly groupId: number
|
||||||
readonly print: MessageEvent[] = []
|
// readonly print: MessageEvent[] = []
|
||||||
testDone?: TestDoneEvent
|
// testDone?: TestDoneEvent
|
||||||
error?: ErrorEvent
|
// error?: ErrorEvent
|
||||||
|
|
||||||
get result(): TestExecutionResult {
|
// get result(): TestExecutionResult {
|
||||||
if (this.testDone?.skipped) {
|
// if (this.testDone?.skipped) {
|
||||||
return 'skipped'
|
// return 'skipped'
|
||||||
}
|
// }
|
||||||
if (this.testDone?.result === 'success') {
|
// if (this.testDone?.result === 'success') {
|
||||||
return 'success'
|
// return 'success'
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (this.testDone?.result === 'error' || this.testDone?.result === 'failure') {
|
// if (this.testDone?.result === 'error' || this.testDone?.result === 'failure') {
|
||||||
return 'failed'
|
// return 'failed'
|
||||||
}
|
// }
|
||||||
|
|
||||||
return undefined
|
// return undefined
|
||||||
}
|
// }
|
||||||
|
|
||||||
get time(): number {
|
// get time(): number {
|
||||||
return this.testDone !== undefined ? this.testDone.time - this.testStart.time : 0
|
// return this.testDone !== undefined ? this.testDone.time - this.testStart.time : 0
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
export class DartJsonParser implements TestParser {
|
// export class DartJsonParser implements TestParser {
|
||||||
assumedWorkDir: string | undefined
|
// assumedWorkDir: string | undefined
|
||||||
|
|
||||||
constructor(
|
// constructor(
|
||||||
readonly options: ParseOptions,
|
// readonly options: ParseOptions,
|
||||||
readonly sdk: 'dart' | 'flutter'
|
// readonly sdk: 'dart' | 'flutter'
|
||||||
) {}
|
// ) {}
|
||||||
|
|
||||||
async parse(path: string, content: string): Promise<TestRunResult> {
|
// async parse(path: string, content: string): Promise<TestRunResult> {
|
||||||
const tr = this.getTestRun(path, content)
|
// const tr = this.getTestRun(path, content)
|
||||||
const result = this.getTestRunResult(tr)
|
// const result = this.getTestRunResult(tr)
|
||||||
return Promise.resolve(result)
|
// return Promise.resolve(result)
|
||||||
}
|
// }
|
||||||
|
|
||||||
private getTestRun(path: string, content: string): TestRun {
|
// private getTestRun(path: string, content: string): TestRun {
|
||||||
const lines = content.split(/\n\r?/g)
|
// const lines = content.split(/\n\r?/g)
|
||||||
const events = lines
|
// const events = lines
|
||||||
.map((str, i) => {
|
// .map((str, i) => {
|
||||||
if (str.trim() === '') {
|
// if (str.trim() === '') {
|
||||||
return null
|
// return null
|
||||||
}
|
// }
|
||||||
try {
|
// try {
|
||||||
return JSON.parse(str)
|
// return JSON.parse(str)
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
const errWithCol = e as {columnNumber?: number}
|
// const errWithCol = e as {columnNumber?: number}
|
||||||
const col = errWithCol.columnNumber !== undefined ? `:${errWithCol.columnNumber}` : ''
|
// const col = errWithCol.columnNumber !== undefined ? `:${errWithCol.columnNumber}` : ''
|
||||||
throw new Error(`Invalid JSON at ${path}:${i + 1}${col}\n\n${e}`)
|
// throw new Error(`Invalid JSON at ${path}:${i + 1}${col}\n\n${e}`)
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
.filter(evt => evt != null) as ReportEvent[]
|
// .filter(evt => evt != null) as ReportEvent[]
|
||||||
|
|
||||||
let success = false
|
// let success = false
|
||||||
let totalTime = 0
|
// let totalTime = 0
|
||||||
const suites: {[id: number]: TestSuite} = {}
|
// const suites: {[id: number]: TestSuite} = {}
|
||||||
const tests: {[id: number]: TestCase} = {}
|
// const tests: {[id: number]: TestCase} = {}
|
||||||
|
|
||||||
for (const evt of events) {
|
// for (const evt of events) {
|
||||||
if (isSuiteEvent(evt)) {
|
// if (isSuiteEvent(evt)) {
|
||||||
suites[evt.suite.id] = new TestSuite(evt.suite)
|
// suites[evt.suite.id] = new TestSuite(evt.suite)
|
||||||
} else if (isGroupEvent(evt)) {
|
// } else if (isGroupEvent(evt)) {
|
||||||
suites[evt.group.suiteID].groups[evt.group.id] = new TestGroup(evt.group)
|
// suites[evt.group.suiteID].groups[evt.group.id] = new TestGroup(evt.group)
|
||||||
} else if (isTestStartEvent(evt) && evt.test.url !== null) {
|
// } else if (isTestStartEvent(evt) && evt.test.url !== null) {
|
||||||
const test: TestCase = new TestCase(evt)
|
// const test: TestCase = new TestCase(evt)
|
||||||
const suite = suites[evt.test.suiteID]
|
// const suite = suites[evt.test.suiteID]
|
||||||
const group = suite.groups[evt.test.groupIDs[evt.test.groupIDs.length - 1]]
|
// const group = suite.groups[evt.test.groupIDs[evt.test.groupIDs.length - 1]]
|
||||||
group.tests.push(test)
|
// group.tests.push(test)
|
||||||
tests[evt.test.id] = test
|
// tests[evt.test.id] = test
|
||||||
} else if (isTestDoneEvent(evt) && !evt.hidden && tests[evt.testID]) {
|
// } else if (isTestDoneEvent(evt) && !evt.hidden && tests[evt.testID]) {
|
||||||
tests[evt.testID].testDone = evt
|
// tests[evt.testID].testDone = evt
|
||||||
} else if (isErrorEvent(evt) && tests[evt.testID]) {
|
// } else if (isErrorEvent(evt) && tests[evt.testID]) {
|
||||||
tests[evt.testID].error = evt
|
// tests[evt.testID].error = evt
|
||||||
} else if (isMessageEvent(evt) && tests[evt.testID]) {
|
// } else if (isMessageEvent(evt) && tests[evt.testID]) {
|
||||||
tests[evt.testID].print.push(evt)
|
// tests[evt.testID].print.push(evt)
|
||||||
} else if (isDoneEvent(evt)) {
|
// } else if (isDoneEvent(evt)) {
|
||||||
success = evt.success
|
// success = evt.success
|
||||||
totalTime = evt.time
|
// totalTime = evt.time
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return new TestRun(path, Object.values(suites), success, totalTime)
|
// return new TestRun(path, Object.values(suites), success, totalTime)
|
||||||
}
|
// }
|
||||||
|
|
||||||
private getTestRunResult(tr: TestRun): TestRunResult {
|
// private getTestRunResult(tr: TestRun): TestRunResult {
|
||||||
const suites = tr.suites.map(s => {
|
// const suites = tr.suites.map(s => {
|
||||||
return new TestSuiteResult(this.getRelativePath(s.suite.path), this.getGroups(s))
|
// return new TestSuiteResult(this.getRelativePath(s.suite.path), this.getGroups(s))
|
||||||
})
|
// })
|
||||||
|
|
||||||
return new TestRunResult(tr.path, suites, tr.time)
|
// return new TestRunResult(tr.path, suites, tr.time)
|
||||||
}
|
// }
|
||||||
|
|
||||||
private 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(tc => {
|
// const tests = group.tests.map(tc => {
|
||||||
const error = this.getError(suite, tc)
|
// const error = this.getError(suite, tc)
|
||||||
const testName =
|
// const testName =
|
||||||
group.group.name !== undefined && tc.testStart.test.name.startsWith(group.group.name)
|
// group.group.name !== undefined && tc.testStart.test.name.startsWith(group.group.name)
|
||||||
? tc.testStart.test.name.slice(group.group.name.length).trim()
|
// ? tc.testStart.test.name.slice(group.group.name.length).trim()
|
||||||
: tc.testStart.test.name.trim()
|
// : tc.testStart.test.name.trim()
|
||||||
return new TestCaseResult(testName, tc.result, tc.time, error)
|
// return new TestCaseResult(testName, tc.result, tc.time, error)
|
||||||
})
|
// })
|
||||||
return new TestGroupResult(group.group.name, tests)
|
// return new TestGroupResult(group.group.name, tests)
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
|
|
||||||
private getError(testSuite: TestSuite, test: TestCase): TestCaseError | undefined {
|
// private getError(testSuite: TestSuite, test: TestCase): TestCaseError | undefined {
|
||||||
if (!this.options.parseErrors || !test.error) {
|
// if (!this.options.parseErrors || !test.error) {
|
||||||
return undefined
|
// return undefined
|
||||||
}
|
// }
|
||||||
|
|
||||||
const {trackedFiles} = this.options
|
// const {trackedFiles} = this.options
|
||||||
const stackTrace = test.error?.stackTrace ?? ''
|
// const stackTrace = test.error?.stackTrace ?? ''
|
||||||
const print = test.print
|
// const print = test.print
|
||||||
.filter(p => p.messageType === 'print')
|
// .filter(p => p.messageType === 'print')
|
||||||
.map(p => p.message)
|
// .map(p => p.message)
|
||||||
.join('\n')
|
// .join('\n')
|
||||||
const details = [print, stackTrace].filter(str => str !== '').join('\n')
|
// const details = [print, stackTrace].filter(str => str !== '').join('\n')
|
||||||
const src = this.exceptionThrowSource(details, trackedFiles)
|
// const src = this.exceptionThrowSource(details, trackedFiles)
|
||||||
const message = this.getErrorMessage(test.error?.error ?? '', print)
|
// const message = this.getErrorMessage(test.error?.error ?? '', print)
|
||||||
let path
|
// let path
|
||||||
let line
|
// let line
|
||||||
|
|
||||||
if (src !== undefined) {
|
// if (src !== undefined) {
|
||||||
path = src.path
|
// path = src.path
|
||||||
line = src.line
|
// line = src.line
|
||||||
} else {
|
// } else {
|
||||||
const testStartPath = this.getRelativePath(testSuite.suite.path)
|
// const testStartPath = this.getRelativePath(testSuite.suite.path)
|
||||||
if (trackedFiles.includes(testStartPath)) {
|
// if (trackedFiles.includes(testStartPath)) {
|
||||||
path = testStartPath
|
// path = testStartPath
|
||||||
line = test.testStart.test.root_line ?? test.testStart.test.line ?? undefined
|
// line = test.testStart.test.root_line ?? test.testStart.test.line ?? undefined
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return {
|
// return {
|
||||||
path,
|
// path,
|
||||||
line,
|
// line,
|
||||||
message,
|
// message,
|
||||||
details
|
// details
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
private getErrorMessage(message: string, print: string): string {
|
// private getErrorMessage(message: string, print: string): string {
|
||||||
if (this.sdk === 'flutter') {
|
// if (this.sdk === 'flutter') {
|
||||||
const uselessMessageRe = /^Test failed\. See exception logs above\.\nThe test description was:/m
|
// const uselessMessageRe = /^Test failed\. See exception logs above\.\nThe test description was:/m
|
||||||
const flutterPrintRe =
|
// const flutterPrintRe =
|
||||||
/^══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞═+\s+(.*)\s+When the exception was thrown, this was the stack:/ms
|
// /^══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞═+\s+(.*)\s+When the exception was thrown, this was the stack:/ms
|
||||||
if (uselessMessageRe.test(message)) {
|
// if (uselessMessageRe.test(message)) {
|
||||||
const match = print.match(flutterPrintRe)
|
// const match = print.match(flutterPrintRe)
|
||||||
if (match !== null) {
|
// if (match !== null) {
|
||||||
return match[1]
|
// return match[1]
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return message || print
|
// return message || print
|
||||||
}
|
// }
|
||||||
|
|
||||||
private exceptionThrowSource(ex: string, trackedFiles: string[]): {path: string; line: number} | undefined {
|
// private exceptionThrowSource(ex: string, trackedFiles: string[]): {path: string; line: number} | undefined {
|
||||||
const lines = ex.split(/\r?\n/g)
|
// const lines = ex.split(/\r?\n/g)
|
||||||
|
|
||||||
// regexp to extract file path and line number from stack trace
|
// // regexp to extract file path and line number from stack trace
|
||||||
const dartRe = /^(?!package:)(.*)\s+(\d+):\d+\s+/
|
// const dartRe = /^(?!package:)(.*)\s+(\d+):\d+\s+/
|
||||||
const flutterRe = /^#\d+\s+.*\((?!package:)(.*):(\d+):\d+\)$/
|
// const flutterRe = /^#\d+\s+.*\((?!package:)(.*):(\d+):\d+\)$/
|
||||||
const re = this.sdk === 'dart' ? dartRe : flutterRe
|
// const re = this.sdk === 'dart' ? dartRe : flutterRe
|
||||||
|
|
||||||
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 [_, pathStr, lineStr] = match
|
// const [_, pathStr, lineStr] = match
|
||||||
const path = normalizeFilePath(this.getRelativePath(pathStr))
|
// const path = normalizeFilePath(this.getRelativePath(pathStr))
|
||||||
if (trackedFiles.includes(path)) {
|
// if (trackedFiles.includes(path)) {
|
||||||
const line = parseInt(lineStr)
|
// const line = parseInt(lineStr)
|
||||||
return {path, line}
|
// return {path, line}
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
private getRelativePath(path: string): string {
|
// private getRelativePath(path: string): string {
|
||||||
const prefix = 'file://'
|
// const prefix = 'file://'
|
||||||
if (path.startsWith(prefix)) {
|
// if (path.startsWith(prefix)) {
|
||||||
path = path.substr(prefix.length)
|
// path = path.substr(prefix.length)
|
||||||
}
|
// }
|
||||||
|
|
||||||
path = normalizeFilePath(path)
|
// path = normalizeFilePath(path)
|
||||||
const workDir = this.getWorkDir(path)
|
// const workDir = this.getWorkDir(path)
|
||||||
if (workDir !== undefined && path.startsWith(workDir)) {
|
// if (workDir !== undefined && path.startsWith(workDir)) {
|
||||||
path = path.substr(workDir.length)
|
// path = path.substr(workDir.length)
|
||||||
}
|
// }
|
||||||
return path
|
// return path
|
||||||
}
|
// }
|
||||||
|
|
||||||
private getWorkDir(path: string): string | undefined {
|
// private getWorkDir(path: string): string | undefined {
|
||||||
return (
|
// return (
|
||||||
this.options.workDir ??
|
// this.options.workDir ??
|
||||||
this.assumedWorkDir ??
|
// this.assumedWorkDir ??
|
||||||
(this.assumedWorkDir = getBasePath(path, this.options.trackedFiles))
|
// (this.assumedWorkDir = getBasePath(path, this.options.trackedFiles))
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue