Skip to content

Commit

Permalink
fix(jest-types): make ConfigGlobal an interace (#9570)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Feb 28, 2020
1 parent 4f4513b commit cc5d630
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
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;
}

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

0 comments on commit cc5d630

Please sign in to comment.