Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Error if
prettier@3
is used for inline snapshots (#14367)
- Loading branch information
Showing
6 changed files
with
175 additions
and
2 deletions.
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