Fix dart-json not stripping cwd from suite paths

This commit is contained in:
Michal Dorner 2021-02-01 12:05:15 +01:00
parent 9c4a2c56d7
commit 2365963b2e
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
5 changed files with 41 additions and 49 deletions

View file

@ -3,9 +3,9 @@
**6** tests were completed in **3.760s** with **1** passed, **4** failed and **1** skipped.
|Test suite|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:|
|[test\main_test.dart](#r0s0)|1✔|3❌||74ms|
|[test\second_test.dart](#r0s1)||1❌|1✖|51ms|
### <a id="user-content-r0s0" href="#r0s0">test\main_test.dart</a>
|[test/main_test.dart](#r0s0)|1✔|3❌||74ms|
|[test/second_test.dart](#r0s1)||1❌|1✖|51ms|
### <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.
**Test 1**
@ -23,7 +23,7 @@
|Result|Test|Time|
|:---:|:---|---:|
|❌|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.
|Result|Test|Time|

View file

@ -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,
},
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,
},
],

38
dist/index.js generated vendored
View file

@ -235,7 +235,7 @@ class DartJsonParser {
}
catch (e) {
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);
@ -272,7 +272,7 @@ class DartJsonParser {
}
getTestRunResult(tr) {
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);
}
@ -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); });
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); });
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);
});
}
getTest(tc) {
const error = this.getError(tc);
return new test_results_1.TestCaseResult(tc.testStart.test.name, tc.result, tc.time, error);
}
getError(test) {
getError(testSuite, test) {
var _a, _b, _c, _d, _e, _f;
if (!this.options.parseErrors || !test.error) {
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 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);
path = src.path;
line = src.line;
}
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)) {
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 {
path,
@ -336,15 +335,12 @@ class DartJsonParser {
}
}
}
getRelativePathFromUrl(file, workDir) {
const prefix = 'file:///';
if (file.startsWith(prefix)) {
file = file.substr(prefix.length);
getRelativePath(path) {
const { workDir } = this.options;
if (path.startsWith(workDir)) {
path = path.substr(workDir.length);
}
if (file.startsWith(workDir)) {
file = file.substr(workDir.length);
}
return file;
return file_utils_1.normalizeFilePath(path);
}
}
exports.DartJsonParser = DartJsonParser;

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -87,7 +87,7 @@ export class DartJsonParser implements TestParser {
return JSON.parse(str)
} catch (e) {
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[]
@ -123,7 +123,7 @@ export class DartJsonParser implements TestParser {
private getTestRunResult(tr: TestRun): TestRunResult {
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)
@ -135,22 +135,20 @@ export class DartJsonParser implements TestParser {
return groups.map(group => {
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)
})
}
private getTest(tc: TestCase): TestCaseResult {
const error = this.getError(tc)
return new TestCaseResult(tc.testStart.test.name, tc.result, tc.time, error)
}
private getError(test: TestCase): TestCaseError | undefined {
private getError(testSuite: TestSuite, test: TestCase): TestCaseError | undefined {
if (!this.options.parseErrors || !test.error) {
return undefined
}
const {workDir, trackedFiles} = this.options
const {trackedFiles} = this.options
const message = test.error?.error ?? ''
const stackTrace = test.error?.stackTrace ?? ''
const src = this.exceptionThrowSource(stackTrace, trackedFiles)
@ -158,13 +156,14 @@ export class DartJsonParser implements TestParser {
let line
if (src !== undefined) {
;(path = src.path), (line = src.line)
path = src.path
line = src.line
} else {
const testStartPath = this.getRelativePathFromUrl(test.testStart.test.url ?? '', workDir)
const testStartPath = this.getRelativePath(testSuite.suite.path)
if (trackedFiles.includes(testStartPath)) {
path = testStartPath
line = test.testStart.test.root_line ?? test.testStart.test.line ?? undefined
}
line = test.testStart.test.line ?? undefined
}
return {
@ -195,14 +194,11 @@ export class DartJsonParser implements TestParser {
}
}
private getRelativePathFromUrl(file: string, workDir: string): string {
const prefix = 'file:///'
if (file.startsWith(prefix)) {
file = file.substr(prefix.length)
private getRelativePath(path: string): string {
const {workDir} = this.options
if (path.startsWith(workDir)) {
path = path.substr(workDir.length)
}
if (file.startsWith(workDir)) {
file = file.substr(workDir.length)
}
return file
return normalizeFilePath(path)
}
}