diff --git a/CHANGELOG.md b/CHANGELOG.md index c2f6e40f09f7..fe9efb87a3ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixes - `[jest-cli]` Use correct file name to override existing jest config on init ([#10337](https://github.com/facebook/jest/pull/10337)) +- `[jest-haste-map]` Properly detect support for native `find` ([#10346](https://github.com/facebook/jest/pull/10346)) ### Chore & Maintenance 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], 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); });