Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include test invocation in trace #2723

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/reporters/beautify-stack.js
Expand Up @@ -23,6 +23,8 @@ const stackUtils = new StackUtils({
]
});

exports.stackUtils = stackUtils;

/*
* Given a string value of the format generated for the `stack` property of a
* V8 error object, return a string that contains only stack frame information
Expand Down Expand Up @@ -59,7 +61,7 @@ const stackUtils = new StackUtils({
* Module.runMain (module.js:604:10)
* ```
*/
module.exports = stack => {
exports.beautifyStack = stack => {
if (!stack) {
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/default.js
Expand Up @@ -13,7 +13,7 @@ const trimOffNewlines = require('trim-off-newlines');

const chalk = require('../chalk').get();
const codeExcerpt = require('../code-excerpt');
const beautifyStack = require('./beautify-stack');
const {beautifyStack} = require('./beautify-stack');
const colors = require('./colors');
const formatSerializedError = require('./format-serialized-error');
const improperUsageMessages = require('./improper-usage-messages');
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/tap.js
Expand Up @@ -7,7 +7,7 @@ const stripAnsi = require('strip-ansi');
const supertap = require('supertap');
const indentString = require('indent-string');

const beautifyStack = require('./beautify-stack');
const {beautifyStack} = require('./beautify-stack');
const prefixTitle = require('./prefix-title');

function dumpError(error) {
Expand Down
5 changes: 4 additions & 1 deletion lib/runner.js
Expand Up @@ -4,6 +4,7 @@ const matcher = require('matcher');
const ContextRef = require('./context-ref');
const createChain = require('./create-chain');
const parseTestArgs = require('./parse-test-args');
const {stackUtils} = require('./reporters/beautify-stack');
const snapshotManager = require('./snapshot-manager');
const serializeError = require('./serialize-error');
const Runnable = require('./test');
Expand Down Expand Up @@ -88,6 +89,8 @@ class Runner extends Emittery {
}

metadata.taskIndex = this.nextTaskIndex++;
const testInvocation = stackUtils.parseLine(stackUtils.captureString().split('\n')[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we should be capturing this at runtime. I'm a little concerned about any additional performance overhead, especially in files with lots of tests.

metadata.testLine = ` at test (${testInvocation.file}:${testInvocation.line}:${testInvocation.column})`;

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

Expand Down Expand Up @@ -366,7 +369,7 @@ class Runner extends Emittery {
this.emit('stateChange', {
type: 'test-failed',
title: result.title,
err: serializeError('Test failure', true, result.error, this.file),
err: serializeError('Test failure', true, result.error, this.file, task.metadata.testLine),
duration: result.duration,
knownFailing: result.metadata.failing,
logs: result.logs
Expand Down
8 changes: 5 additions & 3 deletions lib/serialize-error.js
Expand Up @@ -67,7 +67,7 @@ function buildSource(source) {
};
}

function trySerializeError(error, shouldBeautifyStack, testFile) {
function trySerializeError(error, shouldBeautifyStack, testFile, testLine) {
const stack = error.savedError ? error.savedError.stack : error.stack;

const retval = {
Expand All @@ -82,6 +82,8 @@ function trySerializeError(error, shouldBeautifyStack, testFile) {
retval.stack = error.actualStack;
}

retval.stack += `\n${testLine}`;

if (retval.avaAssertionError) {
retval.improperUsage = error.improperUsage;
retval.message = error.message;
Expand Down Expand Up @@ -143,7 +145,7 @@ function trySerializeError(error, shouldBeautifyStack, testFile) {
return retval;
}

function serializeError(origin, shouldBeautifyStack, error, testFile) {
function serializeError(origin, shouldBeautifyStack, error, testFile, testLine) {
if (!isError(error)) {
return {
avaAssertionError: false,
Expand All @@ -153,7 +155,7 @@ function serializeError(origin, shouldBeautifyStack, error, testFile) {
}

try {
return trySerializeError(error, shouldBeautifyStack, testFile);
return trySerializeError(error, shouldBeautifyStack, testFile, testLine);
} catch {
const replacement = new Error(`${origin}: Could not serialize error`);
return {
Expand Down