diff --git a/CHANGELOG.md b/CHANGELOG.md index 1082888a5ec0..31284a4d69a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - `[jest-runtime]` Lock down version of `write-file-atomic` ([#7725](https://github.com/facebook/jest/pull/7725)) - `[jest-cli]` Print log entries when logging happens after test environment is torn down ([#7731](https://github.com/facebook/jest/pull/7731)) - `[jest-config]` Do not use a uuid as `name` since that breaks caching ([#7746](https://github.com/facebook/jest/pull/7746)) +- `[jest-config]` Make sure `normalize` can consume `Defaults` without warnings ([#7742](https://github.com/facebook/jest/pull/7742)) ### Chore & Maintenance diff --git a/packages/jest-config/src/Defaults.js b/packages/jest-config/src/Defaults.js index 0bbdbdc7a432..f4eabb3168dc 100644 --- a/packages/jest-config/src/Defaults.js +++ b/packages/jest-config/src/Defaults.js @@ -31,8 +31,6 @@ export default ({ coverageThreshold: null, cwd: process.cwd(), dependencyExtractor: null, - detectLeaks: false, - detectOpenHandles: false, errorOnDeprecated: false, expand: false, filter: null, diff --git a/packages/jest-config/src/ValidConfig.js b/packages/jest-config/src/ValidConfig.js index 238aee5dfee8..0b7a06adc64a 100644 --- a/packages/jest-config/src/ValidConfig.js +++ b/packages/jest-config/src/ValidConfig.js @@ -40,6 +40,7 @@ export default ({ statements: 100, }, }, + cwd: '/root', dependencyExtractor: '/dependencyExtractor.js', displayName: 'project-name', errorOnDeprecated: false, diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index a1d37311d373..df031aadd292 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -10,6 +10,7 @@ import crypto from 'crypto'; import path from 'path'; import {escapeStrForRegex} from 'jest-regex-util'; import normalize from '../normalize'; +import Defaults from '../Defaults'; import {DEFAULT_JS_PATTERN} from '../constants'; @@ -45,6 +46,12 @@ beforeEach(() => { expectedPathAbsAnother = path.join(root, 'another', 'abs', 'path'); require('jest-resolve').findNodeModule = findNodeModule; + + jest.spyOn(console, 'warn'); +}); + +afterEach(() => { + console.warn.mockRestore(); }); it('picks a name based on the rootDir', () => { @@ -122,8 +129,7 @@ describe('rootDir', () => { describe('automock', () => { it('falsy automock is not overwritten', () => { - const consoleWarn = console.warn; - console.warn = jest.fn(); + console.warn.mockImplementation(() => {}); const {options} = normalize( { automock: false, @@ -133,8 +139,6 @@ describe('automock', () => { ); expect(options.automock).toBe(false); - - console.warn = consoleWarn; }); }); @@ -401,21 +405,15 @@ describe('setupFilesAfterEnv', () => { describe('setupTestFrameworkScriptFile', () => { let Resolver; - let consoleWarn; beforeEach(() => { - console.warn = jest.fn(); - consoleWarn = console.warn; + console.warn.mockImplementation(() => {}); Resolver = require('jest-resolve'); Resolver.findNodeModule = jest.fn(name => name.startsWith('/') ? name : '/root/path/foo' + path.sep + name, ); }); - afterEach(() => { - console.warn = consoleWarn; - }); - it('logs a deprecation warning when `setupTestFrameworkScriptFile` is used', () => { normalize( { @@ -425,7 +423,7 @@ describe('setupTestFrameworkScriptFile', () => { {}, ); - expect(consoleWarn.mock.calls[0][0]).toMatchSnapshot(); + expect(console.warn.mock.calls[0][0]).toMatchSnapshot(); }); it('logs an error when `setupTestFrameworkScriptFile` and `setupFilesAfterEnv` are used', () => { @@ -782,11 +780,8 @@ describe('babel-jest', () => { }); describe('Upgrade help', () => { - let consoleWarn; - beforeEach(() => { - consoleWarn = console.warn; - console.warn = jest.fn(); + console.warn.mockImplementation(() => {}); const Resolver = require('jest-resolve'); Resolver.findNodeModule = jest.fn(name => { @@ -797,10 +792,6 @@ describe('Upgrade help', () => { }); }); - afterEach(() => { - console.warn = consoleWarn; - }); - it('logs a warning when `scriptPreprocessor` and/or `preprocessorIgnorePatterns` are used', () => { const {options: options, hasDeprecationWarnings} = normalize( { @@ -1469,3 +1460,11 @@ describe('moduleFileExtensions', () => { ).toThrowError("moduleFileExtensions must include 'js'"); }); }); + +describe('Defaults', () => { + it('should be accepted by normalize', () => { + normalize({...Defaults, rootDir: '/root'}, {}); + + expect(console.warn).not.toHaveBeenCalled(); + }); +}); diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 6abbe34122e3..f2304fc71791 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -200,7 +200,9 @@ const normalizeCollectCoverageFrom = (options: InitialOptions, key: string) => { value = JSON.parse(options[key]); } catch (e) {} - Array.isArray(value) || (value = [options[key]]); + if (options[key] && !Array.isArray(value)) { + value = [options[key]]; + } } else { value = options[key]; } diff --git a/types/Config.js b/types/Config.js index d500cf4e7248..f4b14282cdfd 100644 --- a/types/Config.js +++ b/types/Config.js @@ -46,8 +46,6 @@ export type DefaultOptions = {| globalSetup: ?string, globalTeardown: ?string, haste: HasteConfig, - detectLeaks: boolean, - detectOpenHandles: boolean, moduleDirectories: Array, moduleFileExtensions: Array, moduleNameMapper: {[key: string]: string},