Skip to content

Commit 604d040

Browse files
authored
fix: Ignore newlines in stacktrace locations (#227)
1 parent 0108cbf commit 604d040

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ const forEachLeaf = (test: vscode.TestItem, fn: (test: vscode.TestItem) => void)
579579

580580
const escapeRe = (str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
581581
const forceCRLF = (str: string) => str.replace(/(?<!\r)\n/gm, '\r\n');
582-
const locationRe = /\(([^):]+?):([0-9]+):([0-9]+)\)[ \t]*\r?\n?/g;
582+
const locationRe = /\(([^\r\n):]+?):([0-9]+):([0-9]+)\)[ \t]*\r?\n?/g;
583583

584584
/**
585585
* Replaces all stack frames in the stack with source-mapped equivalents.

src/test/integration/simple.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe('simple', () => {
3838
['skip-suite-2', [['addition'], ['subtraction']]],
3939
],
4040
],
41+
['stacktrace.test.js', [['stacktrace', [['should parse error location correctly']]]]],
4142
]);
4243
});
4344

@@ -58,6 +59,7 @@ describe('simple', () => {
5859
['skip-suite-2', [['addition'], ['subtraction']]],
5960
],
6061
],
62+
['stacktrace.test.js', [['stacktrace', [['should parse error location correctly']]]]],
6163
]);
6264
});
6365

@@ -78,6 +80,7 @@ describe('simple', () => {
7880
['skip-suite-2', [['addition'], ['subtraction']]],
7981
],
8082
],
83+
['stacktrace.test.js', [['stacktrace', [['should parse error location correctly']]]]],
8184
]);
8285
});
8386

@@ -106,6 +109,8 @@ describe('simple', () => {
106109
['skip-suite-2', [['addition'], ['subtraction']]],
107110
],
108111
],
112+
113+
['stacktrace.test.js', [['stacktrace', [['should parse error location correctly']]]]],
109114
]);
110115
});
111116

@@ -133,6 +138,11 @@ describe('simple', () => {
133138
'skip.test.js/skip-suite-1/subtraction': ['enqueued', 'skipped'],
134139
'skip.test.js/skip-suite-2/addition': ['enqueued', 'skipped'],
135140
'skip.test.js/skip-suite-2/subtraction': ['enqueued', 'started', 'passed'],
141+
'stacktrace.test.js/stacktrace/should parse error location correctly': [
142+
'enqueued',
143+
'started',
144+
'failed',
145+
],
136146
});
137147
});
138148

@@ -246,6 +256,11 @@ describe('simple', () => {
246256
'skip.test.js/skip-suite-1/subtraction': ['enqueued', 'skipped'],
247257
'skip.test.js/skip-suite-2/addition': ['enqueued', 'skipped'],
248258
'skip.test.js/skip-suite-2/subtraction': ['enqueued', 'started', 'passed'],
259+
'stacktrace.test.js/stacktrace/should parse error location correctly': [
260+
'enqueued',
261+
'started',
262+
'failed',
263+
],
249264
});
250265
});
251266

@@ -275,6 +290,38 @@ describe('simple', () => {
275290
['skip-suite-2', [['addition'], ['subtraction']]],
276291
],
277292
],
293+
['stacktrace.test.js', [['stacktrace', [['should parse error location correctly']]]]],
278294
]);
279295
});
296+
297+
it('parses error stacktrace correctly', async () => {
298+
const c = await getController();
299+
const profiles = c.profiles;
300+
expect(profiles).to.have.lengthOf(2);
301+
302+
const item = c.ctrl.items.get('stacktrace.test.js')!;
303+
const run = await captureTestRun(
304+
c,
305+
new vscode.TestRunRequest(
306+
[item],
307+
undefined,
308+
profiles.find((p) => p.kind === vscode.TestRunProfileKind.Run),
309+
),
310+
);
311+
312+
run.expectStates({
313+
'stacktrace.test.js/stacktrace/should parse error location correctly': [
314+
'enqueued',
315+
'started',
316+
'failed',
317+
],
318+
});
319+
320+
const failed = run.states.find((s) => s.state === 'failed');
321+
expect(failed!.message!.location!.range.start.line).to.equal(4);
322+
expect(failed!.message!.location!.range.start.character).to.equal(11);
323+
expect(failed!.message!.location!.range.end.line).to.equal(4);
324+
expect(failed!.message!.location!.range.end.character).to.equal(11);
325+
expect(failed!.message!.location!.uri.fsPath).to.equal(item.uri!.fsPath);
326+
});
280327
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
describe('stacktrace', () => {
2+
it('should parse error location correctly', function () {
3+
console.log('before');
4+
throw new Error('(...');
5+
console.log('after');
6+
});
7+
});

0 commit comments

Comments
 (0)