diff --git a/e2e/__tests__/crawlSymlinks.test.ts b/e2e/__tests__/crawlSymlinks.test.ts index 1c0ce9db2b13..8f59213ff0ae 100644 --- a/e2e/__tests__/crawlSymlinks.test.ts +++ b/e2e/__tests__/crawlSymlinks.test.ts @@ -74,10 +74,15 @@ test('Node crawler does not pick up symlinked files by default', () => { test('Should throw if watchman used with haste.enableSymlinks', () => { init({'.watchmanconfig': JSON.stringify({})}); - const {stdout, stderr, exitCode} = runJest(DIR, [ - '--haste={"enableSymlinks": true}', - '--watchman', - ]); + // it should throw both if watchman is explicitly provided and not + const run1 = runJest(DIR, ['--haste={"enableSymlinks": true}']); + const run2 = runJest(DIR, ['--haste={"enableSymlinks": true}', '--watchman']); + + expect(run1.exitCode).toEqual(run2.exitCode); + expect(run1.stderr).toEqual(run2.stderr); + expect(run1.stdout).toEqual(run2.stdout); + + const {exitCode, stderr, stdout} = run1; expect(stdout).toEqual(''); expect(wrap(stderr)).toMatchInlineSnapshot(` diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index ae3b198b2fed..6cde82c538e7 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -1714,3 +1714,26 @@ describe('testTimeout', () => { ).toThrowErrorMatchingSnapshot(); }); }); + +describe('haste.enableSymlinks', () => { + it('should throw if watchman is not disabled', () => { + expect(() => + normalize({haste: {enableSymlinks: true}, rootDir: '/root/'}, {}), + ).toThrow('haste.enableSymlinks is incompatible with watchman'); + + expect(() => + normalize( + {haste: {enableSymlinks: true}, rootDir: '/root/', watchman: true}, + {}, + ), + ).toThrow('haste.enableSymlinks is incompatible with watchman'); + + const {options} = normalize( + {haste: {enableSymlinks: true}, rootDir: '/root/', watchman: false}, + {}, + ); + + expect(options.haste.enableSymlinks).toBe(true); + expect(options.watchman).toBe(false); + }); +}); diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index 8e91123cb089..f9f8d6fe45c7 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -577,6 +577,10 @@ export default function normalize( }); } + if (options.watchman == null) { + options.watchman = DEFAULT_CONFIG.watchman; + } + const optionKeys = Object.keys(options) as Array; optionKeys.reduce((newOptions, key: keyof Config.InitialOptions) => { diff --git a/packages/jest-haste-map/src/__tests__/index.test.js b/packages/jest-haste-map/src/__tests__/index.test.js index 2e151abeb5c5..2f1833e313a6 100644 --- a/packages/jest-haste-map/src/__tests__/index.test.js +++ b/packages/jest-haste-map/src/__tests__/index.test.js @@ -517,6 +517,29 @@ describe('HasteMap', () => { }); }); + it('throws if both symlinks and watchman is enabled', () => { + expect( + () => new HasteMap({...defaultConfig, enableSymlinks: true}), + ).toThrow('Set either `enableSymlinks` to false or `watchman` to false.'); + expect( + () => + new HasteMap({ + ...defaultConfig, + enableSymlinks: true, + useWatchman: true, + }), + ).toThrow('Set either `enableSymlinks` to false or `watchman` to false.'); + + expect( + () => + new HasteMap({ + ...defaultConfig, + enableSymlinks: true, + useWatchman: false, + }), + ).not.toThrow(); + }); + describe('builds a haste map on a fresh cache with SHA-1s', () => { [false, true].forEach(useWatchman => { it('uses watchman: ' + useWatchman, async () => { diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index 6300b21a262b..20cbc089fab9 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -282,7 +282,7 @@ class HasteMap extends EventEmitter { throw new Error( 'jest-haste-map: enableSymlinks config option was set, but ' + 'is incompatible with watchman.\n' + - 'Set either `enableSymlinks` to false or `watchman` to false ', + 'Set either `enableSymlinks` to false or `watchman` to false.', ); }