Skip to content

Commit

Permalink
fix: make sure normalize accepts defaults (jestjs#7742)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored and captain-yossarian committed Jul 18, 2019
1 parent eb58be8 commit 385619e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions packages/jest-config/src/Defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export default ({
coverageThreshold: null,
cwd: process.cwd(),
dependencyExtractor: null,
detectLeaks: false,
detectOpenHandles: false,
errorOnDeprecated: false,
expand: false,
filter: null,
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/ValidConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default ({
statements: 100,
},
},
cwd: '/root',
dependencyExtractor: '<rootDir>/dependencyExtractor.js',
displayName: 'project-name',
errorOnDeprecated: false,
Expand Down
39 changes: 19 additions & 20 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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,
Expand All @@ -133,8 +139,6 @@ describe('automock', () => {
);

expect(options.automock).toBe(false);

console.warn = consoleWarn;
});
});

Expand Down Expand Up @@ -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(
{
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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 => {
Expand All @@ -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(
{
Expand Down Expand Up @@ -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();
});
});
4 changes: 3 additions & 1 deletion packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
2 changes: 0 additions & 2 deletions types/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export type DefaultOptions = {|
globalSetup: ?string,
globalTeardown: ?string,
haste: HasteConfig,
detectLeaks: boolean,
detectOpenHandles: boolean,
moduleDirectories: Array<string>,
moduleFileExtensions: Array<string>,
moduleNameMapper: {[key: string]: string},
Expand Down

0 comments on commit 385619e

Please sign in to comment.