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 Jest inline snapshots #1963

Closed
wants to merge 1 commit into from
Closed

Conversation

jeremywiebe
Copy link
Collaborator

@jeremywiebe jeremywiebe commented Dec 6, 2024

Summary:

While writing some tests, I wanted to use inline snapshots, but Jest complained that inline snapshots aren't supported on Prettier v3 (which we use).

The solution is to install Prettier v2 beside v3 and customize Jest to use v2.

Support for Prettier v3 has already landed and will be in Jest 30 but the last I saw was an issue comment from Oct 2023 and even then the author was unsure when it would be released. I'll just use the workaround for now.

Issue: "none"

Test plan:

Find a test that uses .toMatchInlineSnapshot() and delete the snapshot string passed to the function.
Save the file
yarn test
Note that the snapshot string is back!

Screen.Recording.2024-12-05.at.7.34.53.PM.mov

@jeremywiebe jeremywiebe self-assigned this Dec 6, 2024
Copy link
Contributor

github-actions bot commented Dec 6, 2024

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (81fd4cd) and published it to npm. You
can install it using the tag PR1963.

Example:

yarn add @khanacademy/perseus@PR1963

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR1963

Copy link
Contributor

github-actions bot commented Dec 6, 2024

Size Change: 0 B

Total Size: 1.29 MB

ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 77.9 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-editor/dist/es/index.js 697 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus/dist/es/index.js 425 kB
packages/perseus/dist/es/strings.js 3.7 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.5 kB

compressed-size-action

@jeremywiebe jeremywiebe marked this pull request as ready for review December 6, 2024 03:35
@khan-actions-bot khan-actions-bot requested a review from a team December 6, 2024 03:36
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/perseus for changes to package.json, yarn.lock, config/test/test.config.js

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

@jeremywiebe jeremywiebe changed the title Fix inline snapshots Fix Jest inline snapshots Dec 6, 2024
@jeremywiebe
Copy link
Collaborator Author

Closing. This doesn't work as the prettier-2 instance gets installed in node_modules/.bin which then causes formatting issues when we check formatting with yarn prettier --check in GitHub Actions.

Abandoning for now. Wait for Jest v30. 😓

@jeremywiebe jeremywiebe closed this Dec 6, 2024
@jeremywiebe jeremywiebe deleted the jer/jest-inline-snapshots branch December 6, 2024 17:28
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