mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 22:37:09 +01:00
update compiler to e2023
This commit is contained in:
parent
3ece1e5069
commit
fa59c8e9ca
4 changed files with 726 additions and 778 deletions
|
|
@ -1,69 +1,69 @@
|
|||
// import * as fs from 'fs'
|
||||
// import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
|
||||
// import {DartJsonParser} from '../src/parsers/dart-json/dart-json-parser'
|
||||
// import {ParseOptions} from '../src/test-parser'
|
||||
// import {getReport} from '../src/report/get-report'
|
||||
// import {normalizeFilePath} from '../src/utils/path-utils'
|
||||
import {DartJsonParser} from '../src/parsers/dart-json/dart-json-parser'
|
||||
import {ParseOptions} from '../src/test-parser'
|
||||
import {getReport} from '../src/report/get-report'
|
||||
import {normalizeFilePath} from '../src/utils/path-utils'
|
||||
|
||||
// describe('dart-json tests', () => {
|
||||
// it('produces empty test run result when there are no test cases', async () => {
|
||||
// const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'dart-json.json')
|
||||
// const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||
// const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
describe('dart-json tests', () => {
|
||||
it('produces empty test run result when there are no test cases', async () => {
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'dart-json.json')
|
||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
|
||||
// const opts: ParseOptions = {
|
||||
// parseErrors: true,
|
||||
// trackedFiles: []
|
||||
// }
|
||||
const opts: ParseOptions = {
|
||||
parseErrors: true,
|
||||
trackedFiles: []
|
||||
}
|
||||
|
||||
// const parser = new DartJsonParser(opts, 'dart')
|
||||
// const result = await parser.parse(filePath, fileContent)
|
||||
// expect(result.tests).toBe(0)
|
||||
// expect(result.result).toBe('success')
|
||||
// })
|
||||
const parser = new DartJsonParser(opts, 'dart')
|
||||
const result = await parser.parse(filePath, fileContent)
|
||||
expect(result.tests).toBe(0)
|
||||
expect(result.result).toBe('success')
|
||||
})
|
||||
|
||||
// it('matches report snapshot', async () => {
|
||||
// const opts: ParseOptions = {
|
||||
// parseErrors: true,
|
||||
// trackedFiles: ['lib/main.dart', 'test/main_test.dart', 'test/second_test.dart']
|
||||
// //workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dart/'
|
||||
// }
|
||||
it('matches report snapshot', async () => {
|
||||
const opts: ParseOptions = {
|
||||
parseErrors: true,
|
||||
trackedFiles: ['lib/main.dart', 'test/main_test.dart', 'test/second_test.dart']
|
||||
//workDir: 'C:/Users/Michal/Workspace/dorny/test-check/reports/dart/'
|
||||
}
|
||||
|
||||
// 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 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, 'dart')
|
||||
// const result = await parser.parse(filePath, fileContent)
|
||||
// expect(result).toMatchSnapshot()
|
||||
const parser = new DartJsonParser(opts, 'dart')
|
||||
const result = await parser.parse(filePath, fileContent)
|
||||
expect(result).toMatchSnapshot()
|
||||
|
||||
// const report = getReport([result])
|
||||
// fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||
// fs.writeFileSync(outputPath, report)
|
||||
// })
|
||||
const report = getReport([result])
|
||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||
fs.writeFileSync(outputPath, report)
|
||||
})
|
||||
|
||||
// it('report from rrousselGit/provider test results matches snapshot', async () => {
|
||||
// const fixturePath = path.join(__dirname, 'fixtures', 'external', 'flutter', 'provider-test-results.json')
|
||||
// const trackedFilesPath = path.join(__dirname, 'fixtures', 'external', 'flutter', 'files.txt')
|
||||
// const outputPath = path.join(__dirname, '__outputs__', 'provider-test-results.md')
|
||||
// const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||
// const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
it('report from rrousselGit/provider test results matches snapshot', async () => {
|
||||
const fixturePath = path.join(__dirname, 'fixtures', 'external', 'flutter', 'provider-test-results.json')
|
||||
const trackedFilesPath = path.join(__dirname, 'fixtures', 'external', 'flutter', 'files.txt')
|
||||
const outputPath = path.join(__dirname, '__outputs__', 'provider-test-results.md')
|
||||
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||
|
||||
// const trackedFiles = fs.readFileSync(trackedFilesPath, {encoding: 'utf8'}).split(/\n\r?/g)
|
||||
// const opts: ParseOptions = {
|
||||
// trackedFiles,
|
||||
// parseErrors: true
|
||||
// //workDir: '/__w/provider/provider/'
|
||||
// }
|
||||
const trackedFiles = fs.readFileSync(trackedFilesPath, {encoding: 'utf8'}).split(/\n\r?/g)
|
||||
const opts: ParseOptions = {
|
||||
trackedFiles,
|
||||
parseErrors: true
|
||||
//workDir: '/__w/provider/provider/'
|
||||
}
|
||||
|
||||
// const parser = new DartJsonParser(opts, 'flutter')
|
||||
// const result = await parser.parse(filePath, fileContent)
|
||||
// expect(result).toMatchSnapshot()
|
||||
const parser = new DartJsonParser(opts, 'flutter')
|
||||
const result = await parser.parse(filePath, fileContent)
|
||||
expect(result).toMatchSnapshot()
|
||||
|
||||
// const report = getReport([result])
|
||||
// fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||
// fs.writeFileSync(outputPath, report)
|
||||
// })
|
||||
// })
|
||||
const report = getReport([result])
|
||||
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||
fs.writeFileSync(outputPath, report)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
934
dist/index.js
generated
vendored
934
dist/index.js
generated
vendored
File diff suppressed because it is too large
Load diff
|
|
@ -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 {
|
||||
// ReportEvent,
|
||||
// Suite,
|
||||
// Group,
|
||||
// TestStartEvent,
|
||||
// TestDoneEvent,
|
||||
// ErrorEvent,
|
||||
// isSuiteEvent,
|
||||
// isGroupEvent,
|
||||
// isTestStartEvent,
|
||||
// isTestDoneEvent,
|
||||
// isErrorEvent,
|
||||
// isDoneEvent,
|
||||
// isMessageEvent,
|
||||
// MessageEvent
|
||||
// } from './dart-json-types'
|
||||
import {
|
||||
ReportEvent,
|
||||
Suite,
|
||||
Group,
|
||||
TestStartEvent,
|
||||
TestDoneEvent,
|
||||
ErrorEvent,
|
||||
isSuiteEvent,
|
||||
isGroupEvent,
|
||||
isTestStartEvent,
|
||||
isTestDoneEvent,
|
||||
isErrorEvent,
|
||||
isDoneEvent,
|
||||
isMessageEvent,
|
||||
MessageEvent
|
||||
} from './dart-json-types'
|
||||
|
||||
// import {
|
||||
// TestExecutionResult,
|
||||
// TestRunResult,
|
||||
// TestSuiteResult,
|
||||
// TestGroupResult,
|
||||
// TestCaseResult,
|
||||
// TestCaseError
|
||||
// } from '../../test-results'
|
||||
import {
|
||||
TestExecutionResult,
|
||||
TestRunResult,
|
||||
TestSuiteResult,
|
||||
TestGroupResult,
|
||||
TestCaseResult,
|
||||
TestCaseError
|
||||
} from '../../test-results'
|
||||
|
||||
// class TestRun {
|
||||
// constructor(
|
||||
// readonly path: string,
|
||||
// readonly suites: TestSuite[],
|
||||
// readonly success: boolean,
|
||||
// readonly time: number
|
||||
// ) {}
|
||||
// }
|
||||
class TestRun {
|
||||
constructor(
|
||||
readonly path: string,
|
||||
readonly suites: TestSuite[],
|
||||
readonly success: boolean,
|
||||
readonly time: number
|
||||
) {}
|
||||
}
|
||||
|
||||
// class TestSuite {
|
||||
// constructor(readonly suite: Suite) {}
|
||||
// readonly groups: {[id: number]: TestGroup} = {}
|
||||
// }
|
||||
class TestSuite {
|
||||
constructor(readonly suite: Suite) {}
|
||||
readonly groups: {[id: number]: TestGroup} = {}
|
||||
}
|
||||
|
||||
// class TestGroup {
|
||||
// constructor(readonly group: Group) {}
|
||||
// readonly tests: TestCase[] = []
|
||||
// }
|
||||
class TestGroup {
|
||||
constructor(readonly group: Group) {}
|
||||
readonly tests: TestCase[] = []
|
||||
}
|
||||
|
||||
// class TestCase {
|
||||
// constructor(readonly testStart: TestStartEvent) {
|
||||
// this.groupId = testStart.test.groupIDs[testStart.test.groupIDs.length - 1]
|
||||
// }
|
||||
// readonly groupId: number
|
||||
// readonly print: MessageEvent[] = []
|
||||
// testDone?: TestDoneEvent
|
||||
// error?: ErrorEvent
|
||||
class TestCase {
|
||||
constructor(readonly testStart: TestStartEvent) {
|
||||
this.groupId = testStart.test.groupIDs[testStart.test.groupIDs.length - 1]
|
||||
}
|
||||
readonly groupId: number
|
||||
readonly print: MessageEvent[] = []
|
||||
testDone?: TestDoneEvent
|
||||
error?: ErrorEvent
|
||||
|
||||
// get result(): TestExecutionResult {
|
||||
// if (this.testDone?.skipped) {
|
||||
// return 'skipped'
|
||||
// }
|
||||
// if (this.testDone?.result === 'success') {
|
||||
// return 'success'
|
||||
// }
|
||||
get result(): TestExecutionResult {
|
||||
if (this.testDone?.skipped) {
|
||||
return 'skipped'
|
||||
}
|
||||
if (this.testDone?.result === 'success') {
|
||||
return 'success'
|
||||
}
|
||||
|
||||
// if (this.testDone?.result === 'error' || this.testDone?.result === 'failure') {
|
||||
// return 'failed'
|
||||
// }
|
||||
if (this.testDone?.result === 'error' || this.testDone?.result === 'failure') {
|
||||
return 'failed'
|
||||
}
|
||||
|
||||
// return undefined
|
||||
// }
|
||||
return undefined
|
||||
}
|
||||
|
||||
// get time(): number {
|
||||
// return this.testDone !== undefined ? this.testDone.time - this.testStart.time : 0
|
||||
// }
|
||||
// }
|
||||
get time(): number {
|
||||
return this.testDone !== undefined ? this.testDone.time - this.testStart.time : 0
|
||||
}
|
||||
}
|
||||
|
||||
// export class DartJsonParser implements TestParser {
|
||||
// assumedWorkDir: string | undefined
|
||||
export class DartJsonParser implements TestParser {
|
||||
assumedWorkDir: string | undefined
|
||||
|
||||
// constructor(
|
||||
// readonly options: ParseOptions,
|
||||
// readonly sdk: 'dart' | 'flutter'
|
||||
// ) {}
|
||||
constructor(
|
||||
readonly options: ParseOptions,
|
||||
readonly sdk: 'dart' | 'flutter'
|
||||
) {}
|
||||
|
||||
// async parse(path: string, content: string): Promise<TestRunResult> {
|
||||
// const tr = this.getTestRun(path, content)
|
||||
// const result = this.getTestRunResult(tr)
|
||||
// return Promise.resolve(result)
|
||||
// }
|
||||
async parse(path: string, content: string): Promise<TestRunResult> {
|
||||
const tr = this.getTestRun(path, content)
|
||||
const result = this.getTestRunResult(tr)
|
||||
return Promise.resolve(result)
|
||||
}
|
||||
|
||||
// private getTestRun(path: string, content: string): TestRun {
|
||||
// const lines = content.split(/\n\r?/g)
|
||||
// const events = lines
|
||||
// .map((str, i) => {
|
||||
// if (str.trim() === '') {
|
||||
// return null
|
||||
// }
|
||||
// try {
|
||||
// return JSON.parse(str)
|
||||
// } catch (e) {
|
||||
// const errWithCol = e as {columnNumber?: number}
|
||||
// const col = errWithCol.columnNumber !== undefined ? `:${errWithCol.columnNumber}` : ''
|
||||
// throw new Error(`Invalid JSON at ${path}:${i + 1}${col}\n\n${e}`)
|
||||
// }
|
||||
// })
|
||||
// .filter(evt => evt != null) as ReportEvent[]
|
||||
private getTestRun(path: string, content: string): TestRun {
|
||||
const lines = content.split(/\n\r?/g)
|
||||
const events = lines
|
||||
.map((str, i) => {
|
||||
if (str.trim() === '') {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
return JSON.parse(str)
|
||||
} catch (e) {
|
||||
const errWithCol = e as {columnNumber?: number}
|
||||
const col = errWithCol.columnNumber !== undefined ? `:${errWithCol.columnNumber}` : ''
|
||||
throw new Error(`Invalid JSON at ${path}:${i + 1}${col}\n\n${e}`)
|
||||
}
|
||||
})
|
||||
.filter(evt => evt != null) as ReportEvent[]
|
||||
|
||||
// let success = false
|
||||
// let totalTime = 0
|
||||
// const suites: {[id: number]: TestSuite} = {}
|
||||
// const tests: {[id: number]: TestCase} = {}
|
||||
let success = false
|
||||
let totalTime = 0
|
||||
const suites: {[id: number]: TestSuite} = {}
|
||||
const tests: {[id: number]: TestCase} = {}
|
||||
|
||||
// for (const evt of events) {
|
||||
// if (isSuiteEvent(evt)) {
|
||||
// suites[evt.suite.id] = new TestSuite(evt.suite)
|
||||
// } else if (isGroupEvent(evt)) {
|
||||
// suites[evt.group.suiteID].groups[evt.group.id] = new TestGroup(evt.group)
|
||||
// } else if (isTestStartEvent(evt) && evt.test.url !== null) {
|
||||
// const test: TestCase = new TestCase(evt)
|
||||
// const suite = suites[evt.test.suiteID]
|
||||
// const group = suite.groups[evt.test.groupIDs[evt.test.groupIDs.length - 1]]
|
||||
// group.tests.push(test)
|
||||
// tests[evt.test.id] = test
|
||||
// } else if (isTestDoneEvent(evt) && !evt.hidden && tests[evt.testID]) {
|
||||
// tests[evt.testID].testDone = evt
|
||||
// } else if (isErrorEvent(evt) && tests[evt.testID]) {
|
||||
// tests[evt.testID].error = evt
|
||||
// } else if (isMessageEvent(evt) && tests[evt.testID]) {
|
||||
// tests[evt.testID].print.push(evt)
|
||||
// } else if (isDoneEvent(evt)) {
|
||||
// success = evt.success
|
||||
// totalTime = evt.time
|
||||
// }
|
||||
// }
|
||||
for (const evt of events) {
|
||||
if (isSuiteEvent(evt)) {
|
||||
suites[evt.suite.id] = new TestSuite(evt.suite)
|
||||
} else if (isGroupEvent(evt)) {
|
||||
suites[evt.group.suiteID].groups[evt.group.id] = new TestGroup(evt.group)
|
||||
} else if (isTestStartEvent(evt) && evt.test.url !== null) {
|
||||
const test: TestCase = new TestCase(evt)
|
||||
const suite = suites[evt.test.suiteID]
|
||||
const group = suite.groups[evt.test.groupIDs[evt.test.groupIDs.length - 1]]
|
||||
group.tests.push(test)
|
||||
tests[evt.test.id] = test
|
||||
} else if (isTestDoneEvent(evt) && !evt.hidden && tests[evt.testID]) {
|
||||
tests[evt.testID].testDone = evt
|
||||
} else if (isErrorEvent(evt) && tests[evt.testID]) {
|
||||
tests[evt.testID].error = evt
|
||||
} else if (isMessageEvent(evt) && tests[evt.testID]) {
|
||||
tests[evt.testID].print.push(evt)
|
||||
} else if (isDoneEvent(evt)) {
|
||||
success = evt.success
|
||||
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 {
|
||||
// const suites = tr.suites.map(s => {
|
||||
// return new TestSuiteResult(this.getRelativePath(s.suite.path), this.getGroups(s))
|
||||
// })
|
||||
private getTestRunResult(tr: TestRun): TestRunResult {
|
||||
const suites = tr.suites.map(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[] {
|
||||
// const groups = Object.values(suite.groups).filter(grp => grp.tests.length > 0)
|
||||
// groups.sort((a, b) => (a.group.line ?? 0) - (b.group.line ?? 0))
|
||||
private getGroups(suite: TestSuite): TestGroupResult[] {
|
||||
const groups = Object.values(suite.groups).filter(grp => grp.tests.length > 0)
|
||||
groups.sort((a, b) => (a.group.line ?? 0) - (b.group.line ?? 0))
|
||||
|
||||
// return groups.map(group => {
|
||||
// group.tests.sort((a, b) => (a.testStart.test.line ?? 0) - (b.testStart.test.line ?? 0))
|
||||
// const tests = group.tests.map(tc => {
|
||||
// const error = this.getError(suite, tc)
|
||||
// const testName =
|
||||
// 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.trim()
|
||||
// return new TestCaseResult(testName, tc.result, tc.time, error)
|
||||
// })
|
||||
// return new TestGroupResult(group.group.name, tests)
|
||||
// })
|
||||
// }
|
||||
return groups.map(group => {
|
||||
group.tests.sort((a, b) => (a.testStart.test.line ?? 0) - (b.testStart.test.line ?? 0))
|
||||
const tests = group.tests.map(tc => {
|
||||
const error = this.getError(suite, tc)
|
||||
const testName =
|
||||
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.trim()
|
||||
return new TestCaseResult(testName, tc.result, tc.time, error)
|
||||
})
|
||||
return new TestGroupResult(group.group.name, tests)
|
||||
})
|
||||
}
|
||||
|
||||
// private getError(testSuite: TestSuite, test: TestCase): TestCaseError | undefined {
|
||||
// if (!this.options.parseErrors || !test.error) {
|
||||
// return undefined
|
||||
// }
|
||||
private getError(testSuite: TestSuite, test: TestCase): TestCaseError | undefined {
|
||||
if (!this.options.parseErrors || !test.error) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
// const {trackedFiles} = this.options
|
||||
// const stackTrace = test.error?.stackTrace ?? ''
|
||||
// const print = test.print
|
||||
// .filter(p => p.messageType === 'print')
|
||||
// .map(p => p.message)
|
||||
// .join('\n')
|
||||
// const details = [print, stackTrace].filter(str => str !== '').join('\n')
|
||||
// const src = this.exceptionThrowSource(details, trackedFiles)
|
||||
// const message = this.getErrorMessage(test.error?.error ?? '', print)
|
||||
// let path
|
||||
// let line
|
||||
const {trackedFiles} = this.options
|
||||
const stackTrace = test.error?.stackTrace ?? ''
|
||||
const print = test.print
|
||||
.filter(p => p.messageType === 'print')
|
||||
.map(p => p.message)
|
||||
.join('\n')
|
||||
const details = [print, stackTrace].filter(str => str !== '').join('\n')
|
||||
const src = this.exceptionThrowSource(details, trackedFiles)
|
||||
const message = this.getErrorMessage(test.error?.error ?? '', print)
|
||||
let path
|
||||
let line
|
||||
|
||||
// if (src !== undefined) {
|
||||
// path = src.path
|
||||
// line = src.line
|
||||
// } else {
|
||||
// const testStartPath = this.getRelativePath(testSuite.suite.path)
|
||||
// if (trackedFiles.includes(testStartPath)) {
|
||||
// path = testStartPath
|
||||
// line = test.testStart.test.root_line ?? test.testStart.test.line ?? undefined
|
||||
// }
|
||||
// }
|
||||
if (src !== undefined) {
|
||||
path = src.path
|
||||
line = src.line
|
||||
} else {
|
||||
const testStartPath = this.getRelativePath(testSuite.suite.path)
|
||||
if (trackedFiles.includes(testStartPath)) {
|
||||
path = testStartPath
|
||||
line = test.testStart.test.root_line ?? test.testStart.test.line ?? undefined
|
||||
}
|
||||
}
|
||||
|
||||
// return {
|
||||
// path,
|
||||
// line,
|
||||
// message,
|
||||
// details
|
||||
// }
|
||||
// }
|
||||
return {
|
||||
path,
|
||||
line,
|
||||
message,
|
||||
details
|
||||
}
|
||||
}
|
||||
|
||||
// private getErrorMessage(message: string, print: string): string {
|
||||
// if (this.sdk === 'flutter') {
|
||||
// const uselessMessageRe = /^Test failed\. See exception logs above\.\nThe test description was:/m
|
||||
// const flutterPrintRe =
|
||||
// /^══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞═+\s+(.*)\s+When the exception was thrown, this was the stack:/ms
|
||||
// if (uselessMessageRe.test(message)) {
|
||||
// const match = print.match(flutterPrintRe)
|
||||
// if (match !== null) {
|
||||
// return match[1]
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
private getErrorMessage(message: string, print: string): string {
|
||||
if (this.sdk === 'flutter') {
|
||||
const uselessMessageRe = /^Test failed\. See exception logs above\.\nThe test description was:/m
|
||||
const flutterPrintRe =
|
||||
/^══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞═+\s+(.*)\s+When the exception was thrown, this was the stack:/ms
|
||||
if (uselessMessageRe.test(message)) {
|
||||
const match = print.match(flutterPrintRe)
|
||||
if (match !== null) {
|
||||
return match[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return message || print
|
||||
// }
|
||||
return message || print
|
||||
}
|
||||
|
||||
// private exceptionThrowSource(ex: string, trackedFiles: string[]): {path: string; line: number} | undefined {
|
||||
// const lines = ex.split(/\r?\n/g)
|
||||
private exceptionThrowSource(ex: string, trackedFiles: string[]): {path: string; line: number} | undefined {
|
||||
const lines = ex.split(/\r?\n/g)
|
||||
|
||||
// // regexp to extract file path and line number from stack trace
|
||||
// const dartRe = /^(?!package:)(.*)\s+(\d+):\d+\s+/
|
||||
// const flutterRe = /^#\d+\s+.*\((?!package:)(.*):(\d+):\d+\)$/
|
||||
// const re = this.sdk === 'dart' ? dartRe : flutterRe
|
||||
// regexp to extract file path and line number from stack trace
|
||||
const dartRe = /^(?!package:)(.*)\s+(\d+):\d+\s+/
|
||||
const flutterRe = /^#\d+\s+.*\((?!package:)(.*):(\d+):\d+\)$/
|
||||
const re = this.sdk === 'dart' ? dartRe : flutterRe
|
||||
|
||||
// for (const str of lines) {
|
||||
// const match = str.match(re)
|
||||
// if (match !== null) {
|
||||
// const [_, pathStr, lineStr] = match
|
||||
// const path = normalizeFilePath(this.getRelativePath(pathStr))
|
||||
// if (trackedFiles.includes(path)) {
|
||||
// const line = parseInt(lineStr)
|
||||
// return {path, line}
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for (const str of lines) {
|
||||
const match = str.match(re)
|
||||
if (match !== null) {
|
||||
const [_, pathStr, lineStr] = match
|
||||
const path = normalizeFilePath(this.getRelativePath(pathStr))
|
||||
if (trackedFiles.includes(path)) {
|
||||
const line = parseInt(lineStr)
|
||||
return {path, line}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// private getRelativePath(path: string): string {
|
||||
// const prefix = 'file://'
|
||||
// if (path.startsWith(prefix)) {
|
||||
// path = path.substr(prefix.length)
|
||||
// }
|
||||
private getRelativePath(path: string): string {
|
||||
const prefix = 'file://'
|
||||
if (path.startsWith(prefix)) {
|
||||
path = path.substr(prefix.length)
|
||||
}
|
||||
|
||||
// path = normalizeFilePath(path)
|
||||
// const workDir = this.getWorkDir(path)
|
||||
// if (workDir !== undefined && path.startsWith(workDir)) {
|
||||
// path = path.substr(workDir.length)
|
||||
// }
|
||||
// return path
|
||||
// }
|
||||
path = normalizeFilePath(path)
|
||||
const workDir = this.getWorkDir(path)
|
||||
if (workDir !== undefined && path.startsWith(workDir)) {
|
||||
path = path.substr(workDir.length)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
// private getWorkDir(path: string): string | undefined {
|
||||
// return (
|
||||
// this.options.workDir ??
|
||||
// this.assumedWorkDir ??
|
||||
// (this.assumedWorkDir = getBasePath(path, this.options.trackedFiles))
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
private getWorkDir(path: string): string | undefined {
|
||||
return (
|
||||
this.options.workDir ??
|
||||
this.assumedWorkDir ??
|
||||
(this.assumedWorkDir = getBasePath(path, this.options.trackedFiles))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"target": "ES2023", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"outDir": "./lib", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue