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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not modify global types via declarations #8571

Merged
merged 8 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {Circus, Config} from '@jest/types';
import {Circus, Config, Global} from '@jest/types';
import {JestEnvironment} from '@jest/environment';
import {AssertionResult, Status, TestResult} from '@jest/test-result';
import {extractExpectedAssertionsErrors, getState, setState} from 'expect';
Expand Down Expand Up @@ -53,15 +53,16 @@ export const initialize = ({

const mutex = throat(globalConfig.maxConcurrency);

Object.assign(global, globals);
const nodeGlobal = global as Global.Global;
Object.assign(nodeGlobal, globals);

global.xit = global.it.skip;
global.xtest = global.it.skip;
global.xdescribe = global.describe.skip;
global.fit = global.it.only;
global.fdescribe = global.describe.only;
nodeGlobal.xit = nodeGlobal.it.skip;
nodeGlobal.xtest = nodeGlobal.it.skip;
nodeGlobal.xdescribe = nodeGlobal.describe.skip;
nodeGlobal.fit = nodeGlobal.it.only;
nodeGlobal.fdescribe = nodeGlobal.describe.only;

global.test.concurrent = (test => {
nodeGlobal.test.concurrent = (test => {
const concurrent = (
testName: string,
testFn: () => Promise<any>,
Expand All @@ -74,7 +75,7 @@ export const initialize = ({
// that will result in this test to be skipped, so we'll be executing the promise function anyway,
// even if it ends up being skipped.
const promise = mutex(() => testFn());
global.test(testName, () => promise, timeout);
nodeGlobal.test(testName, () => promise, timeout);
};

concurrent.only = (
Expand All @@ -90,7 +91,7 @@ export const initialize = ({
concurrent.skip = test.skip;

return concurrent;
})(global.test);
})(nodeGlobal.test);

addEventHandler(eventHandler);

Expand Down
1 change: 1 addition & 0 deletions packages/jest-each/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"license": "MIT",
"dependencies": {
"@jest/types": "^24.8.0",
"@types/node": "*",
SimenB marked this conversation as resolved.
Show resolved Hide resolved
"chalk": "^2.0.1",
"jest-get-type": "^24.8.0",
"jest-util": "^24.8.0",
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-each/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import {Global} from '@jest/types';
import bind from './bind';

type Global = NodeJS.Global;

type Global = Global.Global;
const install = (
g: Global,
table: Global.EachTable,
Expand Down Expand Up @@ -44,7 +43,7 @@ const install = (
};

const each = (table: Global.EachTable, ...data: Global.TemplateData) =>
install(global, table, ...data);
install(global as Global, table, ...data);

each.withGlobal = (g: Global) => (
table: Global.EachTable,
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-jasmine2/src/jestExpect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import expect, {MatcherState} from 'expect';
import {Global} from '@jest/types';
import {
addSerializer,
toMatchSnapshot,
Expand All @@ -15,6 +16,8 @@ import {
} from 'jest-snapshot';
import {RawMatcherFn, Jasmine} from './types';

declare const global: Global.Global;

type JasmineMatcher = {
(matchersUtil: any, context: any): JasmineMatcher;
compare: () => RawMatcherFn;
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-jasmine2/src/setup_jest_globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {Config} from '@jest/types';
import {Config, Global} from '@jest/types';
import {Plugin} from 'pretty-format';
import {extractExpectedAssertionsErrors, getState, setState} from 'expect';
import {
Expand All @@ -16,6 +16,8 @@ import {
import JasmineSpec, {Attributes, SpecResult} from './jasmine/Spec';
import {Jasmine} from './types';

declare const global: Global.Global;

export type SetupOptions = {
config: Config.ProjectConfig;
globalConfig: Config.GlobalConfig;
Expand Down
16 changes: 0 additions & 16 deletions packages/jest-types/src/Global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,3 @@ export interface Global extends NodeJS.Global {
spyOn: () => void;
spyOnProperty: () => void;
}

declare global {
module NodeJS {
interface Global {
it: It;
test: ItConcurrent;
fit: ItBase;
xit: ItBase;
xtest: ItBase;
describe: Describe;
xdescribe: DescribeBase;
fdescribe: DescribeBase;
jasmine: Jasmine;
}
}
}