-
-
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
fix: Error if prettier@3
is used for inline snapshots
#14367
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import * as path from 'path'; | ||
import {cleanup, runYarnInstall, writeFiles} from '../Utils'; | ||
import runJest from '../runJest'; | ||
|
||
const DIR = path.resolve( | ||
__dirname, | ||
'../to-match-inline-snapshot-with-prettier-3', | ||
); | ||
const TESTS_DIR = path.resolve(DIR, '__tests__'); | ||
const JEST_CONFIG_PATH = path.resolve(DIR, 'jest.config.js'); | ||
|
||
beforeAll(() => { | ||
runYarnInstall(DIR); | ||
}); | ||
beforeEach(() => { | ||
cleanup(TESTS_DIR); | ||
cleanup(JEST_CONFIG_PATH); | ||
}); | ||
afterAll(() => { | ||
cleanup(TESTS_DIR); | ||
cleanup(JEST_CONFIG_PATH); | ||
}); | ||
|
||
test('throws correct error', () => { | ||
writeFiles(DIR, { | ||
'jest.config.js': ` | ||
module.exports = {prettierPath: require.resolve('prettier')}; | ||
`, | ||
}); | ||
writeFiles(TESTS_DIR, { | ||
'test.js': ` | ||
test('snapshots', () => { | ||
expect(3).toMatchInlineSnapshot(); | ||
}); | ||
`, | ||
}); | ||
const {stderr, exitCode} = runJest(DIR, ['--ci=false']); | ||
expect(stderr).toContain( | ||
'Jest: Inline Snapshots are not supported when using Prettier 3.0.0 or above.', | ||
); | ||
expect(exitCode).toBe(1); | ||
}); | ||
|
||
test('supports passing `null` as `prettierPath`', () => { | ||
writeFiles(DIR, { | ||
'jest.config.js': ` | ||
module.exports = {prettierPath: null}; | ||
`, | ||
}); | ||
writeFiles(TESTS_DIR, { | ||
'test.js': ` | ||
test('snapshots', () => { | ||
expect(3).toMatchInlineSnapshot(); | ||
}); | ||
`, | ||
}); | ||
const {stderr, exitCode} = runJest(DIR, ['--ci=false']); | ||
expect(stderr).toContain('Snapshots: 1 written, 1 total'); | ||
expect(exitCode).toBe(0); | ||
}); | ||
|
||
test('supports passing `prettier-2` as `prettierPath`', () => { | ||
writeFiles(DIR, { | ||
'jest.config.js': ` | ||
module.exports = {prettierPath: require.resolve('prettier-2')}; | ||
`, | ||
}); | ||
writeFiles(TESTS_DIR, { | ||
'test.js': ` | ||
test('snapshots', () => { | ||
expect(3).toMatchInlineSnapshot(); | ||
}); | ||
`, | ||
}); | ||
const {stderr, exitCode} = runJest(DIR, ['--ci=false']); | ||
expect(stderr).toContain('Snapshots: 1 written, 1 total'); | ||
expect(exitCode).toBe(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"devDependencies": { | ||
"prettier": "^3.0.0", | ||
"prettier-2": "npm:prettier@^2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This file is generated by running "yarn install" inside your project. | ||
# Manual changes might be lost - proceed with caution! | ||
|
||
__metadata: | ||
version: 6 | ||
cacheKey: 8 | ||
|
||
"prettier-2@npm:prettier@^2": | ||
version: 2.8.8 | ||
resolution: "prettier@npm:2.8.8" | ||
bin: | ||
prettier: bin-prettier.js | ||
checksum: b49e409431bf129dd89238d64299ba80717b57ff5a6d1c1a8b1a28b590d998a34e083fa13573bc732bb8d2305becb4c9a4407f8486c81fa7d55100eb08263cf8 | ||
languageName: node | ||
linkType: hard | ||
|
||
"prettier@npm:^3.0.0": | ||
version: 3.0.0 | ||
resolution: "prettier@npm:3.0.0" | ||
bin: | ||
prettier: bin/prettier.cjs | ||
checksum: 6a832876a1552dc58330d2467874e5a0b46b9ccbfc5d3531eb69d15684743e7f83dc9fbd202db6270446deba9c82b79d24383d09924c462b457136a759425e33 | ||
languageName: node | ||
linkType: hard | ||
|
||
"root-workspace-0b6124@workspace:.": | ||
version: 0.0.0-use.local | ||
resolution: "root-workspace-0b6124@workspace:." | ||
dependencies: | ||
prettier: ^3.0.0 | ||
prettier-2: "npm:prettier@^2" | ||
languageName: unknown | ||
linkType: soft |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've forgotten to roll 29.6 docs - will do so after landing this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about wrapping this block in some
:::info
admonition?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooh,
details
look great! didn't know docusaurus formatted itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://deploy-preview-14367--jestjs.netlify.app/docs/next/configuration#prettierpath-string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
details
is a rarely useful feature, but for my eye it’s just perfect in this case.