From 0d1c05e81e8f7c8ee35876b07458dc4fe3a2d6e4 Mon Sep 17 00:00:00 2001 From: Christopher Roberts Date: Sat, 13 Feb 2021 16:36:41 -0500 Subject: [PATCH 1/2] fix: Allow searching for tests in node_modules --- CHANGELOG.md | 1 + docs/Configuration.md | 2 ++ e2e/__tests__/retainAllFiles.test.ts | 16 ++++++++++++++++ .../node_modules/retainAllFiles.test.js | 16 ++++++++++++++++ e2e/retain-all-files/package.json | 9 +++++++++ packages/jest-config/src/ValidConfig.ts | 1 + packages/jest-haste-map/src/types.ts | 1 + packages/jest-runtime/src/index.ts | 2 +- packages/jest-types/src/Config.ts | 2 ++ 9 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 e2e/__tests__/retainAllFiles.test.ts create mode 100644 e2e/retain-all-files/node_modules/retainAllFiles.test.js create mode 100644 e2e/retain-all-files/package.json diff --git a/CHANGELOG.md b/CHANGELOG.md index c86b32a89e74..7a613addb818 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - `[jest-jasmine2, jest-types]` [**BREAKING**] Move all `jasmine` specific types from `@jest/types` to its own package ([#12125](https://github.com/facebook/jest/pull/12125)) - `[jest-matcher-utils]` Pass maxWidth to `pretty-format` to avoid printing every element in arrays by default ([#12402](https://github.com/facebook/jest/pull/12402)) - `[jest-mock]` Fix function overloads for `spyOn` to allow more correct type inference in complex object ([#12442](https://github.com/facebook/jest/pull/12442)) +- `[jest-config]` Allow searching for tests in node_modules by exposing `retainAllFiles` ([#11084](https://github.com/facebook/jest/pull/11084)) ### Chore & Maintenance diff --git a/docs/Configuration.md b/docs/Configuration.md index c7ffb8c9e6e3..c1e8e7c591cb 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -511,6 +511,8 @@ type HasteConfig = { throwOnModuleCollision?: boolean; /** Custom HasteMap module */ hasteMapModulePath?: string; + /** Whether to retain all files, allowing e.g. search for tests in `node_modules`. */ + retainAllFiles?: boolean; }; ``` diff --git a/e2e/__tests__/retainAllFiles.test.ts b/e2e/__tests__/retainAllFiles.test.ts new file mode 100644 index 000000000000..4eabd6b7e353 --- /dev/null +++ b/e2e/__tests__/retainAllFiles.test.ts @@ -0,0 +1,16 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import runJest from '../runJest'; + +describe('Retain All Files Integration', () => { + test('valid test within node_modules', () => { + const {exitCode, stdout} = runJest('retain-all-files'); + expect(exitCode).toBe(0); + expect(stdout).toContain('I am running from within node_modules'); + }); +}); diff --git a/e2e/retain-all-files/node_modules/retainAllFiles.test.js b/e2e/retain-all-files/node_modules/retainAllFiles.test.js new file mode 100644 index 000000000000..54d85d4d1c7b --- /dev/null +++ b/e2e/retain-all-files/node_modules/retainAllFiles.test.js @@ -0,0 +1,16 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +'use strict'; + +describe('Test in node_modules', () => { + test('gets run', () => { + console.log('I am running from within node_modules'); + expect(true).toBe(true); + }); +}); diff --git a/e2e/retain-all-files/package.json b/e2e/retain-all-files/package.json new file mode 100644 index 000000000000..88730889ec4c --- /dev/null +++ b/e2e/retain-all-files/package.json @@ -0,0 +1,9 @@ +{ + "jest": { + "testEnvironment": "node", + "testPathIgnorePatterns": [], + "haste": { + "retainAllFiles": true + } + } +} diff --git a/packages/jest-config/src/ValidConfig.ts b/packages/jest-config/src/ValidConfig.ts index d8d4ff8bcb5f..6151c59ac451 100644 --- a/packages/jest-config/src/ValidConfig.ts +++ b/packages/jest-config/src/ValidConfig.ts @@ -64,6 +64,7 @@ const initialOptions: Config.InitialOptions = { hasteImplModulePath: '/haste_impl.js', hasteMapModulePath: '', platforms: ['ios', 'android'], + retainAllFiles: false, throwOnModuleCollision: false, }, injectGlobals: true, diff --git a/packages/jest-haste-map/src/types.ts b/packages/jest-haste-map/src/types.ts index 28515e6090ac..314348955655 100644 --- a/packages/jest-haste-map/src/types.ts +++ b/packages/jest-haste-map/src/types.ts @@ -57,6 +57,7 @@ export type WorkerMessage = { rootDir: string; filePath: string; hasteImplModulePath?: string; + retainAllFiles?: boolean; }; export type WorkerMetadata = { diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 363eef8f90cb..0620b33ea117 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -386,7 +386,7 @@ export default class Runtime { name: config.name, platforms: config.haste.platforms || ['ios', 'android'], resetCache: options?.resetCache, - retainAllFiles: false, + retainAllFiles: config.haste.retainAllFiles || false, rootDir: config.rootDir, roots: config.roots, throwOnModuleCollision: config.haste.throwOnModuleCollision, diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index bc1c15daa969..8a1078af1a8d 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -35,6 +35,8 @@ export type HasteConfig = { throwOnModuleCollision?: boolean; /** Custom HasteMap module */ hasteMapModulePath?: string; + /** Whether to retain all files, allowing e.g. search for tests in `node_modules`. */ + retainAllFiles?: boolean; }; export type CoverageReporterName = keyof ReportOptions; From 38172574b6a8907ca7c73744de644d1100ce6e00 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 22 Feb 2022 13:53:50 +0100 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a613addb818..48e1900c81d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,12 +24,12 @@ - `[expect]` Move typings of `.not`, `.rejects` and `.resolves` modifiers outside of `Matchers` interface ([#12346](https://github.com/facebook/jest/pull/12346)) - `[jest-config]` Correctly detect CI environment and update snapshots accordingly ([#12378](https://github.com/facebook/jest/pull/12378)) - `[jest-config]` Pass `moduleTypes` to `ts-node` to enforce CJS when transpiling ([#12397](https://github.com/facebook/jest/pull/12397)) +- `[jest-config, jest-haste-map]` Allow searching for tests in `node_modules` by exposing `retainAllFiles` ([#11084](https://github.com/facebook/jest/pull/11084)) - `[jest-environment-jsdom]` Make `jsdom` accessible to extending environments again ([#12232](https://github.com/facebook/jest/pull/12232)) - `[jest-haste-map]` Don't use partial results if file crawl errors ([#12420](https://github.com/facebook/jest/pull/12420)) - `[jest-jasmine2, jest-types]` [**BREAKING**] Move all `jasmine` specific types from `@jest/types` to its own package ([#12125](https://github.com/facebook/jest/pull/12125)) - `[jest-matcher-utils]` Pass maxWidth to `pretty-format` to avoid printing every element in arrays by default ([#12402](https://github.com/facebook/jest/pull/12402)) - `[jest-mock]` Fix function overloads for `spyOn` to allow more correct type inference in complex object ([#12442](https://github.com/facebook/jest/pull/12442)) -- `[jest-config]` Allow searching for tests in node_modules by exposing `retainAllFiles` ([#11084](https://github.com/facebook/jest/pull/11084)) ### Chore & Maintenance