mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 06:17:10 +01:00
Fix dart-json not stripping cwd from suite paths
This commit is contained in:
parent
9c4a2c56d7
commit
2365963b2e
5 changed files with 41 additions and 49 deletions
|
|
@ -3,9 +3,9 @@
|
||||||
**6** tests were completed in **3.760s** with **1** passed, **4** failed and **1** skipped.
|
**6** tests were completed in **3.760s** with **1** passed, **4** failed and **1** skipped.
|
||||||
|Test suite|Passed|Failed|Skipped|Time|
|
|Test suite|Passed|Failed|Skipped|Time|
|
||||||
|:---|---:|---:|---:|---:|
|
|:---|---:|---:|---:|---:|
|
||||||
|[test\main_test.dart](#r0s0)|1✔️|3❌||74ms|
|
|[test/main_test.dart](#r0s0)|1✔️|3❌||74ms|
|
||||||
|[test\second_test.dart](#r0s1)||1❌|1✖️|51ms|
|
|[test/second_test.dart](#r0s1)||1❌|1✖️|51ms|
|
||||||
### <a id="user-content-r0s0" href="#r0s0">test\main_test.dart</a> ❌
|
### <a id="user-content-r0s0" href="#r0s0">test/main_test.dart</a> ❌
|
||||||
**4** tests were completed in **74ms** with **1** passed, **3** failed and **0** skipped.
|
**4** tests were completed in **74ms** with **1** passed, **3** failed and **0** skipped.
|
||||||
|
|
||||||
**Test 1**
|
**Test 1**
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
|Result|Test|Time|
|
|Result|Test|Time|
|
||||||
|:---:|:---|---:|
|
|:---:|:---|---:|
|
||||||
|❌|Test 2 Exception in test|12ms|
|
|❌|Test 2 Exception in test|12ms|
|
||||||
### <a id="user-content-r0s1" href="#r0s1">test\second_test.dart</a> ❌
|
### <a id="user-content-r0s1" href="#r0s1">test/second_test.dart</a> ❌
|
||||||
**2** tests were completed in **51ms** with **0** passed, **1** failed and **1** skipped.
|
**2** tests were completed in **51ms** with **0** passed, **1** failed and **1** skipped.
|
||||||
|
|
||||||
|Result|Test|Time|
|
|Result|Test|Time|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ test\\\\main_test.dart 17:9 main.<fn>.<fn>.<fn>
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"name": "test\\\\main_test.dart",
|
"name": "test/main_test.dart",
|
||||||
"totalTime": undefined,
|
"totalTime": undefined,
|
||||||
},
|
},
|
||||||
TestSuiteResult {
|
TestSuiteResult {
|
||||||
|
|
@ -97,7 +97,7 @@ test\\\\main_test.dart 17:9 main.<fn>.<fn>.<fn>
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"name": "test\\\\second_test.dart",
|
"name": "test/second_test.dart",
|
||||||
"totalTime": undefined,
|
"totalTime": undefined,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
38
dist/index.js
generated
vendored
38
dist/index.js
generated
vendored
|
|
@ -235,7 +235,7 @@ class DartJsonParser {
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
const col = e.columnNumber !== undefined ? `:${e.columnNumber}` : '';
|
const col = e.columnNumber !== undefined ? `:${e.columnNumber}` : '';
|
||||||
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);
|
.filter(evt => evt != null);
|
||||||
|
|
@ -272,7 +272,7 @@ class DartJsonParser {
|
||||||
}
|
}
|
||||||
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, this.getGroups(s));
|
return new test_results_1.TestSuiteResult(this.getRelativePath(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);
|
||||||
}
|
}
|
||||||
|
|
@ -281,35 +281,34 @@ class DartJsonParser {
|
||||||
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 => this.getTest(t));
|
const tests = group.tests.map(tc => {
|
||||||
|
const error = this.getError(suite, tc);
|
||||||
|
return new test_results_1.TestCaseResult(tc.testStart.test.name, tc.result, tc.time, error);
|
||||||
|
});
|
||||||
return new test_results_1.TestGroupResult(group.group.name, tests);
|
return new test_results_1.TestGroupResult(group.group.name, tests);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getTest(tc) {
|
getError(testSuite, test) {
|
||||||
const error = this.getError(tc);
|
|
||||||
return new test_results_1.TestCaseResult(tc.testStart.test.name, tc.result, tc.time, error);
|
|
||||||
}
|
|
||||||
getError(test) {
|
|
||||||
var _a, _b, _c, _d, _e, _f;
|
var _a, _b, _c, _d, _e, _f;
|
||||||
if (!this.options.parseErrors || !test.error) {
|
if (!this.options.parseErrors || !test.error) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
const { workDir, trackedFiles } = this.options;
|
const { trackedFiles } = this.options;
|
||||||
const message = (_b = (_a = test.error) === null || _a === void 0 ? void 0 : _a.error) !== null && _b !== void 0 ? _b : '';
|
const message = (_b = (_a = test.error) === null || _a === void 0 ? void 0 : _a.error) !== null && _b !== void 0 ? _b : '';
|
||||||
const stackTrace = (_d = (_c = test.error) === null || _c === void 0 ? void 0 : _c.stackTrace) !== null && _d !== void 0 ? _d : '';
|
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);
|
const src = this.exceptionThrowSource(stackTrace, trackedFiles);
|
||||||
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.getRelativePathFromUrl((_e = test.testStart.test.url) !== null && _e !== void 0 ? _e : '', workDir);
|
const testStartPath = this.getRelativePath(testSuite.suite.path);
|
||||||
if (trackedFiles.includes(testStartPath)) {
|
if (trackedFiles.includes(testStartPath)) {
|
||||||
path = testStartPath;
|
path = testStartPath;
|
||||||
|
line = (_f = (_e = test.testStart.test.root_line) !== null && _e !== void 0 ? _e : test.testStart.test.line) !== null && _f !== void 0 ? _f : undefined;
|
||||||
}
|
}
|
||||||
line = (_f = test.testStart.test.line) !== null && _f !== void 0 ? _f : undefined;
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
path,
|
path,
|
||||||
|
|
@ -336,15 +335,12 @@ class DartJsonParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getRelativePathFromUrl(file, workDir) {
|
getRelativePath(path) {
|
||||||
const prefix = 'file:///';
|
const { workDir } = this.options;
|
||||||
if (file.startsWith(prefix)) {
|
if (path.startsWith(workDir)) {
|
||||||
file = file.substr(prefix.length);
|
path = path.substr(workDir.length);
|
||||||
}
|
}
|
||||||
if (file.startsWith(workDir)) {
|
return file_utils_1.normalizeFilePath(path);
|
||||||
file = file.substr(workDir.length);
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.DartJsonParser = DartJsonParser;
|
exports.DartJsonParser = DartJsonParser;
|
||||||
|
|
|
||||||
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
|
|
@ -87,7 +87,7 @@ export class DartJsonParser implements TestParser {
|
||||||
return JSON.parse(str)
|
return JSON.parse(str)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const col = e.columnNumber !== undefined ? `:${e.columnNumber}` : ''
|
const col = e.columnNumber !== undefined ? `:${e.columnNumber}` : ''
|
||||||
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[]
|
||||||
|
|
@ -123,7 +123,7 @@ export class DartJsonParser implements TestParser {
|
||||||
|
|
||||||
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(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)
|
||||||
|
|
@ -135,22 +135,20 @@ export class DartJsonParser implements TestParser {
|
||||||
|
|
||||||
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 => this.getTest(t))
|
const tests = group.tests.map(tc => {
|
||||||
|
const error = this.getError(suite, tc)
|
||||||
|
return new TestCaseResult(tc.testStart.test.name, tc.result, tc.time, error)
|
||||||
|
})
|
||||||
return new TestGroupResult(group.group.name, tests)
|
return new TestGroupResult(group.group.name, tests)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private getTest(tc: TestCase): TestCaseResult {
|
private getError(testSuite: TestSuite, test: TestCase): TestCaseError | undefined {
|
||||||
const error = this.getError(tc)
|
|
||||||
return new TestCaseResult(tc.testStart.test.name, tc.result, tc.time, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
private getError(test: TestCase): TestCaseError | undefined {
|
|
||||||
if (!this.options.parseErrors || !test.error) {
|
if (!this.options.parseErrors || !test.error) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
const {workDir, trackedFiles} = this.options
|
const {trackedFiles} = this.options
|
||||||
const message = test.error?.error ?? ''
|
const message = test.error?.error ?? ''
|
||||||
const stackTrace = test.error?.stackTrace ?? ''
|
const stackTrace = test.error?.stackTrace ?? ''
|
||||||
const src = this.exceptionThrowSource(stackTrace, trackedFiles)
|
const src = this.exceptionThrowSource(stackTrace, trackedFiles)
|
||||||
|
|
@ -158,13 +156,14 @@ export class DartJsonParser implements TestParser {
|
||||||
let line
|
let line
|
||||||
|
|
||||||
if (src !== undefined) {
|
if (src !== undefined) {
|
||||||
;(path = src.path), (line = src.line)
|
path = src.path
|
||||||
|
line = src.line
|
||||||
} else {
|
} else {
|
||||||
const testStartPath = this.getRelativePathFromUrl(test.testStart.test.url ?? '', workDir)
|
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.line ?? undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -195,14 +194,11 @@ export class DartJsonParser implements TestParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getRelativePathFromUrl(file: string, workDir: string): string {
|
private getRelativePath(path: string): string {
|
||||||
const prefix = 'file:///'
|
const {workDir} = this.options
|
||||||
if (file.startsWith(prefix)) {
|
if (path.startsWith(workDir)) {
|
||||||
file = file.substr(prefix.length)
|
path = path.substr(workDir.length)
|
||||||
}
|
}
|
||||||
if (file.startsWith(workDir)) {
|
return normalizeFilePath(path)
|
||||||
file = file.substr(workDir.length)
|
|
||||||
}
|
|
||||||
return file
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue