From 3888ea90a9efc4b21bd4e28658183230659976c4 Mon Sep 17 00:00:00 2001 From: mrmeku Date: Thu, 26 Dec 2019 10:39:36 -0700 Subject: [PATCH] feat(jest-haste-map): Enable crawling for symlink test files --- CHANGELOG.md | 1 + packages/jest-haste-map/src/crawlers/__tests__/node.test.js | 5 +++++ packages/jest-haste-map/src/crawlers/node.ts | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a386a795440..ff4680598d15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- `[jest-haste-map]` Enable crawling for symlink test files ([#9350](https://github.com/facebook/jest/issues/9350)) - `[babel-plugin-jest-hoist]` Show codeframe on static hoisting issues ([#8865](https://github.com/facebook/jest/pull/8865)) - `[babel-plugin-jest-hoist]` Add `BigInt` to `WHITELISTED_IDENTIFIERS` ([#8382](https://github.com/facebook/jest/pull/8382)) - `[babel-preset-jest]` Add `@babel/plugin-syntax-bigint` ([#8382](https://github.com/facebook/jest/pull/8382)) 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 69d3c3d6ca73..97e7094bdebf 100644 --- a/packages/jest-haste-map/src/crawlers/__tests__/node.test.js +++ b/packages/jest-haste-map/src/crawlers/__tests__/node.test.js @@ -118,8 +118,13 @@ describe('node crawler', () => { expect(childProcess.spawn).lastCalledWith('find', [ '/project/fruits', '/project/vegtables', + '(', '-type', 'f', + '-o', + '-type', + 'l', + ')', '(', '-iname', '*.js', diff --git a/packages/jest-haste-map/src/crawlers/node.ts b/packages/jest-haste-map/src/crawlers/node.ts index 6e6b6b5d4c9d..108ecfbcda49 100644 --- a/packages/jest-haste-map/src/crawlers/node.ts +++ b/packages/jest-haste-map/src/crawlers/node.ts @@ -84,7 +84,8 @@ function findNative( callback: Callback, ): void { const args = Array.from(roots); - args.push('-type', 'f'); + args.push('(', '-type', 'f', '-o', '-type', 'l', ')'); + if (extensions.length) { args.push('('); } @@ -121,7 +122,8 @@ function findNative( } else { lines.forEach(path => { fs.stat(path, (err, stat) => { - if (!err && stat) { + // Filter out symlinks that describe directories + if (!err && stat && !stat.isDirectory()) { result.push([path, stat.mtime.getTime(), stat.size]); } if (--count === 0) {