Skip to content

Commit 337efa2

Browse files
Include test invocation in stack trace
1 parent 832f942 commit 337efa2

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/runner.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const matcher = require('matcher');
44
const ContextRef = require('./context-ref');
55
const createChain = require('./create-chain');
66
const parseTestArgs = require('./parse-test-args');
7+
const {stackUtils} = require('./reporters/beautify-stack');
78
const snapshotManager = require('./snapshot-manager');
89
const serializeError = require('./serialize-error');
910
const Runnable = require('./test');
@@ -88,6 +89,8 @@ class Runner extends Emittery {
8889
}
8990

9091
metadata.taskIndex = this.nextTaskIndex++;
92+
const testInvocation = stackUtils.parseLine(stackUtils.captureString().split('\n')[0]);
93+
metadata.testLine = ` at test (${testInvocation.file}:${testInvocation.line}:${testInvocation.column})`;
9194

9295
const {args, buildTitle, implementations, rawTitle} = parseTestArgs(testArgs);
9396

@@ -366,7 +369,7 @@ class Runner extends Emittery {
366369
this.emit('stateChange', {
367370
type: 'test-failed',
368371
title: result.title,
369-
err: serializeError('Test failure', true, result.error, this.file),
372+
err: serializeError('Test failure', true, result.error, this.file, task.metadata.testLine),
370373
duration: result.duration,
371374
knownFailing: result.metadata.failing,
372375
logs: result.logs

lib/serialize-error.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function buildSource(source) {
6767
};
6868
}
6969

70-
function trySerializeError(error, shouldBeautifyStack, testFile) {
70+
function trySerializeError(error, shouldBeautifyStack, testFile, testLine) {
7171
const stack = error.savedError ? error.savedError.stack : error.stack;
7272

7373
const retval = {
@@ -82,6 +82,8 @@ function trySerializeError(error, shouldBeautifyStack, testFile) {
8282
retval.stack = error.actualStack;
8383
}
8484

85+
retval.stack += `\n${testLine}`;
86+
8587
if (retval.avaAssertionError) {
8688
retval.improperUsage = error.improperUsage;
8789
retval.message = error.message;
@@ -143,7 +145,7 @@ function trySerializeError(error, shouldBeautifyStack, testFile) {
143145
return retval;
144146
}
145147

146-
function serializeError(origin, shouldBeautifyStack, error, testFile) {
148+
function serializeError(origin, shouldBeautifyStack, error, testFile, testLine) {
147149
if (!isError(error)) {
148150
return {
149151
avaAssertionError: false,
@@ -153,7 +155,7 @@ function serializeError(origin, shouldBeautifyStack, error, testFile) {
153155
}
154156

155157
try {
156-
return trySerializeError(error, shouldBeautifyStack, testFile);
158+
return trySerializeError(error, shouldBeautifyStack, testFile, testLine);
157159
} catch {
158160
const replacement = new Error(`${origin}: Could not serialize error`);
159161
return {

0 commit comments

Comments
 (0)