Skip to content

Commit

Permalink
require skips nasty fs read
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 12, 2019
1 parent 05e4b8a commit c19c4b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
14 changes: 5 additions & 9 deletions packages/jest-haste-map/src/__tests__/index.test.js
Expand Up @@ -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");
`,
Expand Down Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -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();

Expand Down
7 changes: 3 additions & 4 deletions packages/jest-haste-map/src/index.ts
Expand Up @@ -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 {
Expand Down

0 comments on commit c19c4b4

Please sign in to comment.