diff --git a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts index 8f75aba0df63..9804125de04e 100644 --- a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts +++ b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts @@ -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'; @@ -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, @@ -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 = ( @@ -90,7 +91,7 @@ export const initialize = ({ concurrent.skip = test.skip; return concurrent; - })(global.test); + })(nodeGlobal.test); addEventHandler(eventHandler); diff --git a/packages/jest-each/src/index.ts b/packages/jest-each/src/index.ts index 4ee273bbb596..016e5f60293c 100644 --- a/packages/jest-each/src/index.ts +++ b/packages/jest-each/src/index.ts @@ -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, @@ -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, diff --git a/packages/jest-jasmine2/src/jestExpect.ts b/packages/jest-jasmine2/src/jestExpect.ts index 9453f1731638..254e95701de3 100644 --- a/packages/jest-jasmine2/src/jestExpect.ts +++ b/packages/jest-jasmine2/src/jestExpect.ts @@ -6,6 +6,7 @@ */ import expect, {MatcherState} from 'expect'; +import {Global} from '@jest/types'; import { addSerializer, toMatchSnapshot, @@ -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; diff --git a/packages/jest-jasmine2/src/setup_jest_globals.ts b/packages/jest-jasmine2/src/setup_jest_globals.ts index 9da4aa850bb9..e66580c8bba6 100644 --- a/packages/jest-jasmine2/src/setup_jest_globals.ts +++ b/packages/jest-jasmine2/src/setup_jest_globals.ts @@ -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 { @@ -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; diff --git a/packages/jest-types/src/Global.ts b/packages/jest-types/src/Global.ts index d237eaa3ef5d..3203b7533d62 100644 --- a/packages/jest-types/src/Global.ts +++ b/packages/jest-types/src/Global.ts @@ -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; - } - } -}