Skip to content

Commit

Permalink
fix: Allow searching for tests in node_modules (#11084)
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher Roberts <Christopher.Roberts@AmWell.com>
  • Loading branch information
cjr125 and Christopher Roberts committed Feb 22, 2022
1 parent fa7ab5a commit 491e7cb
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -26,6 +26,7 @@
- `[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))
Expand Down
2 changes: 2 additions & 0 deletions docs/Configuration.md
Expand Up @@ -513,6 +513,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
16 changes: 16 additions & 0 deletions 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');
});
});
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 491e7cb

Please sign in to comment.