Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow searching for tests in node_modules #11084

Merged
merged 2 commits into from Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -24,6 +24,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 @@ -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
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');
cjr125 marked this conversation as resolved.
Show resolved Hide resolved
});
});
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