Skip to content

Commit cc5d630

Browse files
authored
fix(jest-types): make ConfigGlobal an interace (#9570)
1 parent 4f4513b commit cc5d630

File tree

6 files changed

+25
-18
lines changed

6 files changed

+25
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- `[jest-snapshot]` Properly indent new snapshots in the presences of existing ones ([#9523](https://github.com/facebook/jest/pull/9523))
3030
- `[jest-transform]` Correct sourcemap behavior for transformed and instrumented code ([#9460](https://github.com/facebook/jest/pull/9460))
3131
- `[jest-transform]` Allow instrumentation of transformed files with weird file extensions ([#9589](https://github.com/facebook/jest/pull/9589))
32+
- `[@jest/types]` Make `ConfigGlobals` an interface to allow for declaration merging. ([#9570](https://github.com/facebook/jest/pull/9570))
3233
- `[pretty-format]` Export `OldPlugin` type ([#9491](https://github.com/facebook/jest/pull/9491))
3334

3435
### Chore & Maintenance

packages/jest-config/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@jest/types": "^25.1.0",
1616
"babel-jest": "^25.1.0",
1717
"chalk": "^3.0.0",
18+
"deepmerge": "^4.2.2",
1819
"glob": "^7.1.1",
1920
"jest-environment-jsdom": "^25.1.0",
2021
"jest-environment-node": "^25.1.0",

packages/jest-config/src/__tests__/normalize.test.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,9 +1251,11 @@ describe('preset with globals', () => {
12511251
'/node_modules/global-foo/jest-preset.json',
12521252
() => ({
12531253
globals: {
1254+
__DEV__: false,
12541255
config: {
12551256
hereToStay: 'This should stay here',
12561257
},
1258+
myString: 'hello world',
12571259
},
12581260
}),
12591261
{virtual: true},
@@ -1268,9 +1270,11 @@ describe('preset with globals', () => {
12681270
const {options} = normalize(
12691271
{
12701272
globals: {
1273+
__DEV__: true,
12711274
config: {
12721275
sideBySide: 'This should also live another day',
12731276
},
1277+
myString: 'hello sunshine',
12741278
textValue: 'This is just text',
12751279
},
12761280
preset: 'global-foo',
@@ -1279,17 +1283,15 @@ describe('preset with globals', () => {
12791283
{},
12801284
);
12811285

1282-
expect(options).toEqual(
1283-
expect.objectContaining({
1284-
globals: {
1285-
config: {
1286-
hereToStay: 'This should stay here',
1287-
sideBySide: 'This should also live another day',
1288-
},
1289-
textValue: 'This is just text',
1290-
},
1291-
}),
1292-
);
1286+
expect(options.globals).toEqual({
1287+
__DEV__: true,
1288+
config: {
1289+
hereToStay: 'This should stay here',
1290+
sideBySide: 'This should also live another day',
1291+
},
1292+
myString: 'hello sunshine',
1293+
textValue: 'This is just text',
1294+
});
12931295
});
12941296
});
12951297

packages/jest-config/src/normalize.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import micromatch = require('micromatch');
1717
import {sync as realpath} from 'realpath-native';
1818
import Resolver = require('jest-resolve');
1919
import {replacePathSepForRegex} from 'jest-regex-util';
20+
import merge = require('deepmerge');
2021
import validatePattern from './validatePattern';
2122
import getMaxWorkers from './getMaxWorkers';
2223
import {
@@ -112,12 +113,7 @@ const mergeGlobalsWithPreset = (
112113
preset: Config.InitialOptions,
113114
) => {
114115
if (options['globals'] && preset['globals']) {
115-
for (const p in preset['globals']) {
116-
options['globals'][p] = {
117-
...preset['globals'][p],
118-
...options['globals'][p],
119-
};
120-
}
116+
options['globals'] = merge(preset['globals'], options['globals']);
121117
}
122118
};
123119

packages/jest-types/src/Config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export type HasteConfig = {
2727
export type ReporterConfig = [string, Record<string, unknown>];
2828
export type TransformerConfig = [string, Record<string, unknown>];
2929

30-
export type ConfigGlobals = Record<string, any>;
30+
export interface ConfigGlobals {
31+
[K: string]: unknown;
32+
}
3133

3234
export type DefaultOptions = {
3335
automock: boolean;

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5221,6 +5221,11 @@ deepmerge@^3.2.0:
52215221
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-3.3.0.tgz#d3c47fd6f3a93d517b14426b0628a17b0125f5f7"
52225222
integrity sha512-GRQOafGHwMHpjPx9iCvTgpu9NojZ49q794EEL94JVEw6VaeA8XTUyBKvAkOOjBX9oJNiV6G3P+T+tihFjo2TqA==
52235223

5224+
deepmerge@^4.2.2:
5225+
version "4.2.2"
5226+
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"
5227+
integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==
5228+
52245229
defaults@^1.0.3:
52255230
version "1.0.3"
52265231
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"

0 commit comments

Comments
 (0)