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

fix(testing/snapshot): handle multiline strings #2166

Merged
merged 1 commit into from
May 3, 2022

Conversation

bcheidemann
Copy link
Contributor

Fix for #2142

@@ -29,7 +29,7 @@ function serialize(actual: unknown): string {
compact: false,
iterableLimit: Infinity,
strAbbreviateSize: Infinity,
});
}).replace(/\\n/g, "\n");
Copy link
Member

Choose a reason for hiding this comment

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

With this change, the expression "..." isn't canonical string literal anymore if it contains \n.

I think it's ok and works in most cases.

But does anyone have any concern about this transformation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this is also how it is in Jest but that doesn't necessarily mean it's how it should be done here. The alternative I considered was:

await assertSnapshot("Hello\nWorld!");

export[`snapshot`] = `
\`Hello
World!\`
`;

But I felt that this has two downsides:

  1. The snapshot is less readable due to the presence of escape characters
  2. It would require significant changes to Deno.inspect and I was concerned about cluttering the API with options that have no use case (at least not that I can think of!) outside of snapshot testing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am currently working on improving the API for assertSnapshot to allow an options object. We could offer an option preserveCanonicalStringLiterals if this is something people care about.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the clarification.

The snapshot is less readable due to the presence of escape characters

I think readability of snapshot is more important. I'm in favor of the current approach.

I am currently working on improving the API for assertSnapshot to allow an options object. We could offer an option preserveCanonicalStringLiterals if this is something people care about.

Right, we can improve it later based on the feedbacks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this change, the expression "..." isn't canonical string literal anymore if it contains \n.

I think it's ok and works in most cases.

But does anyone have any concern about this transformation?

@kt3k Are we still waiting for feedback on this?

Copy link
Member

Choose a reason for hiding this comment

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

Let's land and try to see the community feedback. Thanks for your contribution!

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM

@kt3k kt3k merged commit d9fd8a1 into denoland:main May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants