From 17bde04d99ea22ef5ded0e109d76c17fb4b71bf0 Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Mon, 17 Jul 2017 17:14:51 +0100 Subject: [PATCH] jest-haste-map: add test case for broken handling of ignore pattern (#4047) --- .../src/__tests__/index.test.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/jest-haste-map/src/__tests__/index.test.js b/packages/jest-haste-map/src/__tests__/index.test.js index 455671780cdb..10ef316f7c6d 100644 --- a/packages/jest-haste-map/src/__tests__/index.test.js +++ b/packages/jest-haste-map/src/__tests__/index.test.js @@ -548,6 +548,36 @@ describe('HasteMap', () => { }); }); + it('discards the cache when configuration changes (broken)', () => { + return new HasteMap(defaultConfig) + .build() + .then(() => { + fs.readFileSync.mockClear(); + + // Explicitly mock that no files have changed. + mockChangedFiles = Object.create(null); + + // Watchman would give us different clocks. + mockClocks = object({ + '/fruits': 'c:fake-clock:3', + '/vegetables': 'c:fake-clock:4', + }); + + const config = Object.assign( + {}, + defaultConfig, + {ignorePattern: /kiwi|pear/}, + ); + return new HasteMap(config) + .build() + .then(({moduleMap}) => { + // `getModule` should actually return `null` here, because Pear + // should get ignored by the pattern. + expect(typeof moduleMap.getModule('Pear')).toBe('string'); + }); + }); + }); + it('ignores files that do not exist', () => { const watchman = require('../crawlers/watchman'); const mockImpl = watchman.getMockImplementation();