Skip to content

Diffing objects with ANSI codes are not escaped #3357

@colinta

Description

@colinta

I'm using ava to write tests that involve lots of ANSI codes, and the test output gets unwieldy. I'm surprised, actually, since ava is used to test chalk, I would think this would've come up before.

Anyway, ansi in this screenshot contains \x1b[31;41m and the output looks like this:

image

I narrowed down the search to assert.js

function formatDescriptorDiff(actualDescriptor, expectedDescriptor, options) {
	options = { ...options, ...concordanceOptions };
	const { diffGutters } = options.theme;
	const { insertLine, deleteLine } = options.theme.string.diff;
// here
	const formatted = concordance.diffDescriptors(
		actualDescriptor,
		expectedDescriptor,
		options,
	);
	return {
		label: `Difference (${diffGutters.actual}${deleteLine.open}actual${deleteLine.close}, ${diffGutters.expected}${insertLine.open}expected${insertLine.close}):`,
		formatted,
	};
}

options contains all the colorization, which makes sense. What I couldn't find was an option in concordance that would let me escape the input.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions