Skip to content

Commit 0d1c05e

Browse files
Christopher RobertsChristopher Roberts
authored andcommitted
fix: Allow searching for tests in node_modules
1 parent f9d4fc4 commit 0d1c05e

File tree

9 files changed

+49
-1
lines changed

9 files changed

+49
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- `[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))
3030
- `[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))
3131
- `[jest-mock]` Fix function overloads for `spyOn` to allow more correct type inference in complex object ([#12442](https://github.com/facebook/jest/pull/12442))
32+
- `[jest-config]` Allow searching for tests in node_modules by exposing `retainAllFiles` ([#11084](https://github.com/facebook/jest/pull/11084))
3233

3334
### Chore & Maintenance
3435

docs/Configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ type HasteConfig = {
511511
throwOnModuleCollision?: boolean;
512512
/** Custom HasteMap module */
513513
hasteMapModulePath?: string;
514+
/** Whether to retain all files, allowing e.g. search for tests in `node_modules`. */
515+
retainAllFiles?: boolean;
514516
};
515517
```
516518

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import runJest from '../runJest';
9+
10+
describe('Retain All Files Integration', () => {
11+
test('valid test within node_modules', () => {
12+
const {exitCode, stdout} = runJest('retain-all-files');
13+
expect(exitCode).toBe(0);
14+
expect(stdout).toContain('I am running from within node_modules');
15+
});
16+
});

e2e/retain-all-files/node_modules/retainAllFiles.test.js

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/retain-all-files/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"jest": {
3+
"testEnvironment": "node",
4+
"testPathIgnorePatterns": [],
5+
"haste": {
6+
"retainAllFiles": true
7+
}
8+
}
9+
}

packages/jest-config/src/ValidConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const initialOptions: Config.InitialOptions = {
6464
hasteImplModulePath: '<rootDir>/haste_impl.js',
6565
hasteMapModulePath: '',
6666
platforms: ['ios', 'android'],
67+
retainAllFiles: false,
6768
throwOnModuleCollision: false,
6869
},
6970
injectGlobals: true,

packages/jest-haste-map/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export type WorkerMessage = {
5757
rootDir: string;
5858
filePath: string;
5959
hasteImplModulePath?: string;
60+
retainAllFiles?: boolean;
6061
};
6162

6263
export type WorkerMetadata = {

packages/jest-runtime/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ export default class Runtime {
386386
name: config.name,
387387
platforms: config.haste.platforms || ['ios', 'android'],
388388
resetCache: options?.resetCache,
389-
retainAllFiles: false,
389+
retainAllFiles: config.haste.retainAllFiles || false,
390390
rootDir: config.rootDir,
391391
roots: config.roots,
392392
throwOnModuleCollision: config.haste.throwOnModuleCollision,

packages/jest-types/src/Config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export type HasteConfig = {
3535
throwOnModuleCollision?: boolean;
3636
/** Custom HasteMap module */
3737
hasteMapModulePath?: string;
38+
/** Whether to retain all files, allowing e.g. search for tests in `node_modules`. */
39+
retainAllFiles?: boolean;
3840
};
3941

4042
export type CoverageReporterName = keyof ReportOptions;

0 commit comments

Comments
 (0)