diff --git a/CHANGELOG.md b/CHANGELOG.md index e4efa82d5ee7..110188111a8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -153,6 +153,7 @@ - `[*]` Standardize file names ([#7316](https://github.com/facebook/jest/pull/7316), [#7266](https://github.com/facebook/jest/pull/7266), [#7238](https://github.com/facebook/jest/pull/7238), [#7314](https://github.com/facebook/jest/pull/7314), [#7467](https://github.com/facebook/jest/pull/7467), [#7464](https://github.com/facebook/jest/pull/7464)), [#7471](https://github.com/facebook/jest/pull/7471)) - `[docs]` Add `testPathIgnorePatterns` in CLI documentation ([#7440](https://github.com/facebook/jest/pull/7440)) - `[docs]` Removed misleading text about `describe()` grouping together tests into a test suite ([#7434](https://github.com/facebook/jest/pull/7434)) +- `[*]` Replace as many `Object.assign` with object spread as possible ### Performance diff --git a/TestUtils.js b/TestUtils.js index 1c2ec68398ec..33c9e93490e2 100644 --- a/TestUtils.js +++ b/TestUtils.js @@ -134,7 +134,7 @@ export const makeGlobalConfig = (overrides: Object = {}): GlobalConfig => { `); } - return Object.assign({}, DEFAULT_GLOBAL_CONFIG, overrides); + return {...DEFAULT_GLOBAL_CONFIG, ...overrides}; }; export const makeProjectConfig = (overrides: Object = {}): ProjectConfig => { @@ -148,5 +148,5 @@ export const makeProjectConfig = (overrides: Object = {}): ProjectConfig => { `); } - return Object.assign({}, DEFAULT_PROJECT_CONFIG, overrides); + return {...DEFAULT_GLOBAL_CONFIG, ...overrides}; }; diff --git a/e2e/runJest.js b/e2e/runJest.js index cb67e53545ac..9095e9a54a39 100644 --- a/e2e/runJest.js +++ b/e2e/runJest.js @@ -49,7 +49,7 @@ export default function runJest( ); } - const env = Object.assign({}, process.env, {FORCE_COLOR: 0}); + const env = {...process.env, FORCE_COLOR: 0}; if (options.nodePath) env['NODE_PATH'] = options.nodePath; const result = spawnSync(JEST_PATH, args || [], { cwd: dir, @@ -119,7 +119,7 @@ export const until = async function( ); } - const env = Object.assign({}, process.env, {FORCE_COLOR: 0}); + const env = {...process.env, FORCE_COLOR: 0}; if (options.nodePath) env['NODE_PATH'] = options.nodePath; const jestPromise = execa(JEST_PATH, args || [], { diff --git a/examples/module-mock/__tests__/partial_mock.js b/examples/module-mock/__tests__/partial_mock.js index 21077480ad1d..7e2b92434e13 100644 --- a/examples/module-mock/__tests__/partial_mock.js +++ b/examples/module-mock/__tests__/partial_mock.js @@ -12,10 +12,12 @@ jest.mock('../fruit', () => { const mockedModule = jest.genMockFromModule('../fruit'); //Mock the default export and named export 'apple'. - return Object.assign({}, mockedModule, originalModule, { + return { + ...mockedModule, + ...originalModule, apple: 'mocked apple', default: jest.fn(() => 'mocked fruit'), - }); + }; }); it('does a partial mock', () => { diff --git a/packages/expect/src/index.js b/packages/expect/src/index.js index c570fb8a41a9..ca6cacf16e3b 100644 --- a/packages/expect/src/index.js +++ b/packages/expect/src/index.js @@ -234,27 +234,22 @@ const makeThrowingMatcher = ( ): ThrowingMatcherFn => function throwingMatcher(...args): any { let throws = true; - const utils = Object.assign({}, matcherUtils, { - iterableEquality, - subsetEquality, - }); + const utils = {...matcherUtils, iterableEquality, subsetEquality}; - const matcherContext: MatcherState = Object.assign( + const matcherContext: MatcherState = { // When throws is disabled, the matcher will not throw errors during test // execution but instead add them to the global matcher state. If a // matcher throws, test execution is normally stopped immediately. The // snapshot matcher uses it because we want to log all snapshot // failures in a test. - {dontThrow: () => (throws = false)}, - getState(), - { - equals, - error: err, - isNot, - promise, - utils, - }, - ); + dontThrow: () => (throws = false), + ...getState(), + equals, + error: err, + isNot, + promise, + utils, + }; const processResult = (result: SyncExpectationResult) => { _validateResult(result); diff --git a/packages/jest-changed-files/src/hg.js b/packages/jest-changed-files/src/hg.js index 7e1294fa42cd..9459619fcc6c 100644 --- a/packages/jest-changed-files/src/hg.js +++ b/packages/jest-changed-files/src/hg.js @@ -13,9 +13,7 @@ import type {Options, SCMAdapter} from 'types/ChangedFiles'; import path from 'path'; import execa from 'execa'; -const env = Object.assign({}, process.env, { - HGPLAIN: 1, -}); +const env = {...process.env, HGPLAIN: 1}; const ANCESTORS = [ // Parent commit to this one. diff --git a/packages/jest-changed-files/src/index.js b/packages/jest-changed-files/src/index.js index c1ad572adbbd..f7ecf3d8fb1d 100644 --- a/packages/jest-changed-files/src/index.js +++ b/packages/jest-changed-files/src/index.js @@ -27,7 +27,7 @@ export const getChangedFilesForRoots = async ( ): ChangedFilesPromise => { const repos = await findRepos(roots); - const changedFilesOptions = Object.assign({}, {includePaths: roots}, options); + const changedFilesOptions = {includePaths: roots, ...options}; const gitPromises = Array.from(repos.git).map(repo => git.findChangedFiles(repo, changedFilesOptions), diff --git a/packages/jest-cli/src/FailedTestsCache.js b/packages/jest-cli/src/FailedTestsCache.js index 46ae69b1aadf..73c0970e1646 100644 --- a/packages/jest-cli/src/FailedTestsCache.js +++ b/packages/jest-cli/src/FailedTestsCache.js @@ -41,8 +41,7 @@ export default class FailedTestsCache { if (!this._enabledTestsMap) { return globalConfig; } - // $FlowFixMe Object.assign - const newConfig: GlobalConfig = Object.assign({}, globalConfig); + const newConfig: GlobalConfig = {...globalConfig}; newConfig.enabledTestsMap = this._enabledTestsMap; return Object.freeze(newConfig); } diff --git a/packages/jest-cli/src/SearchSource.js b/packages/jest-cli/src/SearchSource.js index 38892285b8d9..1744ef00bb2a 100644 --- a/packages/jest-cli/src/SearchSource.js +++ b/packages/jest-cli/src/SearchSource.js @@ -275,10 +275,10 @@ export default class SearchSource { filterResult.filtered.map(result => result.test), ); - // $FlowFixMe: Object.assign with empty object causes troubles to Flow. - return Object.assign({}, searchResult, { + return { + ...searchResult, tests: tests.filter(test => filteredSet.has(test.path)), - }); + }; } return searchResult; diff --git a/packages/jest-cli/src/__tests__/notify_reporter.test.js b/packages/jest-cli/src/__tests__/notify_reporter.test.js index 26c2b0a59937..424b6f212d1a 100644 --- a/packages/jest-cli/src/__tests__/notify_reporter.test.js +++ b/packages/jest-cli/src/__tests__/notify_reporter.test.js @@ -69,11 +69,7 @@ const notifyEvents = [ ]; test('.addReporter() .removeReporter()', () => { - const scheduler = new TestScheduler( - {}, - {}, - Object.assign({}, initialContext), - ); + const scheduler = new TestScheduler({}, {}, {...initialContext}); const reporter = new NotifyReporter(); scheduler.addReporter(reporter); expect(scheduler._dispatcher._reporters).toContain(reporter); diff --git a/packages/jest-cli/src/__tests__/runJestWithCoverage.test.js b/packages/jest-cli/src/__tests__/runJestWithCoverage.test.js index 75b5949937cc..21a9d76c0c40 100644 --- a/packages/jest-cli/src/__tests__/runJestWithCoverage.test.js +++ b/packages/jest-cli/src/__tests__/runJestWithCoverage.test.js @@ -70,13 +70,12 @@ describe('collectCoverageFrom patterns', () => { it('should apply collectCoverageFrom patterns coming from SearchSource', async () => { expect.assertions(1); - await runJest( - Object.assign({}, defaults, { - globalConfig: { - rootDir: '', - }, - }), - ); + await runJest({ + ...defaults, + globalConfig: { + rootDir: '', + }, + }); expect(globalConfig.collectCoverageFrom).toEqual([ 'foo.js', 'dont/cover.js', @@ -86,29 +85,27 @@ describe('collectCoverageFrom patterns', () => { it('excludes coverage from files outside the global collectCoverageFrom config', async () => { expect.assertions(1); - await runJest( - Object.assign({}, defaults, { - globalConfig: { - collectCoverageFrom: ['**/dont/*.js'], - rootDir: '', - }, - }), - ); + await runJest({ + ...defaults, + globalConfig: { + collectCoverageFrom: ['**/dont/*.js'], + rootDir: '', + }, + }); expect(globalConfig.collectCoverageFrom).toEqual(['dont/cover.js']); }); it('respects coveragePathIgnorePatterns', async () => { expect.assertions(1); - await runJest( - Object.assign({}, defaults, { - globalConfig: { - collectCoverageFrom: ['**/*.js'], - coveragePathIgnorePatterns: ['dont'], - rootDir: '', - }, - }), - ); + await runJest({ + ...defaults, + globalConfig: { + collectCoverageFrom: ['**/*.js'], + coveragePathIgnorePatterns: ['dont'], + rootDir: '', + }, + }); expect(globalConfig.collectCoverageFrom).toEqual(['foo.js']); }); }); diff --git a/packages/jest-cli/src/__tests__/watch.test.js b/packages/jest-cli/src/__tests__/watch.test.js index 6ce991334169..8fd2b2926157 100644 --- a/packages/jest-cli/src/__tests__/watch.test.js +++ b/packages/jest-cli/src/__tests__/watch.test.js @@ -179,10 +179,11 @@ describe('Watch mode flows', () => { it('resolves relative to the package root', () => { expect(async () => { await watch( - Object.assign({}, globalConfig, { + { + ...globalConfig, rootDir: __dirname, watchPlugins: [{config: {}, path: watchPluginPath}], - }), + }, contexts, pipe, hasteMapInstances, @@ -198,13 +199,14 @@ describe('Watch mode flows', () => { const ci_watch = require('../watch').default; ci_watch( - Object.assign({}, globalConfig, { + { + ...globalConfig, rootDir: __dirname, watchPlugins: [ {config: {}, path: watchPluginPath}, {config: {}, path: watchPlugin2Path}, ], - }), + }, contexts, pipe, hasteMapInstances, @@ -228,10 +230,11 @@ describe('Watch mode flows', () => { const ci_watch = require('../watch').default; ci_watch( - Object.assign({}, globalConfig, { + { + ...globalConfig, rootDir: __dirname, watchPlugins: [], - }), + }, contexts, pipe, hasteMapInstances, @@ -274,10 +277,11 @@ describe('Watch mode flows', () => { const ci_watch = require('../watch').default; ci_watch( - Object.assign({}, globalConfig, { + { + ...globalConfig, rootDir: __dirname, watchPlugins: [], - }), + }, contexts, pipe, hasteMapInstances, @@ -308,10 +312,11 @@ describe('Watch mode flows', () => { ); watch( - Object.assign({}, globalConfig, { + { + ...globalConfig, rootDir: __dirname, watchPlugins: [{config: {}, path: pluginPath}], - }), + }, contexts, pipe, hasteMapInstances, @@ -344,10 +349,11 @@ describe('Watch mode flows', () => { ); watch( - Object.assign({}, globalConfig, { + { + ...globalConfig, rootDir: __dirname, watchPlugins: [{config: {}, path: pluginPath}], - }), + }, contexts, pipe, hasteMapInstances, @@ -394,10 +400,11 @@ describe('Watch mode flows', () => { expect(() => { watch( - Object.assign({}, globalConfig, { + { + ...globalConfig, rootDir: __dirname, watchPlugins: [{config: {}, path: pluginPath}], - }), + }, contexts, pipe, hasteMapInstances, @@ -441,10 +448,11 @@ describe('Watch mode flows', () => { ); watch( - Object.assign({}, globalConfig, { + { + ...globalConfig, rootDir: __dirname, watchPlugins: [{config: {}, path: pluginPath}], - }), + }, contexts, pipe, hasteMapInstances, @@ -481,10 +489,11 @@ describe('Watch mode flows', () => { expect(() => { watch( - Object.assign({}, globalConfig, { + { + ...globalConfig, rootDir: __dirname, watchPlugins: pluginPaths.map(path => ({config: {}, path})), - }), + }, contexts, pipe, hasteMapInstances, @@ -519,7 +528,8 @@ describe('Watch mode flows', () => { ); watch( - Object.assign({}, globalConfig, { + { + ...globalConfig, rootDir: __dirname, watchPlugins: [ { @@ -527,7 +537,7 @@ describe('Watch mode flows', () => { path: pluginPath, }, ], - }), + }, contexts, pipe, hasteMapInstances, @@ -552,10 +562,11 @@ describe('Watch mode flows', () => { ); watch( - Object.assign({}, globalConfig, { + { + ...globalConfig, rootDir: __dirname, watchPlugins: [{config: {}, path: pluginPath}], - }), + }, contexts, pipe, hasteMapInstances, @@ -647,10 +658,11 @@ describe('Watch mode flows', () => { {virtual: true}, ); - const config = Object.assign({}, globalConfig, { + const config = { + ...globalConfig, rootDir: __dirname, watchPlugins: [{config: {}, path: pluginPath}], - }); + }; watch(config, contexts, pipe, hasteMapInstances, stdin); await nextTick(); @@ -690,10 +702,11 @@ describe('Watch mode flows', () => { ); watch( - Object.assign({}, globalConfig, { + { + ...globalConfig, rootDir: __dirname, watchPlugins: [{config: {}, path: pluginPath}], - }), + }, contexts, pipe, hasteMapInstances, @@ -750,13 +763,14 @@ describe('Watch mode flows', () => { ); watch( - Object.assign({}, globalConfig, { + { + ...globalConfig, rootDir: __dirname, watchPlugins: [ {config: {}, path: pluginPath}, {config: {}, path: pluginPath2}, ], - }), + }, contexts, pipe, hasteMapInstances, diff --git a/packages/jest-cli/src/cli/index.js b/packages/jest-cli/src/cli/index.js index 709b17305883..031c92d53446 100644 --- a/packages/jest-cli/src/cli/index.js +++ b/packages/jest-cli/src/cli/index.js @@ -194,7 +194,7 @@ export const buildArgv = (maybeArgv: ?Argv, project: ?Path) => { validateCLIOptions( argv, - Object.assign({}, args.options, {deprecationEntries}), + {...args.options, deprecationEntries}, // strip leading dashes Array.isArray(rawArgv) ? rawArgv.map(rawArgv => rawArgv.replace(/^--?/, '')) diff --git a/packages/jest-cli/src/lib/update_global_config.js b/packages/jest-cli/src/lib/update_global_config.js index ec782b5032bd..5b0047f8a6b1 100644 --- a/packages/jest-cli/src/lib/update_global_config.js +++ b/packages/jest-cli/src/lib/update_global_config.js @@ -36,8 +36,7 @@ export type Options = { }; export default (globalConfig: GlobalConfig, options: Options): GlobalConfig => { - // $FlowFixMe Object.assign - const newConfig: GlobalConfig = Object.assign({}, globalConfig); + const newConfig: GlobalConfig = {...globalConfig}; if (!options) { options = {}; diff --git a/packages/jest-cli/src/reporters/__tests__/coverage_reporter.test.js b/packages/jest-cli/src/reporters/__tests__/coverage_reporter.test.js index a1087b137dbf..a93b1cc71749 100644 --- a/packages/jest-cli/src/reporters/__tests__/coverage_reporter.test.js +++ b/packages/jest-cli/src/reporters/__tests__/coverage_reporter.test.js @@ -95,7 +95,7 @@ describe('onRunComplete', () => { ].reduce((c, f) => { const file = path.resolve(f[0]); const override = f[1]; - const obj = Object.assign({}, covSummary, override); + const obj = {...covSummary, ...override}; c[file] = libCoverage.createCoverageSummary(obj); return c; }, {}); diff --git a/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js b/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js index 799a4c41f9c6..be5144991d25 100644 --- a/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js +++ b/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js @@ -8,7 +8,7 @@ import SummaryReporter from '../summary_reporter'; -const env = Object.assign({}, process.env); +const env = {...process.env}; const now = Date.now; const write = process.stderr.write; const globalConfig = { diff --git a/packages/jest-cli/src/runJest.js b/packages/jest-cli/src/runJest.js index d7660791f418..8e3a6dcb1785 100644 --- a/packages/jest-cli/src/runJest.js +++ b/packages/jest-cli/src/runJest.js @@ -192,10 +192,7 @@ export default (async function runJest({ ); if (collectCoverageFrom.length) { - // $FlowFixMe Object.assign - const newConfig: GlobalConfig = Object.assign({}, globalConfig, { - collectCoverageFrom, - }); + const newConfig: GlobalConfig = {...globalConfig, collectCoverageFrom}; globalConfig = Object.freeze(newConfig); } diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index e820158e1157..7c08a098c013 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -59,12 +59,11 @@ const mergeOptionWithPreset = ( optionName: string, ) => { if (options[optionName] && preset[optionName]) { - options[optionName] = Object.assign( - {}, - options[optionName], - preset[optionName], - options[optionName], - ); + options[optionName] = { + ...options[optionName], + ...preset[optionName], + ...options[optionName], + }; } }; @@ -127,7 +126,7 @@ const setupPreset = ( mergeOptionWithPreset(options, preset, 'moduleNameMapper'); mergeOptionWithPreset(options, preset, 'transform'); - return Object.assign({}, preset, options); + return {...preset, ...options}; }; const setupBabelJest = (options: InitialOptions) => { @@ -447,9 +446,9 @@ export default function normalize(options: InitialOptions, argv: Argv) { } const babelJest = setupBabelJest(options); - const newOptions: $Shape< - DefaultOptions & ProjectConfig & GlobalConfig, - > = (Object.assign({}, DEFAULT_CONFIG): any); + const newOptions: $Shape = { + ...DEFAULT_CONFIG, + }; try { // try to resolve windows short paths, ignoring errors (permission errors, mostly) @@ -580,7 +579,7 @@ export default function normalize(options: InitialOptions, argv: Argv) { value = normalizeUnmockedModulePathPatterns(options, key); break; case 'haste': - value = Object.assign({}, options[key]); + value = {...options[key]}; if (value.hasteImplModulePath != null) { value.hasteImplModulePath = resolve(newOptions.resolver, { filePath: replaceRootDirInPath( diff --git a/packages/jest-config/src/setFromArgv.js b/packages/jest-config/src/setFromArgv.js index 45facad681e6..2cde2ee37d33 100644 --- a/packages/jest-config/src/setFromArgv.js +++ b/packages/jest-config/src/setFromArgv.js @@ -52,10 +52,9 @@ export default function setFromArgv( return options; }, {}); - return Object.assign( - {}, - options, - isJSONString(argv.config) ? JSON.parse(argv.config) : null, - argvToOptions, - ); + return { + ...options, + ...(isJSONString(argv.config) ? JSON.parse(argv.config) : null), + ...argvToOptions, + }; } diff --git a/packages/jest-diff/src/index.js b/packages/jest-diff/src/index.js index 60dfc1d97137..716e863fb1c4 100644 --- a/packages/jest-diff/src/index.js +++ b/packages/jest-diff/src/index.js @@ -35,17 +35,13 @@ const PLUGINS = [ const FORMAT_OPTIONS = { plugins: PLUGINS, }; -const FORMAT_OPTIONS_0 = Object.assign({}, FORMAT_OPTIONS, { - indent: 0, -}); +const FORMAT_OPTIONS_0 = {...FORMAT_OPTIONS, indent: 0}; const FALLBACK_FORMAT_OPTIONS = { callToJSON: false, maxDepth: 10, plugins: PLUGINS, }; -const FALLBACK_FORMAT_OPTIONS_0 = Object.assign({}, FALLBACK_FORMAT_OPTIONS, { - indent: 0, -}); +const FALLBACK_FORMAT_OPTIONS_0 = {...FALLBACK_FORMAT_OPTIONS, indent: 0}; // Generate a string that will highlight the difference between two values // with green and red. (similar to how github does code diffing) diff --git a/packages/jest-each/src/bind.js b/packages/jest-each/src/bind.js index c8b5c019872e..76e646a0cad3 100644 --- a/packages/jest-each/src/bind.js +++ b/packages/jest-each/src/bind.js @@ -184,7 +184,7 @@ const buildTable = ( .map((_, index) => data.slice(index * rowSize, index * rowSize + rowSize)) .map(row => row.reduce( - (acc, value, index) => Object.assign({}, acc, {[keys[index]]: value}), + (acc, value, index) => Object.assign(acc, {[keys[index]]: value}), {}, ), ); diff --git a/packages/jest-environment-jsdom/src/__mocks__/index.js b/packages/jest-environment-jsdom/src/__mocks__/index.js index 8f868074616b..f2bf9a30476e 100644 --- a/packages/jest-environment-jsdom/src/__mocks__/index.js +++ b/packages/jest-environment-jsdom/src/__mocks__/index.js @@ -16,7 +16,7 @@ JSDOMEnvironment.mockImplementation(function(config) { console: {}, }; - const globalValues = Object.assign({}, config.globals); + const globalValues = {...config.globals}; for (const customGlobalKey in globalValues) { this.global[customGlobalKey] = globalValues[customGlobalKey]; } diff --git a/packages/jest-environment-jsdom/src/index.js b/packages/jest-environment-jsdom/src/index.js index 9b19f6fb38a7..52eed2ff069c 100644 --- a/packages/jest-environment-jsdom/src/index.js +++ b/packages/jest-environment-jsdom/src/index.js @@ -24,20 +24,13 @@ class JSDOMEnvironment { moduleMocker: ?ModuleMocker; constructor(config: ProjectConfig, options?: EnvironmentContext = {}) { - this.dom = new JSDOM( - '', - Object.assign( - { - pretendToBeVisual: true, - runScripts: 'dangerously', - url: config.testURL, - virtualConsole: new VirtualConsole().sendTo( - options.console || console, - ), - }, - config.testEnvironmentOptions, - ), - ); + this.dom = new JSDOM('', { + pretendToBeVisual: true, + runScripts: 'dangerously', + url: config.testURL, + virtualConsole: new VirtualConsole().sendTo(options.console || console), + ...config.testEnvironmentOptions, + }); const global = (this.global = this.dom.window.document.defaultView); // Node's error-message stack size is limited at 10, but it's pretty useful // to see more than that when a test fails. diff --git a/packages/jest-haste-map/src/__tests__/index.test.js b/packages/jest-haste-map/src/__tests__/index.test.js index cdf7a88df62a..7e23749f3d93 100644 --- a/packages/jest-haste-map/src/__tests__/index.test.js +++ b/packages/jest-haste-map/src/__tests__/index.test.js @@ -223,12 +223,8 @@ describe('HasteMap', () => { it('creates different cache file paths for different roots', () => { jest.resetModuleRegistry(); const HasteMap = require('../'); - const hasteMap1 = new HasteMap( - Object.assign({}, defaultConfig, {rootDir: '/root1'}), - ); - const hasteMap2 = new HasteMap( - Object.assign({}, defaultConfig, {rootDir: '/root2'}), - ); + const hasteMap1 = new HasteMap({...defaultConfig, rootDir: '/root1'}); + const hasteMap2 = new HasteMap({...defaultConfig, rootDir: '/root2'}); expect(hasteMap1.getCacheFilePath()).not.toBe(hasteMap2.getCacheFilePath()); }); @@ -236,9 +232,10 @@ describe('HasteMap', () => { jest.resetModuleRegistry(); const HasteMap = require('../'); const dependencyExtractor = require('./dependencyExtractor'); - const config = Object.assign({}, defaultConfig, { + const config = { + ...defaultConfig, dependencyExtractor: require.resolve('./dependencyExtractor'), - }); + }; dependencyExtractor.setCacheKey('foo'); const hasteMap1 = new HasteMap(config); dependencyExtractor.setCacheKey('bar'); @@ -260,12 +257,8 @@ describe('HasteMap', () => { it('creates different cache file paths for different projects', () => { jest.resetModuleRegistry(); const HasteMap = require('../'); - const hasteMap1 = new HasteMap( - Object.assign({}, defaultConfig, {name: '@scoped/package'}), - ); - const hasteMap2 = new HasteMap( - Object.assign({}, defaultConfig, {name: '-scoped-package'}), - ); + const hasteMap1 = new HasteMap({...defaultConfig, name: '@scoped/package'}); + const hasteMap2 = new HasteMap({...defaultConfig, name: '-scoped-package'}); expect(hasteMap1.getCacheFilePath()).not.toBe(hasteMap2.getCacheFilePath()); }); @@ -284,7 +277,7 @@ describe('HasteMap', () => { })); it('ignores files given a pattern', () => { - const config = Object.assign({}, defaultConfig, {ignorePattern: /Kiwi/}); + const config = {...defaultConfig, ignorePattern: /Kiwi/}; mockFs['/project/fruits/Kiwi.js'] = ` // Kiwi! `; @@ -325,12 +318,11 @@ describe('HasteMap', () => { // fbjs2 `; - const hasteMap = new HasteMap( - Object.assign({}, defaultConfig, { - mocksPattern: '/__mocks__/', - providesModuleNodeModules: ['react', 'fbjs'], - }), - ); + const hasteMap = new HasteMap({ + ...defaultConfig, + mocksPattern: '/__mocks__/', + providesModuleNodeModules: ['react', 'fbjs'], + }); return hasteMap.build().then(({__hasteMapForTest: data}) => { expect(data.clocks).toEqual(mockClocks); @@ -424,13 +416,12 @@ describe('HasteMap', () => { return Promise.resolve(data); }); - const hasteMap = new HasteMap( - Object.assign({}, defaultConfig, { - computeSha1: true, - maxWorkers: 1, - useWatchman, - }), - ); + const hasteMap = new HasteMap({ + ...defaultConfig, + computeSha1: true, + maxWorkers: 1, + useWatchman, + }); const data = (await hasteMap.build()).__hasteMapForTest; @@ -489,12 +480,11 @@ describe('HasteMap', () => { module.exports = require("./video.mp4"); `; - const hasteMap = new HasteMap( - Object.assign({}, defaultConfig, { - extensions: [...defaultConfig.extensions], - roots: [...defaultConfig.roots, '/project/video'], - }), - ); + const hasteMap = new HasteMap({ + ...defaultConfig, + extensions: [...defaultConfig.extensions], + roots: [...defaultConfig.roots, '/project/video'], + }); const {__hasteMapForTest: data} = await hasteMap.build(); @@ -508,12 +498,11 @@ describe('HasteMap', () => { // fbjs! `; - const hasteMap = new HasteMap( - Object.assign({}, defaultConfig, { - mocksPattern: '/__mocks__/', - retainAllFiles: true, - }), - ); + const hasteMap = new HasteMap({ + ...defaultConfig, + mocksPattern: '/__mocks__/', + retainAllFiles: true, + }); return hasteMap.build().then(({__hasteMapForTest: data}) => { // Expect the node module to be part of files but make sure it wasn't @@ -543,9 +532,7 @@ describe('HasteMap', () => { // Blueberry too! `; - return new HasteMap( - Object.assign({mocksPattern: '__mocks__'}, defaultConfig), - ) + return new HasteMap({mocksPattern: '__mocks__', ...defaultConfig}) .build() .then(({__hasteMapForTest: data}) => { expect(console.warn.mock.calls[0][0]).toMatchSnapshot(); @@ -588,9 +575,7 @@ describe('HasteMap', () => { const Banana = require("Banana"); `; - return new HasteMap( - Object.assign({throwOnModuleCollision: true}, defaultConfig), - ) + return new HasteMap({throwOnModuleCollision: true, ...defaultConfig}) .build() .catch(err => { expect(err).toMatchSnapshot(); @@ -970,9 +955,7 @@ describe('HasteMap', () => { vegetables: 'c:fake-clock:4', }); - const config = Object.assign({}, defaultConfig, { - ignorePattern: /Kiwi|Pear/, - }); + const config = {...defaultConfig, ignorePattern: /Kiwi|Pear/}; return new HasteMap(config).build().then(({moduleMap}) => { expect(moduleMap.getModule('Pear')).toBe(null); }); @@ -1004,13 +987,12 @@ describe('HasteMap', () => { const jestWorker = require('jest-worker'); const path = require('path'); const dependencyExtractor = path.join(__dirname, 'dependencyExtractor.js'); - return new HasteMap( - Object.assign({}, defaultConfig, { - dependencyExtractor, - hasteImplModulePath: undefined, - maxWorkers: 4, - }), - ) + return new HasteMap({ + ...defaultConfig, + dependencyExtractor, + hasteImplModulePath: undefined, + maxWorkers: 4, + }) .build() .then(({__hasteMapForTest: data}) => { expect(jestWorker.mock.calls.length).toBe(1); @@ -1176,7 +1158,7 @@ describe('HasteMap', () => { if (options.mockFs) { mockFs = options.mockFs; } - const watchConfig = Object.assign({}, defaultConfig, {watch: true}); + const watchConfig = {...defaultConfig, watch: true}; const hm = new HasteMap(watchConfig); await hm.build(); try { diff --git a/packages/jest-jasmine2/src/jasmine/jasmineLight.js b/packages/jest-jasmine2/src/jasmine/jasmineLight.js index 2004ad36c30f..341e4c211647 100644 --- a/packages/jest-jasmine2/src/jasmine/jasmineLight.js +++ b/packages/jest-jasmine2/src/jasmine/jasmineLight.js @@ -43,7 +43,7 @@ import Suite from './Suite'; import Timer from './Timer'; exports.create = function(createOptions: Object) { - const j$ = Object.assign({}, createOptions); + const j$ = {...createOptions}; j$._DEFAULT_TIMEOUT_INTERVAL = 5000; diff --git a/packages/jest-jasmine2/src/jasmine/spyRegistry.js b/packages/jest-jasmine2/src/jasmine/spyRegistry.js index cba5c7d7daa3..b3e84c09cad2 100644 --- a/packages/jest-jasmine2/src/jasmine/spyRegistry.js +++ b/packages/jest-jasmine2/src/jasmine/spyRegistry.js @@ -200,9 +200,7 @@ export default function SpyRegistry(options: Object) { restoreObjectToOriginalState: restoreStrategy, }); - const spiedDescriptor = Object.assign({}, descriptor, { - [accessType]: spiedProperty, - }); + const spiedDescriptor = {...descriptor, [accessType]: spiedProperty}; Object.defineProperty(obj, propertyName, spiedDescriptor); diff --git a/packages/jest-phabricator/src/index.js b/packages/jest-phabricator/src/index.js index 16995e0ed0e4..5c02ee4ae1b3 100644 --- a/packages/jest-phabricator/src/index.js +++ b/packages/jest-phabricator/src/index.js @@ -43,7 +43,8 @@ function summarize(coverageMap: CoverageMap) { module.exports = function(results: AggregatedResult): PhabricatorReport { // $FlowFixMe: This should work, but it does not. - return Object.assign({}, results, { + return { + ...results, coverageMap: results.coverageMap && summarize(results.coverageMap), - }); + }; }; diff --git a/packages/jest-repl/src/cli/args.js b/packages/jest-repl/src/cli/args.js index 242eb2928f46..c5d29b013765 100644 --- a/packages/jest-repl/src/cli/args.js +++ b/packages/jest-repl/src/cli/args.js @@ -11,7 +11,8 @@ import Runtime from 'jest-runtime'; export const usage = 'Usage: $0 [--config=]'; -export const options = Object.assign({}, Runtime.getCLIOptions(), { +export const options = { + ...Runtime.getCLIOptions(), replname: { alias: 'r', description: @@ -19,4 +20,4 @@ export const options = Object.assign({}, Runtime.getCLIOptions(), { 'transformed. For example, "repl.ts" if using a TypeScript transformer.', type: 'string', }, -}); +}; diff --git a/packages/jest-repl/src/cli/index.js b/packages/jest-repl/src/cli/index.js index 6e10194437ca..b9a0abaf9c3b 100644 --- a/packages/jest-repl/src/cli/index.js +++ b/packages/jest-repl/src/cli/index.js @@ -22,10 +22,7 @@ const REPL_SCRIPT = path.resolve(__dirname, './repl.js'); module.exports = function() { const argv = yargs.usage(args.usage).options(args.options).argv; - validateCLIOptions( - argv, - Object.assign({}, args.options, {deprecationEntries}), - ); + validateCLIOptions(argv, {...args.options, deprecationEntries}); argv._ = [REPL_SCRIPT]; diff --git a/packages/jest-runner/src/runTest.js b/packages/jest-runner/src/runTest.js index d388d1c427e0..14d34483955a 100644 --- a/packages/jest-runner/src/runTest.js +++ b/packages/jest-runner/src/runTest.js @@ -56,12 +56,11 @@ async function runTestInternal( let testEnvironment = config.testEnvironment; if (customEnvironment) { - testEnvironment = getTestEnvironment( - Object.assign({}, config, { - // $FlowFixMe - testEnvironment: customEnvironment, - }), - ); + testEnvironment = getTestEnvironment({ + ...config, + // $FlowFixMe + testEnvironment: customEnvironment, + }); } /* $FlowFixMe */ diff --git a/packages/jest-runtime/src/__mocks__/createRuntime.js b/packages/jest-runtime/src/__mocks__/createRuntime.js index ae951f28cbec..0a2932e87176 100644 --- a/packages/jest-runtime/src/__mocks__/createRuntime.js +++ b/packages/jest-runtime/src/__mocks__/createRuntime.js @@ -14,25 +14,24 @@ module.exports = function createRuntime(filename, config) { const {normalize} = require('jest-config'); config = normalize( - Object.assign( - { - haste: { - hasteImplModulePath: path.resolve( - __dirname, - '..', - '..', - '..', - 'jest-haste-map', - 'src', - '__tests__', - 'haste_impl.js', - ), - }, - name: 'Runtime-' + filename.replace(/\W/, '-') + '.tests', - rootDir: path.resolve(path.dirname(filename), 'test_root'), + { + haste: { + hasteImplModulePath: path.resolve( + __dirname, + '..', + '..', + '..', + 'jest-haste-map', + 'src', + '__tests__', + 'haste_impl.js', + ), }, - config, - ), + name: 'Runtime-' + filename.replace(/\W/, '-') + '.tests', + rootDir: path.resolve(path.dirname(filename), 'test_root'), + ...config, + }, + {}, ).options; diff --git a/packages/jest-runtime/src/__tests__/script_transformer.test.js b/packages/jest-runtime/src/__tests__/script_transformer.test.js index 6aa2094c670c..63dcf0f420fb 100644 --- a/packages/jest-runtime/src/__tests__/script_transformer.test.js +++ b/packages/jest-runtime/src/__tests__/script_transformer.test.js @@ -11,7 +11,8 @@ jest .mock('fs', () => // Node 10.5.x compatibility - Object.assign({}, jest.genMockFromModule('fs'), { + ({ + ...jest.genMockFromModule('fs'), ReadStream: jest.requireActual('fs').ReadStream, WriteStream: jest.requireActual('fs').WriteStream, readFileSync: jest.fn((path, options) => { @@ -264,9 +265,10 @@ describe('ScriptTransformer', () => { "throws an error if `process` doesn't return a string or an object" + 'containing `code` key with processed string', () => { - config = Object.assign(config, { + config = { + ...config, transform: [['^.+\\.js$', 'passthrough-preprocessor']], - }); + }; const scriptTransformer = new ScriptTransformer(config); const incorrectReturnValues = [ @@ -299,9 +301,10 @@ describe('ScriptTransformer', () => { ); it("throws an error if `process` doesn't defined", () => { - Object.assign(config, { + config = { + ...config, transform: [['^.+\\.js$', 'skipped-required-props-preprocessor']], - }); + }; const scriptTransformer = new ScriptTransformer(config); expect(() => scriptTransformer.transformSource('sample.js', '', false), @@ -309,11 +312,12 @@ describe('ScriptTransformer', () => { }); it('throws an error if createTransformer returns object without `process` method', () => { - Object.assign(config, { + config = { + ...config, transform: [ ['^.+\\.js$', 'skipped-required-create-transformer-props-preprocessor'], ], - }); + }; const scriptTransformer = new ScriptTransformer(config); expect(() => scriptTransformer.transformSource('sample.js', '', false), @@ -321,9 +325,10 @@ describe('ScriptTransformer', () => { }); it("shouldn't throw error without process method. But with corrent createTransformer method", () => { - Object.assign(config, { + config = { + ...config, transform: [['^.+\\.js$', 'skipped-process-method-preprocessor']], - }); + }; const scriptTransformer = new ScriptTransformer(config); expect(() => scriptTransformer.transformSource('sample.js', '', false), @@ -331,9 +336,7 @@ describe('ScriptTransformer', () => { }); it('uses the supplied preprocessor', () => { - config = Object.assign(config, { - transform: [['^.+\\.js$', 'test_preprocessor']], - }); + config = {...config, transform: [['^.+\\.js$', 'test_preprocessor']]}; const scriptTransformer = new ScriptTransformer(config); scriptTransformer.transform('/fruits/banana.js', {}); @@ -347,12 +350,13 @@ describe('ScriptTransformer', () => { }); it('uses multiple preprocessors', () => { - config = Object.assign(config, { + config = { + ...config, transform: [ ['^.+\\.js$', 'test_preprocessor'], ['^.+\\.css$', 'css-preprocessor'], ], - }); + }; const scriptTransformer = new ScriptTransformer(config); scriptTransformer.transform('/fruits/banana.js', {}); @@ -369,9 +373,10 @@ describe('ScriptTransformer', () => { }); it('writes source map if preprocessor supplies it', () => { - config = Object.assign(config, { + config = { + ...config, transform: [['^.+\\.js$', 'preprocessor-with-sourcemaps']], - }); + }; const scriptTransformer = new ScriptTransformer(config); const map = { @@ -395,9 +400,10 @@ describe('ScriptTransformer', () => { }); it('writes source map if preprocessor inlines it', () => { - config = Object.assign(config, { + config = { + ...config, transform: [['^.+\\.js$', 'preprocessor-with-sourcemaps']], - }); + }; const scriptTransformer = new ScriptTransformer(config); const sourceMap = JSON.stringify({ @@ -424,9 +430,10 @@ describe('ScriptTransformer', () => { }); it('writes source maps if given by the transformer', () => { - config = Object.assign(config, { + config = { + ...config, transform: [['^.+\\.js$', 'preprocessor-with-sourcemaps']], - }); + }; const scriptTransformer = new ScriptTransformer(config); const map = { @@ -453,9 +460,10 @@ describe('ScriptTransformer', () => { }); it('does not write source map if not given by the transformer', () => { - config = Object.assign(config, { + config = { + ...config, transform: [['^.+\\.js$', 'preprocessor-with-sourcemaps']], - }); + }; const scriptTransformer = new ScriptTransformer(config); require('preprocessor-with-sourcemaps').process.mockReturnValue({ @@ -471,9 +479,7 @@ describe('ScriptTransformer', () => { }); it('passes expected transform options to getCacheKey', () => { - config = Object.assign(config, { - transform: [['^.+\\.js$', 'test_preprocessor']], - }); + config = {...config, transform: [['^.+\\.js$', 'test_preprocessor']]}; const scriptTransformer = new ScriptTransformer(config); scriptTransformer.transform('/fruits/banana.js', { @@ -485,9 +491,10 @@ describe('ScriptTransformer', () => { }); it('reads values from the cache', () => { - const transformConfig = Object.assign(config, { + const transformConfig = { + ...config, transform: [['^.+\\.js$', 'test_preprocessor']], - }); + }; let scriptTransformer = new ScriptTransformer(transformConfig); scriptTransformer.transform('/fruits/banana.js', {}); @@ -525,19 +532,17 @@ describe('ScriptTransformer', () => { }); it('does not reuse the in-memory cache between different projects', () => { - const scriptTransformer = new ScriptTransformer( - Object.assign({}, config, { - transform: [['^.+\\.js$', 'test_preprocessor']], - }), - ); + const scriptTransformer = new ScriptTransformer({ + ...config, + transform: [['^.+\\.js$', 'test_preprocessor']], + }); scriptTransformer.transform('/fruits/banana.js', {}); - const anotherScriptTransformer = new ScriptTransformer( - Object.assign({}, config, { - transform: [['^.+\\.js$', 'css-preprocessor']], - }), - ); + const anotherScriptTransformer = new ScriptTransformer({ + ...config, + transform: [['^.+\\.js$', 'css-preprocessor']], + }); anotherScriptTransformer.transform('/fruits/banana.js', {}); diff --git a/packages/jest-runtime/src/cli/index.js b/packages/jest-runtime/src/cli/index.js index fbc3ed4ec8ef..2662efe5407b 100644 --- a/packages/jest-runtime/src/cli/index.js +++ b/packages/jest-runtime/src/cli/index.js @@ -37,10 +37,7 @@ export function run(cliArgv?: Argv, cliInfo?: Array) { .version(false) .options(args.options).argv; - validateCLIOptions( - argv, - Object.assign({}, args.options, {deprecationEntries}), - ); + validateCLIOptions(argv, {...args.options, deprecationEntries}); } if (argv.help) { @@ -70,10 +67,11 @@ export function run(cliArgv?: Argv, cliInfo?: Array) { const options = readConfig(argv, root); const globalConfig = options.globalConfig; // Always disable automocking in scripts. - const config = Object.assign({}, options.projectConfig, { + const config = { + ...options.projectConfig, automock: false, unmockedModulePathPatterns: null, - }); + }; // Break circular dependency const Runtime = require('..'); diff --git a/packages/jest-snapshot/src/__mocks__/prettier.js b/packages/jest-snapshot/src/__mocks__/prettier.js index a450b76e0b34..717891860829 100644 --- a/packages/jest-snapshot/src/__mocks__/prettier.js +++ b/packages/jest-snapshot/src/__mocks__/prettier.js @@ -4,17 +4,10 @@ const prettier = jest.requireActual('prettier'); module.exports = { format: (text, opts) => - prettier.format( - text, - Object.assign( - { - pluginSearchDirs: [ - require('path').dirname(require.resolve('prettier')), - ], - }, - opts, - ), - ), + prettier.format(text, { + pluginSearchDirs: [require('path').dirname(require.resolve('prettier'))], + ...opts, + }), getFileInfo: {sync: () => ({inferredParser: 'babylon'})}, resolveConfig: {sync: jest.fn()}, version: prettier.version, diff --git a/packages/jest-snapshot/src/inline_snapshots.js b/packages/jest-snapshot/src/inline_snapshots.js index 469c7bd8f3d7..cd171877a4a7 100644 --- a/packages/jest-snapshot/src/inline_snapshots.js +++ b/packages/jest-snapshot/src/inline_snapshots.js @@ -75,13 +75,11 @@ const saveSnapshotsForFile = ( : (config && config.parser) || simpleDetectParser(sourceFilePath); // Format the source code using the custom parser API. - const newSourceFile = prettier.format( - sourceFile, - Object.assign({}, config, { - filepath: sourceFilePath, - parser: createParser(snapshots, inferredParser, babelTraverse), - }), - ); + const newSourceFile = prettier.format(sourceFile, { + ...config, + filepath: sourceFilePath, + parser: createParser(snapshots, inferredParser, babelTraverse), + }); if (newSourceFile !== sourceFile) { fs.writeFileSync(sourceFilePath, newSourceFile); @@ -93,9 +91,7 @@ const groupSnapshotsBy = (createKey: InlineSnapshot => string) => ( ) => snapshots.reduce((object, inlineSnapshot) => { const key = createKey(inlineSnapshot); - return Object.assign(object, { - [key]: (object[key] || []).concat(inlineSnapshot), - }); + return {...object, [key]: (object[key] || []).concat(inlineSnapshot)}; }, {}); const groupSnapshotsByFrame = groupSnapshotsBy( diff --git a/packages/jest-snapshot/src/utils.js b/packages/jest-snapshot/src/utils.js index 950a7d17ab40..61b812ebdf68 100644 --- a/packages/jest-snapshot/src/utils.js +++ b/packages/jest-snapshot/src/utils.js @@ -179,7 +179,7 @@ export const saveSnapshotFile = ( }; export const deepMerge = (target: any, source: any) => { - const mergedOutput = Object.assign({}, target); + const mergedOutput = {...target}; if (isObject(target) && isObject(source)) { Object.keys(source).forEach(key => { if (isObject(source[key]) && !source[key].$$typeof) { diff --git a/packages/jest-util/src/FakeTimers.js b/packages/jest-util/src/FakeTimers.js index 5352ec71fb36..8fe11e83295d 100644 --- a/packages/jest-util/src/FakeTimers.js +++ b/packages/jest-util/src/FakeTimers.js @@ -239,7 +239,7 @@ export default class FakeTimers { } runOnlyPendingTimers() { - const timers = Object.assign({}, this._timers); + const timers = {...this._timers}; this._checkFakeTimers(); this._immediates.forEach(this._runImmediate, this); Object.keys(timers) diff --git a/packages/jest-util/src/__tests__/getCallsite.test.js b/packages/jest-util/src/__tests__/getCallsite.test.js index ab04ebf66241..d73c7c80dfae 100644 --- a/packages/jest-util/src/__tests__/getCallsite.test.js +++ b/packages/jest-util/src/__tests__/getCallsite.test.js @@ -5,12 +5,11 @@ import SourceMap from 'source-map'; import getCallsite from '../getCallsite'; // Node 10.5.x compatibility -jest.mock('fs', () => - Object.assign({}, jest.genMockFromModule('fs'), { - ReadStream: jest.requireActual('fs').ReadStream, - WriteStream: jest.requireActual('fs').WriteStream, - }), -); +jest.mock('fs', () => ({ + ...jest.genMockFromModule('fs'), + ReadStream: jest.requireActual('fs').ReadStream, + WriteStream: jest.requireActual('fs').WriteStream, +})); describe('getCallsite', () => { test('without source map', () => { diff --git a/packages/jest-validate/src/validate.js b/packages/jest-validate/src/validate.js index af64a7a9dfcd..0495b5990774 100644 --- a/packages/jest-validate/src/validate.js +++ b/packages/jest-validate/src/validate.js @@ -87,13 +87,12 @@ const validate = (config: Object, options: ValidationOptions) => { options.recursiveBlacklist || [], ); - const defaultedOptions: ValidationOptions = Object.assign( - {}, - defaultConfig, - options, - {recursiveBlacklist: combinedBlacklist}, - {title: Object.assign({}, defaultConfig.title, options.title)}, - ); + const defaultedOptions: ValidationOptions = Object.assign({ + ...defaultConfig, + ...options, + recursiveBlacklist: combinedBlacklist, + title: options.title || defaultConfig.title, + }); const {hasDeprecationWarnings: hdw} = _validate( config, diff --git a/packages/jest-validate/src/validateCLIOptions.js b/packages/jest-validate/src/validateCLIOptions.js index 7ac3677b2381..faf863efc9a2 100644 --- a/packages/jest-validate/src/validateCLIOptions.js +++ b/packages/jest-validate/src/validateCLIOptions.js @@ -55,14 +55,10 @@ const logDeprecatedOptions = ( argv: Argv, ) => { deprecatedOptions.forEach(opt => { - deprecationWarning( - argv, - opt, - deprecationEntries, - Object.assign({}, defaultConfig, { - comment: DOCUMENTATION_NOTE, - }), - ); + deprecationWarning(argv, opt, deprecationEntries, { + ...defaultConfig, + comment: DOCUMENTATION_NOTE, + }); }); }; diff --git a/packages/jest-worker/src/index.js b/packages/jest-worker/src/index.js index 807545c1a634..b5bc4885b53f 100644 --- a/packages/jest-worker/src/index.js +++ b/packages/jest-worker/src/index.js @@ -74,7 +74,7 @@ export default class JestWorker { _workerPool: WorkerPoolInterface; constructor(workerPath: string, options?: FarmOptions) { - this._options = Object.assign({}, options); + this._options = {...options}; const workerPoolOptions: WorkerPoolOptions = { forkOptions: this._options.forkOptions || {}, diff --git a/packages/jest-worker/src/workers/ChildProcessWorker.js b/packages/jest-worker/src/workers/ChildProcessWorker.js index 49b86a0b9caf..2ad70be2cd07 100644 --- a/packages/jest-worker/src/workers/ChildProcessWorker.js +++ b/packages/jest-worker/src/workers/ChildProcessWorker.js @@ -57,27 +57,18 @@ export default class ChildProcessWorker implements WorkerInterface { initialize() { const forceColor = supportsColor.stdout ? {FORCE_COLOR: '1'} : {}; - const child = childProcess.fork( - require.resolve('./processChild'), - // $FlowFixMe: Flow does not work well with Object.assign. - Object.assign( - { - cwd: process.cwd(), - env: Object.assign( - {}, - process.env, - { - JEST_WORKER_ID: this._options.workerId, - }, - forceColor, - ), - // Suppress --debug / --inspect flags while preserving others (like --harmony). - execArgv: process.execArgv.filter(v => !/^--(debug|inspect)/.test(v)), - silent: true, - }, - this._options.forkOptions, - ), - ); + const child = childProcess.fork(require.resolve('./processChild'), { + cwd: process.cwd(), + env: { + ...process.env, + JEST_WORKER_ID: this._options.workerId, + ...forceColor, + }, + // Suppress --debug / --inspect flags while preserving others (like --harmony). + execArgv: process.execArgv.filter(v => !/^--(debug|inspect)/.test(v)), + silent: true, + ...this._options.forkOptions, + }); child.on('message', this.onMessage.bind(this)); child.on('exit', this.onExit.bind(this)); diff --git a/packages/jest-worker/src/workers/NodeThreadsWorker.js b/packages/jest-worker/src/workers/NodeThreadsWorker.js index fc0585e5d1bb..3b93ab822b7d 100644 --- a/packages/jest-worker/src/workers/NodeThreadsWorker.js +++ b/packages/jest-worker/src/workers/NodeThreadsWorker.js @@ -46,19 +46,14 @@ export default class ExperimentalWorker implements WorkerInterface { eval: false, stderr: true, stdout: true, - // $FlowFixMe: Flow does not work well with Object.assign. - workerData: Object.assign( - { - cwd: process.cwd(), - env: Object.assign({}, process.env, { - JEST_WORKER_ID: this._options.workerId, - }), - // Suppress --debug / --inspect flags while preserving others (like --harmony). - execArgv: process.execArgv.filter(v => !/^--(debug|inspect)/.test(v)), - silent: true, - }, - this._options.forkOptions, - ), + workerData: { + cwd: process.cwd(), + env: {...process.env, JEST_WORKER_ID: this._options.workerId}, + // Suppress --debug / --inspect flags while preserving others (like --harmony). + execArgv: process.execArgv.filter(v => !/^--(debug|inspect)/.test(v)), + silent: true, + ...this._options.forkOptions, + }, }); this._worker.on('message', this.onMessage.bind(this)); diff --git a/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js b/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js index ccabd691559c..d6c5fc8790b7 100644 --- a/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js +++ b/packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.js @@ -65,9 +65,7 @@ it('passes fork options down to child_process.fork, adding the defaults', () => expect(childProcess.fork.mock.calls[0][0]).toBe(child); expect(childProcess.fork.mock.calls[0][1]).toEqual({ cwd: '/tmp', // Overridden default option. - env: Object.assign({}, process.env, { - FORCE_COLOR: supportsColor.stdout ? '1' : undefined, - }), // Default option. + env: {...process.env, FORCE_COLOR: supportsColor.stdout ? '1' : undefined}, // Default option. execArgv: ['-p'], // Filtered option. execPath: 'hello', // Added option. silent: true, // Default option. diff --git a/packages/jest-worker/src/workers/processChild.js b/packages/jest-worker/src/workers/processChild.js index a6b5f2077bc5..9becbba0fb49 100644 --- a/packages/jest-worker/src/workers/processChild.js +++ b/packages/jest-worker/src/workers/processChild.js @@ -96,7 +96,7 @@ function reportError(error: Error, type: PARENT_MESSAGE_ERROR) { error.message, error.stack, // $FlowFixMe: this is safe to just inherit from Object. - typeof error === 'object' ? Object.assign({}, error) : error, + typeof error === 'object' ? {...error} : error, ]); } diff --git a/packages/jest-worker/src/workers/threadChild.js b/packages/jest-worker/src/workers/threadChild.js index 17d087ee1ae9..e35e4610acc5 100644 --- a/packages/jest-worker/src/workers/threadChild.js +++ b/packages/jest-worker/src/workers/threadChild.js @@ -101,7 +101,7 @@ function reportError(error: Error, type: PARENT_MESSAGE_ERROR) { error.message, error.stack, // $FlowFixMe: this is safe to just inherit from Object. - typeof error === 'object' ? Object.assign({}, error) : error, + typeof error === 'object' ? {...error} : error, ]); } diff --git a/packages/pretty-format/src/__tests__/getPrettyPrint.js b/packages/pretty-format/src/__tests__/getPrettyPrint.js index b5dd8e4b2dde..3eae13b07dbc 100644 --- a/packages/pretty-format/src/__tests__/getPrettyPrint.js +++ b/packages/pretty-format/src/__tests__/getPrettyPrint.js @@ -16,15 +16,7 @@ const prettyFormat = require('../'); const getPrettyPrint = (plugins: Plugins) => function(received: any, expected: any, options?: OptionsReceived) { - const prettyFormatted = prettyFormat( - received, - Object.assign( - ({ - plugins, - }: OptionsReceived), - options, - ), - ); + const prettyFormatted = prettyFormat(received, {plugins, ...options}); const pass = prettyFormatted === expected; const message = pass diff --git a/packages/pretty-format/src/__tests__/react.test.js b/packages/pretty-format/src/__tests__/react.test.js index 83694a19689a..6a268319cf99 100644 --- a/packages/pretty-format/src/__tests__/react.test.js +++ b/packages/pretty-format/src/__tests__/react.test.js @@ -20,26 +20,13 @@ const prettyFormat = require('..'); const {ReactElement, ReactTestComponent} = prettyFormat.plugins; const formatElement = (element: any, options?: OptionsReceived) => - prettyFormat( - element, - Object.assign( - ({ - plugins: [ReactElement], - }: OptionsReceived), - options, - ), - ); + prettyFormat(element, {plugins: [ReactElement], ...options}); const formatTestObject = (object: any, options?: OptionsReceived) => - prettyFormat( - object, - Object.assign( - ({ - plugins: [ReactTestComponent, ReactElement], - }: OptionsReceived), - options, - ), - ); + prettyFormat(object, { + plugins: [ReactTestComponent, ReactElement], + ...options, + }); function assertPrintedJSX( val: any, diff --git a/packages/pretty-format/src/plugins/DOMCollection.js b/packages/pretty-format/src/plugins/DOMCollection.js index 86c71e23af3a..b45975022286 100644 --- a/packages/pretty-format/src/plugins/DOMCollection.js +++ b/packages/pretty-format/src/plugins/DOMCollection.js @@ -51,7 +51,7 @@ export const serialize = ( printObjectProperties( name === 'NamedNodeMap' ? Array.prototype.reduce.call(collection, propsReducer, {}) - : Object.assign({}, collection), + : {...collection}, config, indentation, depth,