|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +import * as path from 'path'; |
| 9 | +import {cleanup, runYarnInstall, writeFiles} from '../Utils'; |
| 10 | +import runJest from '../runJest'; |
| 11 | + |
| 12 | +const DIR = path.resolve( |
| 13 | + __dirname, |
| 14 | + '../to-match-inline-snapshot-with-prettier-3', |
| 15 | +); |
| 16 | +const TESTS_DIR = path.resolve(DIR, '__tests__'); |
| 17 | +const JEST_CONFIG_PATH = path.resolve(DIR, 'jest.config.js'); |
| 18 | + |
| 19 | +beforeAll(() => { |
| 20 | + runYarnInstall(DIR); |
| 21 | +}); |
| 22 | +beforeEach(() => { |
| 23 | + cleanup(TESTS_DIR); |
| 24 | + cleanup(JEST_CONFIG_PATH); |
| 25 | +}); |
| 26 | +afterAll(() => { |
| 27 | + cleanup(TESTS_DIR); |
| 28 | + cleanup(JEST_CONFIG_PATH); |
| 29 | +}); |
| 30 | + |
| 31 | +test('throws correct error', () => { |
| 32 | + writeFiles(DIR, { |
| 33 | + 'jest.config.js': ` |
| 34 | + module.exports = {prettierPath: require.resolve('prettier')}; |
| 35 | + `, |
| 36 | + }); |
| 37 | + writeFiles(TESTS_DIR, { |
| 38 | + 'test.js': ` |
| 39 | + test('snapshots', () => { |
| 40 | + expect(3).toMatchInlineSnapshot(); |
| 41 | + }); |
| 42 | + `, |
| 43 | + }); |
| 44 | + const {stderr, exitCode} = runJest(DIR, ['--ci=false']); |
| 45 | + expect(stderr).toContain( |
| 46 | + 'Jest: Inline Snapshots are not supported when using Prettier 3.0.0 or above.', |
| 47 | + ); |
| 48 | + expect(exitCode).toBe(1); |
| 49 | +}); |
| 50 | + |
| 51 | +test('supports passing `null` as `prettierPath`', () => { |
| 52 | + writeFiles(DIR, { |
| 53 | + 'jest.config.js': ` |
| 54 | + module.exports = {prettierPath: null}; |
| 55 | + `, |
| 56 | + }); |
| 57 | + writeFiles(TESTS_DIR, { |
| 58 | + 'test.js': ` |
| 59 | + test('snapshots', () => { |
| 60 | + expect(3).toMatchInlineSnapshot(); |
| 61 | + }); |
| 62 | + `, |
| 63 | + }); |
| 64 | + const {stderr, exitCode} = runJest(DIR, ['--ci=false']); |
| 65 | + expect(stderr).toContain('Snapshots: 1 written, 1 total'); |
| 66 | + expect(exitCode).toBe(0); |
| 67 | +}); |
| 68 | + |
| 69 | +test('supports passing `prettier-2` as `prettierPath`', () => { |
| 70 | + writeFiles(DIR, { |
| 71 | + 'jest.config.js': ` |
| 72 | + module.exports = {prettierPath: require.resolve('prettier-2')}; |
| 73 | + `, |
| 74 | + }); |
| 75 | + writeFiles(TESTS_DIR, { |
| 76 | + 'test.js': ` |
| 77 | + test('snapshots', () => { |
| 78 | + expect(3).toMatchInlineSnapshot(); |
| 79 | + }); |
| 80 | + `, |
| 81 | + }); |
| 82 | + const {stderr, exitCode} = runJest(DIR, ['--ci=false']); |
| 83 | + expect(stderr).toContain('Snapshots: 1 written, 1 total'); |
| 84 | + expect(exitCode).toBe(0); |
| 85 | +}); |
0 commit comments