From 0363816ce8b37d4573d5ea522c80b68c3ea81f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 12 Jun 2019 22:41:50 +0200 Subject: [PATCH 1/3] fix(jest-haste-map): don't pass mapper to Node crawler --- packages/jest-haste-map/src/__tests__/index.test.js | 4 ++++ packages/jest-haste-map/src/index.ts | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/jest-haste-map/src/__tests__/index.test.js b/packages/jest-haste-map/src/__tests__/index.test.js index a24f9c3bddbf..c69ed8ee2558 100644 --- a/packages/jest-haste-map/src/__tests__/index.test.js +++ b/packages/jest-haste-map/src/__tests__/index.test.js @@ -408,6 +408,9 @@ describe('HasteMap', () => { node.mockImplementation(options => { const {data} = options; + // `mapper` is not supported in Node crawl + expect(options.mapper).toBeUndefined(); + // The node crawler returns "null" for the SHA-1. data.files = createMap({ 'fruits/Banana.js': ['Banana', 32, 42, 0, 'Strawberry', null], @@ -426,6 +429,7 @@ describe('HasteMap', () => { const hasteMap = new HasteMap({ ...defaultConfig, computeSha1: true, + mapper: file => [file], maxWorkers: 1, useWatchman, }); diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index 70965909d79d..fc9f8f6cd8d6 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -741,15 +741,15 @@ class HasteMap extends EventEmitter { private _crawl(hasteMap: InternalHasteMap) { const options = this._options; const ignore = this._ignore.bind(this); - const crawl = - canUseWatchman && this._options.useWatchman ? watchmanCrawl : nodeCrawl; + const useWatchman = canUseWatchman && this._options.useWatchman; + const crawl = useWatchman ? watchmanCrawl : nodeCrawl; const crawlerOptions: CrawlerOptions = { computeSha1: options.computeSha1, data: hasteMap, extensions: options.extensions, forceNodeFilesystemAPI: options.forceNodeFilesystemAPI, ignore, - mapper: options.mapper, + mapper: useWatchman ? options.mapper : undefined, rootDir: options.rootDir, roots: options.roots, }; From ac5a94e119dab5b229d6f666869dbbe7290d3bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 12 Jun 2019 22:45:27 +0200 Subject: [PATCH 2/3] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13b20390b701..020f83470d7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - `[babel-plugin-jest-hoist]` Expand list of whitelisted globals in global mocks ([#8429](https://github.com/facebook/jest/pull/8429) - `[jest-core]` Make watch plugin initialization errors look nice ([#8422](https://github.com/facebook/jest/pull/8422)) - `[jest-snapshot]` Prevent inline snapshots from drifting when inline snapshots are updated ([#8492](https://github.com/facebook/jest/pull/8492)) +- `[jest-haste-map]` Don't pass mapper to Node crawler snapshots are updated ([#8558](https://github.com/facebook/jest/pull/8558)) ### Chore & Maintenance From 486891c8d7c8b38e285f2114d3ae27fa0d113a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 13 Jun 2019 07:53:54 +0200 Subject: [PATCH 3/3] get rid of throwing when mapper passed to node crawler --- CHANGELOG.md | 2 +- packages/jest-haste-map/src/__tests__/index.test.js | 3 --- packages/jest-haste-map/src/crawlers/node.ts | 4 ---- packages/jest-haste-map/src/index.ts | 6 +++--- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 020f83470d7f..a33bbe692568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ - `[babel-plugin-jest-hoist]` Expand list of whitelisted globals in global mocks ([#8429](https://github.com/facebook/jest/pull/8429) - `[jest-core]` Make watch plugin initialization errors look nice ([#8422](https://github.com/facebook/jest/pull/8422)) - `[jest-snapshot]` Prevent inline snapshots from drifting when inline snapshots are updated ([#8492](https://github.com/facebook/jest/pull/8492)) -- `[jest-haste-map]` Don't pass mapper to Node crawler snapshots are updated ([#8558](https://github.com/facebook/jest/pull/8558)) +- `[jest-haste-map]` Don't throw on missing mapper in Node crawler ([#8558](https://github.com/facebook/jest/pull/8558)) ### Chore & Maintenance diff --git a/packages/jest-haste-map/src/__tests__/index.test.js b/packages/jest-haste-map/src/__tests__/index.test.js index c69ed8ee2558..196094edd1c8 100644 --- a/packages/jest-haste-map/src/__tests__/index.test.js +++ b/packages/jest-haste-map/src/__tests__/index.test.js @@ -408,9 +408,6 @@ describe('HasteMap', () => { node.mockImplementation(options => { const {data} = options; - // `mapper` is not supported in Node crawl - expect(options.mapper).toBeUndefined(); - // The node crawler returns "null" for the SHA-1. data.files = createMap({ 'fruits/Banana.js': ['Banana', 32, 42, 0, 'Strawberry', null], diff --git a/packages/jest-haste-map/src/crawlers/node.ts b/packages/jest-haste-map/src/crawlers/node.ts index 71ee6c053a3b..87bcb00b9680 100644 --- a/packages/jest-haste-map/src/crawlers/node.ts +++ b/packages/jest-haste-map/src/crawlers/node.ts @@ -139,10 +139,6 @@ export = function nodeCrawl( removedFiles: FileData; hasteMap: InternalHasteMap; }> { - if (options.mapper) { - throw new Error(`Option 'mapper' isn't supported by the Node crawler`); - } - const { data, extensions, diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index fc9f8f6cd8d6..70965909d79d 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -741,15 +741,15 @@ class HasteMap extends EventEmitter { private _crawl(hasteMap: InternalHasteMap) { const options = this._options; const ignore = this._ignore.bind(this); - const useWatchman = canUseWatchman && this._options.useWatchman; - const crawl = useWatchman ? watchmanCrawl : nodeCrawl; + const crawl = + canUseWatchman && this._options.useWatchman ? watchmanCrawl : nodeCrawl; const crawlerOptions: CrawlerOptions = { computeSha1: options.computeSha1, data: hasteMap, extensions: options.extensions, forceNodeFilesystemAPI: options.forceNodeFilesystemAPI, ignore, - mapper: useWatchman ? options.mapper : undefined, + mapper: options.mapper, rootDir: options.rootDir, roots: options.roots, };