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

test: better snapshot errors #4985

Merged
merged 5 commits into from
Dec 3, 2024
Merged

test: better snapshot errors #4985

merged 5 commits into from
Dec 3, 2024

Conversation

wjhsf
Copy link
Contributor

@wjhsf wjhsf commented Dec 2, 2024

Details

If you have a test fixture for a "success" scenario, it will generate an expected.html (or .js, etc) with content and an empty error.txt. If you then update some code and it causes a failure, then the test output will be an empty expected.html (or .js, etc) and an error.txt with content. The snapshot checker only compares files of the same name, so the output looks lomething like this:

 FAIL |lwc-ssr-compiler|  src/__tests__/fixtures.spec.ts > fixtures > wire/errors/throws-when-wired-prop-method-collision/index.js
Error: SSR Fixture `fixtures > wire/errors/throws-when-wired-prop-method-collision/index.js 1` mismatched

- Expected
+ Received

+ instance.wired is not a function

That's not very helpful, so I added some logic to check for that case (and the other way around), to make it more clear that your outputs have gotten mixed up.

 FAIL |lwc-ssr-compiler|  src/__tests__/fixtures.spec.ts > fixtures > wire/errors/throws-when-wired-prop-method-collision/index.js
AssertionError: Expected content in expected.html, but found content in error.txt.

- Expected
+ Received

- <x-wire>
-   <template shadowrootmode="open">
-     <div>
-       Wired? true
-     </div>
-     <div>
-       Using method? false
-     </div>
-   </template>
- </x-wire>
+ instance.wired is not a function

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.
  • 💔 Yes, it does introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.
  • 🔬 Yes, it does include an observable change.

GUS work item

@wjhsf wjhsf requested a review from a team as a code owner December 2, 2024 20:18
Copy link
Collaborator

@nolanlawson nolanlawson left a comment

Choose a reason for hiding this comment

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

Very nice!

const otherSnapshot = readFileSync(
path.resolve(dirname, otherName),
'utf8'
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a shame we have to keep reading in snapshot files when presumably Vitest is already doing this elsewhere.

? brokenSnapshot
: otherSnapshot,
actual: brokenResultHasContent ? brokenResult : otherResult,
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

TIL about AssertionError!

@nolanlawson nolanlawson changed the title Wjh/better snapshot errors test: better snapshot errors Dec 2, 2024
@wjhsf wjhsf merged commit ff79f53 into master Dec 3, 2024
11 checks passed
@wjhsf wjhsf deleted the wjh/better-snapshot-errors branch December 3, 2024 14:54
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