From bc05989dff9b62b30de4fea371c83a90e0b4cfcd Mon Sep 17 00:00:00 2001 From: Taki Komiyama <39375566+komtaki@users.noreply.github.com> Date: Sun, 6 Dec 2020 00:47:46 +0900 Subject: [PATCH] chore(jest-haste-map): remove support for ignorePattern as function (#10348) --- CHANGELOG.md | 1 + .../src/__tests__/index.test.js | 20 +++++++++---------- packages/jest-haste-map/src/index.ts | 10 ++-------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45f2fd4e0eb5..d406153b7969 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ - `[jest-console]` [**BREAKING**] Move `root` into `config` and take `GlobalConfig` as mandatory parameter for `getConsoleOutput` ([#10126](https://github.com/facebook/jest/pull/10126)) - `[jest-fake-timers]` Clarify global behavior of `jest.useFakeTimers` and `jest.useRealTimers` ([#10867](https://github.com/facebook/jest/pull/10867)) - `[jest-haste-map]` [**BREAKING**] Migrate to ESM ([#10875](https://github.com/facebook/jest/pull/10875)) +- `[jest-haste-map]` [**BREAKING**] Remove support for deprecated option `ignorePattern` as function ([#10348](https://github.com/facebook/jest/pull/10348)) - `[jest-jasmine2]` [**BREAKING**] Migrate to ESM ([#10906](https://github.com/facebook/jest/pull/10906)) - `[jest-repl, jest-runtime]` [**BREAKING**] Move the `jest-runtime` CLI into `jest-repl` ([#10016](https://github.com/facebook/jest/pull/10016)) - `[jest-resolve]` [**BREAKING**] Migrate to ESM ([#10688](https://github.com/facebook/jest/pull/10688)) diff --git a/packages/jest-haste-map/src/__tests__/index.test.js b/packages/jest-haste-map/src/__tests__/index.test.js index 4805292f7992..7bf339408e80 100644 --- a/packages/jest-haste-map/src/__tests__/index.test.js +++ b/packages/jest-haste-map/src/__tests__/index.test.js @@ -326,19 +326,19 @@ describe('HasteMap', () => { }); }); - it('ignores vcs directories with ignore pattern function', () => { - const config = {...defaultConfig, ignorePattern: f => /Kiwi/.test(f)}; - mockFs[path.join('/', 'project', 'fruits', 'Kiwi.js')] = ` + it('warn on ignore pattern except for regex', () => { + const config = {ignorePattern: 'Kiwi', ...defaultConfig}; + mockFs['/project/fruits/Kiwi.js'] = ` // Kiwi! `; - mockFs[path.join('/', 'project', 'fruits', '.git', 'fruit-history.js')] = ` - // test - `; - return new HasteMap(config).build().then(({hasteFS}) => { - expect(hasteFS.matchFiles(/Kiwi/)).toEqual([]); - expect(hasteFS.matchFiles('.git')).toEqual([]); - }); + try { + new HasteMap(config).build(); + } catch (err) { + expect(err.message).toBe( + 'jest-haste-map: the `ignorePattern` option must be a RegExp', + ); + } }); it('builds a haste map on a fresh cache', () => { diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index c6def19cb48c..04f805b5c441 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -254,14 +254,8 @@ export default class HasteMap extends EventEmitter { options.ignorePattern.flags, ); } else { - const ignorePattern = options.ignorePattern; - const vcsIgnoreRegExp = new RegExp(VCS_DIRECTORIES); - this._options.ignorePattern = (filePath: string) => - vcsIgnoreRegExp.test(filePath) || ignorePattern(filePath); - - this._console.warn( - 'jest-haste-map: the `ignorePattern` options as a function is being ' + - 'deprecated. Provide a RegExp instead. See https://github.com/facebook/jest/pull/4063.', + throw new Error( + 'jest-haste-map: the `ignorePattern` option must be a RegExp', ); } } else {