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

Adding --noDuplicateMockWarn cli option #6037

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### Features

* `[jest-cli]` Added `--noDuplicateMockWarn` to disable HasteMap warning of
duplicate mocks. ([#6037](https://github.com/facebook/jest/pull/6037))
* `[jest-haste-map]` Added `noDuplicateMockWarn` option to disable warning of
duplicate mocks. ([#6037](https://github.com/facebook/jest/pull/6037))
* `[jest-snapshot]` [**BREAKING**] Concatenate name of test, optional snapshot
name and count ([#6015](https://github.com/facebook/jest/pull/6015))
* `[jest-runtime]` Allow for transform plugins to skip the definition process
Expand Down
1 change: 1 addition & 0 deletions TestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const DEFAULT_PROJECT_CONFIG: ProjectConfig = {
modulePathIgnorePatterns: [],
modulePaths: [],
name: 'test_name',
noDuplicateMockWarn: false,
resetMocks: false,
resetModules: false,
resolver: null,
Expand Down
4 changes: 4 additions & 0 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ for running tests. This defaults to the number of the cores available on your
machine. It may be useful to adjust this in resource limited environments like
CIs but the default should be adequate for most use-cases.

### `--noDuplicateMockWarn`

Disables duplicate mock warnings in output

### `--noStackTrace`

Disables stack trace in test results output.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
\\"moduleNameMapper\\": {},
\\"modulePathIgnorePatterns\\": [],
\\"name\\": \\"[md5 hash]\\",
\\"noDuplicateMockWarn\\": false,
\\"resetMocks\\": false,
\\"resetModules\\": false,
\\"restoreMocks\\": false,
Expand Down
5 changes: 5 additions & 0 deletions packages/jest-cli/src/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ export const options = {
'search when resolving modules.',
type: 'array',
},
noDuplicateMockWarn: {
default: undefined,
description: 'Disables duplicate mock warnings in output',
type: 'boolean',
},
noStackTrace: {
default: undefined,
description: 'Disables stack trace in test results output',
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default ({
moduleFileExtensions: ['js', 'json', 'jsx', 'node'],
moduleNameMapper: {},
modulePathIgnorePatterns: [],
noDuplicateMockWarn: false,
noStackTrace: false,
notify: false,
notifyMode: 'always',
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const getConfigs = (
modulePathIgnorePatterns: options.modulePathIgnorePatterns,
modulePaths: options.modulePaths,
name: options.name,
noDuplicateMockWarn: options.noDuplicateMockWarn,
resetMocks: options.resetMocks,
resetModules: options.resetModules,
resolver: options.resolver,
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ export default function normalize(options: InitialOptions, argv: Argv) {
case 'mapCoverage':
case 'moduleFileExtensions':
case 'name':
case 'noDuplicateMockWarn':
case 'noStackTrace':
case 'notify':
case 'notifyMode':
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/valid_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default ({
modulePathIgnorePatterns: ['<rootDir>/build/'],
modulePaths: ['/shared/vendor/modules'],
name: 'string',
noDuplicateMockWarn: false,
noStackTrace: false,
notify: false,
notifyMode: 'always',
Expand Down
25 changes: 25 additions & 0 deletions packages/jest-haste-map/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,31 @@ describe('HasteMap', () => {
});
});

it('does not warn on duplicate mock files if noDuplicateMockWarn is true', () => {
// Duplicate mock files for blueberry
mockFs['/fruits1/__mocks__/subdir/blueberry.js'] = [
'/**',
' * @providesModule Blueberry1',
' */',
].join('\n');
mockFs['/fruits2/__mocks__/subdir/blueberry.js'] = [
'/**',
' * @providesModule Blueberry2',
' */',
].join('\n');

return new HasteMap(
Object.assign(
{mocksPattern: '__mocks__', noDuplicateMockWarn: true},
defaultConfig,
),
)
.build()
.then(({__hasteMapForTest: data}) => {
expect(console.warn).not.toHaveBeenCalled();
});
});

it('warns on duplicate module ids', () => {
// Raspberry thinks it is a Strawberry
mockFs['/fruits/raspberry.js'] = [
Expand Down
5 changes: 4 additions & 1 deletion packages/jest-haste-map/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Options = {
maxWorkers: number,
mocksPattern?: string,
name: string,
noDuplicateMockWarn?: boolean,
platforms: Array<string>,
providesModuleNodeModules?: Array<string>,
resetCache?: boolean,
Expand All @@ -73,6 +74,7 @@ type InternalOptions = {
maxWorkers: number,
mocksPattern: ?RegExp,
name: string,
noDuplicateMockWarn: ?boolean,
platforms: Array<string>,
resetCache: ?boolean,
retainAllFiles: boolean,
Expand Down Expand Up @@ -223,6 +225,7 @@ class HasteMap extends EventEmitter {
? new RegExp(options.mocksPattern)
: null,
name: options.name,
noDuplicateMockWarn: options.noDuplicateMockWarn,
platforms: options.platforms,
resetCache: options.resetCache,
retainAllFiles: options.retainAllFiles,
Expand Down Expand Up @@ -418,7 +421,7 @@ class HasteMap extends EventEmitter {
this._options.mocksPattern.test(filePath)
) {
const mockPath = getMockName(filePath);
if (mocks[mockPath]) {
if (mocks[mockPath] && !this._options.noDuplicateMockWarn) {
this._console.warn(
`jest-haste-map: duplicate manual mock found:\n` +
` Module name: ${mockPath}\n` +
Expand Down
1 change: 1 addition & 0 deletions packages/jest-runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class Runtime {
maxWorkers: (options && options.maxWorkers) || 1,
mocksPattern: escapePathForRegex(path.sep + '__mocks__' + path.sep),
name: config.name,
noDuplicateMockWarn: config.noDuplicateMockWarn,
platforms: config.haste.platforms || ['ios', 'android'],
providesModuleNodeModules: config.haste.providesModuleNodeModules,
resetCache: options && options.resetCache,
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-validate/src/__tests__/fixtures/jest_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const defaultConfig = {
moduleFileExtensions: ['js', 'json', 'jsx', 'node'],
moduleNameMapper: {},
modulePathIgnorePatterns: [],
noDuplicateMockWarn: false,
noStackTrace: false,
notify: false,
notifyMode: 'always',
Expand Down Expand Up @@ -95,6 +96,7 @@ const validConfig = {
modulePathIgnorePatterns: ['<rootDir>/build/'],
modulePaths: ['/shared/vendor/modules'],
name: 'string',
noDuplicateMockWarn: false,
noStackTrace: false,
notify: false,
notifyMode: 'always',
Expand Down
1 change: 1 addition & 0 deletions types/Argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type Argv = {|
modulePathIgnorePatterns: Array<string>,
modulePaths: Array<string>,
name: string,
noDuplicateMockWarn: boolean,
noSCM: boolean,
noStackTrace: boolean,
notify: boolean,
Expand Down
3 changes: 3 additions & 0 deletions types/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type DefaultOptions = {|
moduleFileExtensions: Array<string>,
moduleNameMapper: {[key: string]: string},
modulePathIgnorePatterns: Array<string>,
noDuplicateMockWarn: boolean,
noStackTrace: boolean,
notify: boolean,
notifyMode: string,
Expand Down Expand Up @@ -109,6 +110,7 @@ export type InitialOptions = {
modulePathIgnorePatterns?: Array<string>,
modulePaths?: Array<string>,
name?: string,
noDuplicateMockWarn?: boolean,
noStackTrace?: boolean,
notify?: boolean,
notifyMode?: string,
Expand Down Expand Up @@ -231,6 +233,7 @@ export type ProjectConfig = {|
modulePathIgnorePatterns: Array<string>,
modulePaths: Array<string>,
name: string,
noDuplicateMockWarn: boolean,
resetMocks: boolean,
resetModules: boolean,
resolver: ?Path,
Expand Down