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

chore(tests): use built-in snapshot matcher for fixtures #4710

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cardoso
Copy link
Contributor

@cardoso cardoso commented Oct 25, 2024

Details

Improves the experience a bit.

Before

Screenshot 2024-10-25 at 20 14 32

After

Screenshot 2024-10-25 at 20 13 27

Does this pull request introduce a breaking change?

  • ๐Ÿ˜ฎโ€๐Ÿ’จ No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • ๐Ÿคž No, it does not introduce an observable change.

GUS work item

@cardoso cardoso requested a review from a team as a code owner October 25, 2024 23:22
Comment on lines +136 to +148
try {
if (content === undefined) {
expect(fs.existsSync(outputPath)).toBe(false);
} else {
await expect(content).toMatchFileSnapshot(outputPath);
}
} catch (err) {
if (typeof err === 'object' && err !== null) {
Error.captureStackTrace(err, testFixtureDir);
}

throw err;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the content is undefined, toMatchFileSnapshot would create a file with the undefined as its content, so we check if the file doesn't exist instead.

Catching the error and capturing the stack trace makes sure the failure will be reported in the spec file instead of test-fixture-dir.ts .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant