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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jest-types): make ConfigGlobal an interface #9570

Merged
merged 5 commits into from Feb 28, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -29,6 +29,7 @@
- `[jest-snapshot]` Properly indent new snapshots in the presences of existing ones ([#9523](https://github.com/facebook/jest/pull/9523))
- `[jest-transform]` Correct sourcemap behavior for transformed and instrumented code ([#9460](https://github.com/facebook/jest/pull/9460))
- `[jest-transform]` Allow instrumentation of transformed files with weird file extensions ([#9589](https://github.com/facebook/jest/pull/9589))
- `[@jest/types]` Make `ConfigGlobals` an interface to allow for declaration merging. ([#9570](https://github.com/facebook/jest/pull/9570))
- `[pretty-format]` Export `OldPlugin` type ([#9491](https://github.com/facebook/jest/pull/9491))

### Chore & Maintenance
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/package.json
Expand Up @@ -15,6 +15,7 @@
"@jest/types": "^25.1.0",
"babel-jest": "^25.1.0",
"chalk": "^3.0.0",
"deepmerge": "^4.2.2",
"glob": "^7.1.1",
"jest-environment-jsdom": "^25.1.0",
"jest-environment-node": "^25.1.0",
Expand Down
24 changes: 13 additions & 11 deletions packages/jest-config/src/__tests__/normalize.test.js
Expand Up @@ -1251,9 +1251,11 @@ describe('preset with globals', () => {
'/node_modules/global-foo/jest-preset.json',
() => ({
globals: {
__DEV__: false,
config: {
hereToStay: 'This should stay here',
},
myString: 'hello world',
},
}),
{virtual: true},
Expand All @@ -1268,9 +1270,11 @@ describe('preset with globals', () => {
const {options} = normalize(
{
globals: {
__DEV__: true,
config: {
sideBySide: 'This should also live another day',
},
myString: 'hello sunshine',
textValue: 'This is just text',
},
preset: 'global-foo',
Expand All @@ -1279,17 +1283,15 @@ describe('preset with globals', () => {
{},
);

expect(options).toEqual(
expect.objectContaining({
globals: {
config: {
hereToStay: 'This should stay here',
sideBySide: 'This should also live another day',
},
textValue: 'This is just text',
},
}),
);
expect(options.globals).toEqual({
__DEV__: true,
config: {
hereToStay: 'This should stay here',
sideBySide: 'This should also live another day',
},
myString: 'hello sunshine',
textValue: 'This is just text',
});
});
});

Expand Down
8 changes: 2 additions & 6 deletions packages/jest-config/src/normalize.ts
Expand Up @@ -17,6 +17,7 @@ import micromatch = require('micromatch');
import {sync as realpath} from 'realpath-native';
import Resolver = require('jest-resolve');
import {replacePathSepForRegex} from 'jest-regex-util';
import merge = require('deepmerge');
import validatePattern from './validatePattern';
import getMaxWorkers from './getMaxWorkers';
import {
Expand Down Expand Up @@ -112,12 +113,7 @@ const mergeGlobalsWithPreset = (
preset: Config.InitialOptions,
) => {
if (options['globals'] && preset['globals']) {
for (const p in preset['globals']) {
options['globals'][p] = {
...preset['globals'][p],
...options['globals'][p],
};
}
options['globals'] = merge(preset['globals'], options['globals']);
}
};

Expand Down
4 changes: 3 additions & 1 deletion packages/jest-types/src/Config.ts
Expand Up @@ -27,7 +27,9 @@ export type HasteConfig = {
export type ReporterConfig = [string, Record<string, unknown>];
export type TransformerConfig = [string, Record<string, unknown>];

export type ConfigGlobals = Record<string, any>;
export interface ConfigGlobals {
[K: string]: unknown;
G-Rath marked this conversation as resolved.
Show resolved Hide resolved
}

export type DefaultOptions = {
automock: boolean;
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -5221,6 +5221,11 @@ deepmerge@^3.2.0:
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-3.3.0.tgz#d3c47fd6f3a93d517b14426b0628a17b0125f5f7"
integrity sha512-GRQOafGHwMHpjPx9iCvTgpu9NojZ49q794EEL94JVEw6VaeA8XTUyBKvAkOOjBX9oJNiV6G3P+T+tihFjo2TqA==

deepmerge@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"
integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==

defaults@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
Expand Down