Skip to content
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 @@ -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

Expand Down
4 changes: 2 additions & 2 deletions TestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -148,5 +148,5 @@ export const makeProjectConfig = (overrides: Object = {}): ProjectConfig => {
`);
}

return Object.assign({}, DEFAULT_PROJECT_CONFIG, overrides);
return {...DEFAULT_GLOBAL_CONFIG, ...overrides};
};
4 changes: 2 additions & 2 deletions e2e/runJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 || [], {
Expand Down
6 changes: 4 additions & 2 deletions examples/module-mock/__tests__/partial_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
25 changes: 10 additions & 15 deletions packages/expect/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions packages/jest-changed-files/src/hg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-changed-files/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-cli/src/FailedTestsCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Comment thread
SimenB marked this conversation as resolved.
newConfig.enabledTestsMap = this._enabledTestsMap;
return Object.freeze(newConfig);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-cli/src/SearchSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions packages/jest-cli/src/__tests__/notify_reporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 21 additions & 24 deletions packages/jest-cli/src/__tests__/runJestWithCoverage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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']);
});
});
Loading