Skip to content

Commit 161da2e

Browse files
committed
Don't local require perttier in jest-jasmine2
1 parent 7caef39 commit 161da2e

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Fixes
88

99
- `[babel-jest]` Make `getCacheKey()` take into account `createTransformer` options ([#6699](https://github.com/facebook/jest/pull/6699))
10+
- `[jest-jasmine2]` Use prettier through `require` instead of `localRequire`. Fixes `matchInlineSnapshot` where prettier dependencies like `path` and `fs` are mocked with `jest.mock`. ([#6776](https://github.com/facebook/jest/pull/6776))
1011
- `[docs]` Fix contributors link ([#6711](https://github.com/facebook/jest/pull/6711))
1112
- `[website]` Fix website versions page to link to correct language ([#6734](https://github.com/facebook/jest/pull/6734))
1213

e2e/__tests__/to_match_inline_snapshot.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,20 @@ test('supports async tests', () => {
163163
expect(status).toBe(0);
164164
expect(fileAfter).toMatchSnapshot();
165165
});
166+
167+
// issue: https://github.com/facebook/jest/issues/6702
168+
test('handles mocking native modules prettier relies on', () => {
169+
const filename = 'mockFail.test.js';
170+
const test = `
171+
jest.mock('path', () => ({}));
172+
jest.mock('fs', () => ({}));
173+
test('inline snapshots', () => {
174+
expect({}).toMatchInlineSnapshot();
175+
});
176+
`;
177+
178+
writeFiles(TESTS_DIR, {[filename]: test});
179+
const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]);
180+
expect(stderr).toMatch('1 snapshot written from 1 test suite.');
181+
expect(status).toBe(0);
182+
});

packages/jest-jasmine2/src/setup_jest_globals.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ export default ({
102102
expand,
103103
getBabelTraverse: () => require('babel-traverse').default,
104104
getPrettier: () =>
105-
config.prettierPath ? localRequire(config.prettierPath) : null,
105+
// $FlowFixMe dynamic require
106+
config.prettierPath ? require(config.prettierPath) : null,
106107
updateSnapshot,
107108
});
108109
setState({snapshotState, testPath});

0 commit comments

Comments
 (0)