diff --git a/packages/jest-haste-map/src/__tests__/index.test.js b/packages/jest-haste-map/src/__tests__/index.test.js index bda4878ec8c9..c11a752bd8b9 100644 --- a/packages/jest-haste-map/src/__tests__/index.test.js +++ b/packages/jest-haste-map/src/__tests__/index.test.js @@ -146,9 +146,6 @@ describe('HasteMap', () => { mockEmitters = Object.create(null); mockFs = object({ - [require.resolve('../../package.json')]: JSON.stringify({ - version: '1.0.0', - }), '/project/fruits/Banana.js': ` const Strawberry = require("Strawberry"); `, @@ -519,8 +516,8 @@ describe('HasteMap', () => { expect(data.map.get('fbjs')).not.toBeDefined(); - // package.json + cache file + 5 modules - the node_module - expect(fs.readFileSync.mock.calls.length).toBe(7); + // cache file + 5 modules - the node_module + expect(fs.readFileSync.mock.calls.length).toBe(6); }); }); @@ -638,10 +635,9 @@ describe('HasteMap', () => { new HasteMap(defaultConfig) .build() .then(({__hasteMapForTest: initialData}) => { - // The first run should access the file system once for package.json, - // once for the (empty) cache file and five times for the files in the - // system. - expect(fs.readFileSync.mock.calls.length).toBe(7); + // The first run should access the file system once for the (empty) + // cache file and five times for the files in the system. + expect(fs.readFileSync.mock.calls.length).toBe(6); fs.readFileSync.mockClear(); diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index 641e1285386f..f6bd3bad058b 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -106,10 +106,9 @@ const CHANGE_INTERVAL = 30; const MAX_WAIT_TIME = 240000; const NODE_MODULES = path.sep + 'node_modules' + path.sep; -// TypeScript doesn't like us importing from outside `rootDir` -const {version: VERSION} = JSON.parse( - fs.readFileSync(require.resolve('../package.json'), 'utf8'), -); +// TypeScript doesn't like us importing from outside `rootDir`, but it doesn't +// understand `require`. +const {version: VERSION} = require('../package.json'); const canUseWatchman = ((): boolean => { try {