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 763c204
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
25 changes: 25 additions & 0 deletions e2e/__tests__/retainAllFiles.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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 config = {
haste: {
retainAllFiles: true,
},
};

const {exitCode} = runJest('retain-all-files', [
'--config',
JSON.stringify(config),
'retainAllFiles.test.js',
]);
expect(exitCode).toBe(0);
});
});
15 changes: 15 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"jest": {
"testEnvironment": "node",
"testPathIgnorePatterns": [],
"haste": {
"retainAllFiles": true
}
}
}
1 change: 1 addition & 0 deletions packages/jest-config/src/ValidConfig.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 763c204

Please sign in to comment.