From 6d744dd93998de676177c9ee9eb840e9ec2bcae3 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Mon, 1 Oct 2018 22:48:01 +0100 Subject: [PATCH] Fix absolute paths on eject (#5214) --- scripts/utils/createJestConfig.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/utils/createJestConfig.js b/scripts/utils/createJestConfig.js index af085383f0..040c1f58b6 100644 --- a/scripts/utils/createJestConfig.js +++ b/scripts/utils/createJestConfig.js @@ -22,8 +22,20 @@ module.exports = (resolve, rootDir, isEjecting) => { // in Jest configs. We need help from somebody with Windows to determine this. const config = { collectCoverageFrom: ['src/**/*.{js,jsx}'], - resolver: require.resolve('jest-pnp-resolver'), - setupFiles: [require.resolve('react-app-polyfill/jsdom')], + + // TODO: this breaks Yarn PnP on eject. + // But we can't simply emit this because it'll be an absolute path. + // The proper fix is to write jest.config.js on eject instead of a package.json key. + // Then these can always stay as require.resolve()s. + resolver: isEjecting + ? 'jest-pnp-resolver' + : require.resolve('jest-pnp-resolver'), + setupFiles: [ + isEjecting + ? 'react-app-polyfill/jsdom' + : require.resolve('react-app-polyfill/jsdom'), + ], + setupTestFrameworkScriptFile: setupTestsFile, testMatch: [ '/src/**/__tests__/**/*.{js,jsx}',