From ba542f4d1e742cff53b4bdb716c49110d0a91ed9 Mon Sep 17 00:00:00 2001 From: Tryggvi Gylfason Date: Sun, 29 Jul 2018 23:47:01 +0200 Subject: [PATCH] Don't local require perttier in jest-jasmine2 --- e2e/__tests__/to_match_inline_snapshot.test.js | 17 +++++++++++++++++ .../jest-jasmine2/src/setup_jest_globals.js | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/e2e/__tests__/to_match_inline_snapshot.test.js b/e2e/__tests__/to_match_inline_snapshot.test.js index f02ad696c316..54b0173ed6fd 100644 --- a/e2e/__tests__/to_match_inline_snapshot.test.js +++ b/e2e/__tests__/to_match_inline_snapshot.test.js @@ -163,3 +163,20 @@ test('supports async tests', () => { expect(status).toBe(0); expect(fileAfter).toMatchSnapshot(); }); + +// issue: https://github.com/facebook/jest/issues/6702 +test('handles mocking native modules prettier relies on', () => { + const filename = 'mockFail.test.js'; + const test = ` + jest.mock('path', () => ({})); + jest.mock('fs', () => ({})); + test('inline snapshots', () => { + expect({}).toMatchInlineSnapshot(); + }); + `; + + writeFiles(TESTS_DIR, {[filename]: test}); + const {stderr, status} = runJest(DIR, ['-w=1', '--ci=false', filename]); + expect(stderr).toMatch('1 snapshot written from 1 test suite.'); + expect(status).toBe(0); +}); diff --git a/packages/jest-jasmine2/src/setup_jest_globals.js b/packages/jest-jasmine2/src/setup_jest_globals.js index d839eb296f9e..c25b638ffd70 100644 --- a/packages/jest-jasmine2/src/setup_jest_globals.js +++ b/packages/jest-jasmine2/src/setup_jest_globals.js @@ -102,7 +102,8 @@ export default ({ expand, getBabelTraverse: () => require('babel-traverse').default, getPrettier: () => - config.prettierPath ? localRequire(config.prettierPath) : null, + // $FlowFixMe dynamic require + config.prettierPath ? require(config.prettierPath) : null, updateSnapshot, }); setState({snapshotState, testPath});