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: make sure normalize accepts defaults #7742

Merged
merged 3 commits into from
Jan 29, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'}, {});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rootDir is added by readConfig

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to preserve that information 😄

Suggested change
normalize({...Defaults, rootDir: '/root'}, {});
// rootDir is added by readConfig
normalize({...Defaults, rootDir: '/root'}, {});

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reason, it's used like this all over this test file


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