Skip to content

Commit

Permalink
fix: Allow searching for tests in node_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Roberts authored and Christopher Roberts committed Feb 22, 2022
1 parent f9d4fc4 commit 213ce11
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docs/Configuration.md
Expand Up @@ -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;
};
```

Expand Down
17 changes: 17 additions & 0 deletions e2e/__tests__/retainAllFiles.test.ts
@@ -0,0 +1,17 @@
/**
* 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).toMatchSnapshot();
expect(stdout).toContain('I am running from within node_modules');
});
});
16 changes: 16 additions & 0 deletions e2e/retain-all-files/node_modules/retainAllFiles.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions e2e/retain-all-files/package.json
@@ -0,0 +1,9 @@
{
"jest": {
"testEnvironment": "node",
"testPathIgnorePatterns": [],
"haste": {
"retainAllFiles": true
}
}
}
1 change: 1 addition & 0 deletions packages/jest-config/src/ValidConfig.ts
Expand Up @@ -64,6 +64,7 @@ const initialOptions: Config.InitialOptions = {
hasteImplModulePath: '<rootDir>/haste_impl.js',
hasteMapModulePath: '',
platforms: ['ios', 'android'],
retainAllFiles: false,
throwOnModuleCollision: false,
},
injectGlobals: true,
Expand Down
1 change: 1 addition & 0 deletions packages/jest-haste-map/src/types.ts
Expand Up @@ -57,6 +57,7 @@ export type WorkerMessage = {
rootDir: string;
filePath: string;
hasteImplModulePath?: string;
retainAllFiles?: boolean;
};

export type WorkerMetadata = {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runtime/src/index.ts
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-types/src/Config.ts
Expand Up @@ -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;
Expand Down

0 comments on commit 213ce11

Please sign in to comment.