From d0bccc40334bd6a9236f42c8e150a76bb3215fe4 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 2 Nov 2020 08:31:05 +0100 Subject: [PATCH] also validate in haste-map --- e2e/__tests__/crawlSymlinks.test.ts | 20 ++++++++++++++++++++ packages/jest-haste-map/src/index.ts | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/e2e/__tests__/crawlSymlinks.test.ts b/e2e/__tests__/crawlSymlinks.test.ts index 32d2f78068e9..1c0ce9db2b13 100644 --- a/e2e/__tests__/crawlSymlinks.test.ts +++ b/e2e/__tests__/crawlSymlinks.test.ts @@ -6,6 +6,7 @@ */ import {tmpdir} from 'os'; import * as path from 'path'; +import {wrap} from 'jest-snapshot-serializer-raw'; import {cleanup, writeFiles, writeSymlinks} from '../Utils'; import runJest from '../runJest'; @@ -69,3 +70,22 @@ test('Node crawler does not pick up symlinked files by default', () => { expect(stderr).toEqual(''); expect(exitCode).toEqual(1); }); + +test('Should throw if watchman used with haste.enableSymlinks', () => { + init({'.watchmanconfig': JSON.stringify({})}); + + const {stdout, stderr, exitCode} = runJest(DIR, [ + '--haste={"enableSymlinks": true}', + '--watchman', + ]); + + expect(stdout).toEqual(''); + expect(wrap(stderr)).toMatchInlineSnapshot(` + Validation Error: + + haste.enableSymlinks is incompatible with watchman + + Either set haste.enableSymlinks to false or do not use watchman + `); + expect(exitCode).toEqual(1); +}); diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index cc350d66a2bf..6300b21a262b 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -278,6 +278,14 @@ class HasteMap extends EventEmitter { this._options.ignorePattern = new RegExp(VCS_DIRECTORIES); } + if (this._options.enableSymlinks && this._options.useWatchman) { + 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 ', + ); + } + const rootDirHash = createHash('md5').update(options.rootDir).digest('hex'); let hasteImplHash = ''; let dependencyExtractorHash = '';