-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Bug]: Prettier v3 doesn't work with jest-snapshots #14305
Comments
Confirmed: if Prettier v3 is installed, Jest fails to update or create inline snapshots. Existing inline snapshots work fine if they are passing. Seems like this is similar to what |
Seems like it is possible to add |
I doubt we'll ever support Prettier v3 as we need it to work synchronously. However, we might be able to add support for |
That module is currently broken (prettier/prettier-synchronized#5), but I think it should work after that is released. We'll then have to look at the version of prettier we load, and decide which API to use |
|
Maybe |
That would great, of course. |
Right, good point. Passing a path for prettier sounds reasonable 👍 |
With the release of that, we should be able to integrate here. |
FWIW, added an explicit error in https://github.com/jestjs/jest/releases/tag/v29.6.2, and updated the docs with workarounds |
For anyone that lands here for a temporary fix, this works for now:
|
The suggestion above is a good idea, but it may have some problematic side effects: if I wish I could think of a better way around this, but the best I can come up with is a postinstall script to fix the link if needed: const path = require('path');
const fs = require('fs');
// TODO: Update this to point to your node_modules path relative to the script location
const nodeModulesPath = path.resolve(__dirname, 'node_modules');
const prettierBinPath = path.join(nodeModulesPath, '.bin/prettier');
if (fs.realpathSync(prettierBinPath).includes('prettier-2')) {
fs.rmSync(prettierBinPath);
const packageJson = JSON.parse(fs.readFileSync(path.join(nodeModulesPath, 'prettier/package.json'), 'utf-8'));
const binFile =
typeof packageJson.bin === 'string' ? packageJson.bin : packageJson.bin.prettier;
const realBinPath = path.join(nodeModulesPath, 'prettier', binFile);
fs.symlinkSync(realBinPath, prettierBinPath);
} |
Maybe making a new |
#### Details Due to jestjs/jest#14305, our inline snapshots are causing problems when using `yarn test -u`. We discussed this internally and decided that the simplest approach was to convert the inline snapshots to traditional snapshots. For most cases, this was just removing "Inline" from the method name and removing the string that provided the snapshot. A small number of test cases were checking multiple inline snapshots in the same test, so the approach there was to build an array of the things that were previously checked individually, then having a single snapshot for the test case. I ran `yarn test -u` and `yarn format:fix` after making all of the changes, just to make sure that we're ready for future changes. It will probably be easiest to review this one commit at a time--each of the 32 commits represents the conversion of a single test case. ##### Motivation <!-- This can be as simple as "addresses issue #123" --> ##### Context <!-- Are there any parts that you've intentionally left out-of-scope for a later PR to handle? --> <!-- Were there any alternative approaches you considered? What tradeoffs did you consider? --> #### Pull request checklist <!-- If a checklist item is not applicable to this change, write "n/a" in the checkbox --> - [n/a] Addresses an existing issue: - [x] Added relevant unit test for your changes. (`yarn test`) - [x] Verified code coverage for the changes made. Check coverage report at: `<rootDir>/test-results/unit/coverage` - [x] Ran precheckin (`yarn precheckin`)
#### Details Due to jestjs/jest#14305, our inline snapshots are causing problems when using `yarn test -u`. We discussed this internally and decided that the simplest approach was to convert the inline snapshots to traditional snapshots. For most cases, this was just removing "Inline" from the method name and removing the string that provided the snapshot. A small number of test cases were checking multiple inline snapshots in the same test, so the approach there was to build an array of the things that were previously checked individually, then having a single snapshot for the test case. I ran `yarn test -u` and `yarn format:fix` after making all of the changes, just to make sure that we're ready for future changes. It will probably be easiest to review this one commit at a time--each of the 32 commits represents the conversion of a single test case. ##### Motivation <!-- This can be as simple as "addresses issue #123" --> ##### Context <!-- Are there any parts that you've intentionally left out-of-scope for a later PR to handle? --> <!-- Were there any alternative approaches you considered? What tradeoffs did you consider? --> #### Pull request checklist <!-- If a checklist item is not applicable to this change, write "n/a" in the checkbox --> - [n/a] Addresses an existing issue - [x] Ran `yarn fastpass` - [x] Added/updated relevant unit test(s) (and ran `yarn test`) - [x] Verified code coverage for the changes made. Check coverage report at: `<rootDir>/test-results/unit/coverage` - [x] PR title *AND* final merge commit title both start with a semantic tag (`fix:`, `chore:`, `feat(feature-name):`, `refactor:`). See `CONTRIBUTING.md`. - [n/a] (UI changes only) Added screenshots/GIFs to description above - [n/a] (UI changes only) Verified usability with NVDA/JAWS
It'll be in Jest 30. Not sure when there'll be a release, but within the next few weeks, hopefully 🙂 |
Thanks for the good work! 💪🏻 |
KK-1017. More details: jestjs/jest#14305
KK-1017. More details: jestjs/jest#14305
The manual reason is because Prettier 3 isn't supported by Jest (yet). See [Jest docs](https://jestjs.io/docs/configuration/#prettierpath-string) and [this Jest tracking issue](jestjs/jest#14305).
* build(deps): lock file maintenance * Use @gr2m's fetch-mock * Update octokit/types version * Manually update snapshots The manual reason is because Prettier 3 isn't supported by Jest (yet). See [Jest docs](https://jestjs.io/docs/configuration/#prettierpath-string) and [this Jest tracking issue](jestjs/jest#14305). --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Keegan Campbell <me@kfcampbell.com>
KK-1017. More details: jestjs/jest#14305
KK-1017. More details: jestjs/jest#14305
@SimenB Do you know already when Jest v30 will be released? Is there some nightly release that I can install right now and use Prettier v3? |
I don't have a firm date in mind, but I can probably do a prerelease. Nightlies would be awesome (or CI publishing in general), but we don't have that at the moment, unfortunately. |
The version is needed because currently jest snapshots cannot be used if prettier 3 is used. It has been fixed but is not released in a non-alpha version. jestjs/jest#14305
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Version
29.6.1
Steps to reproduce
prettier@3.0.0
, which was just released yesterdayExpected behavior
The inline snapshot is updated
Actual behavior
Jest fails with
Additional context
Prettier just released v3, which removed this line that added the
sync
function toresolveConfig
. It looks likeeslint-plugin-prettier
ran into a similar problem. based on this issue.Environment
The text was updated successfully, but these errors were encountered: