From 8c0a0e08af937507630345fd2daf7d92e49cfdd0 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 31 Jul 2020 11:38:54 +0200 Subject: [PATCH 1/3] fix: correct check for compatible `find` binary --- CHANGELOG.md | 2 ++ packages/jest-haste-map/src/crawlers/node.ts | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 392a977ffa31..832292cffdd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[jest-haste-map]` Properly detect support for native `find` + ### Chore & Maintenance ### Performance diff --git a/packages/jest-haste-map/src/crawlers/node.ts b/packages/jest-haste-map/src/crawlers/node.ts index be6bcae43b05..7fdc6bbf8020 100644 --- a/packages/jest-haste-map/src/crawlers/node.ts +++ b/packages/jest-haste-map/src/crawlers/node.ts @@ -30,9 +30,20 @@ async function hasNativeFindSupport( try { return await new Promise(resolve => { - // Check the find binary supports the non-POSIX -iname parameter. - const args = ['.', '-iname', "''"]; - const child = spawn('find', args); + // Check the find binary supports the non-POSIX -iname parameter wrapped in parens. + const args = [ + '.', + '-type', + 'f', + '(', + '-iname', + '*.ts', + '-o', + '-iname', + '*.js', + ')', + ]; + const child = spawn('find', args, {cwd: __dirname}); child.on('error', () => { resolve(false); }); From e558c022037a9a4df27d9025102654181702cd88 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 31 Jul 2020 11:41:44 +0200 Subject: [PATCH 2/3] link to pr --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 832292cffdd6..3d6924c57994 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixes -- `[jest-haste-map]` Properly detect support for native `find` +- `[jest-haste-map]` Properly detect support for native `find` ([#10346](https://github.com/facebook/jest/pull/10346)) ### Chore & Maintenance From 64704ad07cf4431f5de19a93435fa0471123f16e Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 31 Jul 2020 12:05:42 +0200 Subject: [PATCH 3/3] fix test --- packages/jest-haste-map/src/crawlers/__tests__/node.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/jest-haste-map/src/crawlers/__tests__/node.test.js b/packages/jest-haste-map/src/crawlers/__tests__/node.test.js index 467c0acb9195..cf84bbaf5811 100644 --- a/packages/jest-haste-map/src/crawlers/__tests__/node.test.js +++ b/packages/jest-haste-map/src/crawlers/__tests__/node.test.js @@ -282,7 +282,11 @@ describe('node crawler', () => { rootDir, roots: ['/project/fruits'], }).then(({hasteMap, removedFiles}) => { - expect(childProcess.spawn).lastCalledWith('find', ['.', '-iname', "''"]); + expect(childProcess.spawn).lastCalledWith( + 'find', + ['.', '-type', 'f', '(', '-iname', '*.ts', '-o', '-iname', '*.js', ')'], + {cwd: expect.any(String)}, + ); expect(hasteMap.files).toEqual( createMap({ 'fruits/directory/strawberry.js': ['', 33, 42, 0, '', null],