-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Better string and object diffs #406
Comments
Hah, opening an issue like this was already on my todo list. 👍 👍 Is this maybe something the |
Related power-assert-js/power-assert#31 |
Hmm. I don't know. It doesn't depend on // @twada |
It makes sense when the assertion has two args ( Rendering diffs between |
Oh yeah, forgot about BinaryExpressionRenderer - we definitely want good diffs if they do: t.true(someLongString === someOtherLongString) How about extending BinaryExpressionRenderer with a "minimumLength" parameter that prevents short diffs from being displayed, a diff for |
From Gitter, for posterity: jamestalmage ben-eb jamestalmage 01:05 ben-eb 01:06 jamestalmage 01:06 ben-eb 01:07 jamestalmage 01:08 ben-eb 01:10 jamestalmage 01:12 ben-eb 01:13 jamestalmage 01:14 ben-eb 01:18 ben-eb 01:40 ben-eb 03:17 |
@sindresorhus Oh thanks |
I'd love this feature by the way, but I'm not at all familiar with AVA's code base... |
As a workaround I've been doing this: export const same = (t, actual, expected, message) => {
return t.same(actual, expected, `
${message}
Actual:
${JSON.stringify(actual, null, 2).split("\n").join("\n ")}
Expected:
${JSON.stringify(expected, null, 2).split("\n").join("\n ")}
`);
}; and then using: same(t, actual, expected, message); instead of: t.same(actual, expected, message); |
@paulyoung Good trick! |
I've run into this lately. It makes it getting tests to pass quite cumbersome. Maybe we should step up the priority? @twada are you saying this should be fixed in |
@novemberborn I've started a new power-assert-runtime modules in a monorepo style and deprecate First alpha version is already published and the first beta version will be released soon, maybe this weekend.
Therefore, this issue would be fixed in new power-assert-runtime repo. I'll migrate Sorry for inconvenience 🙇 Let's go forward together. |
@twada cool, I just started watching the new repo 😄 |
I have to admit that long multilines string can be a pain
And in the terminal, it's even worst because you cannot scroll horizontally :) |
Doing something similar to @paulyoung import chalk from 'chalk';
import * as JsDiff from 'diff';
// warning!
// t.deepEqual() tests attribute order while prettyDiff() does not
export function deepEqual(t, actual, expected) {
t.deepEqual(actual, expected, prettyDiff(actual, expected));
}
export function prettyDiff(actual, expected) {
const diff = JsDiff.diffJson(expected, actual).map(part => {
if (part.added) return chalk.green(part.value.replace(/.+/g, ' - $&'));
if (part.removed) return chalk.red(part.value.replace(/.+/g, ' + $&'));
return chalk.gray(part.value.replace(/.+/g, ' | $&'));
}).join('');
return `\n${diff}\n`;
} diff 2.2.2 |
Also something similar to @wenzowski and @paulyoung but with less moving parts: import difflet from 'difflet'
const diff = difflet({ indent: 2 })
export default function deepEqual(t, actual, expected) {
t.deepEqual(actual, expected, diff.compare(actual, expected))
} difflet@1.0.1 |
Is anyone working on this? |
@calebmer I don't think so, want to help? |
@sotojuan what was the last idea to fix this? |
@creeperyang It's being worked on in #1154. |
Great! 👍 |
#1154 is merged! Is this issue closeable now? Or are you waiting for the release? |
@hughrawlinson that's in the release, so yup, this issue can be closed. Thanks for reminding us. |
The
power-assert
output is great except for long strings and moderate to large sized JSON objects.I think for those cases, it is probably better to just output a diff. Something similar to mocha.
(I'm almost certain there was an issue raised about this already, but I couldn't find it quickly).
The text was updated successfully, but these errors were encountered: