diff --git a/CHANGELOG.md b/CHANGELOG.md index 62338c844522..df981d065cf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - `[jest-environment-node]` [**BREAKING**] Migrate to ESM ([#12340](https://github.com/facebook/jest/pull/12340)) - `[@jest/expect-utils]` New module exporting utils for `expect` ([#12323](https://github.com/facebook/jest/pull/12323)) - `[jest-jasmine2, jest-runtime]` [**BREAKING**] Use `Symbol` to pass `jest.setTimeout` value instead of `jasmine` specific logic ([#12124](https://github.com/facebook/jest/pull/12124)) +- `[jest-jasmine2, jest-types]` [**BREAKING**] Move all `jasmine` specific types from `@jest/types` to its own package ([#12125](https://github.com/facebook/jest/pull/12125)) - `[jest-snapshot]` [**BREAKING**] Migrate to ESM ([#12342](https://github.com/facebook/jest/pull/12342)) - `[jest-worker]` [**BREAKING**] Allow only absolute `workerPath` ([#12343](https://github.com/facebook/jest/pull/12343)) diff --git a/packages/jest-jasmine2/src/errorOnPrivate.ts b/packages/jest-jasmine2/src/errorOnPrivate.ts index 1ffe1f0d081c..56874b058de4 100644 --- a/packages/jest-jasmine2/src/errorOnPrivate.ts +++ b/packages/jest-jasmine2/src/errorOnPrivate.ts @@ -7,7 +7,6 @@ import type {Global} from '@jest/types'; import {ErrorWithStack} from 'jest-util'; -import type {Jasmine} from './types'; type DisabledGlobalKeys = 'fail' | 'pending' | 'spyOn' | 'spyOnProperty'; @@ -40,7 +39,7 @@ const disabledJasmineMethods: Record = { }; export function installErrorOnPrivate(global: Global.Global): void { - const jasmine = global.jasmine as Jasmine; + const jasmine = global.jasmine; (Object.keys(disabledGlobals) as Array).forEach( functionName => { diff --git a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts index b7f705bd4b4e..3d9e85eb9552 100644 --- a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts +++ b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts @@ -230,7 +230,7 @@ export default function jasmineAsyncInstall( globalConfig: Config.GlobalConfig, global: Global.Global, ): void { - const jasmine = global.jasmine as Jasmine; + const jasmine = global.jasmine; const mutex = throat(globalConfig.maxConcurrency); const env = jasmine.getEnv(); diff --git a/packages/jest-jasmine2/src/jestExpect.ts b/packages/jest-jasmine2/src/jestExpect.ts index 1c1d2a2e85c1..6269cdfb40b0 100644 --- a/packages/jest-jasmine2/src/jestExpect.ts +++ b/packages/jest-jasmine2/src/jestExpect.ts @@ -7,7 +7,6 @@ /* eslint-disable local/prefer-spread-eventually */ -import type {Global} from '@jest/types'; import {MatcherState, expect} from 'expect'; import { addSerializer, @@ -16,9 +15,7 @@ import { toThrowErrorMatchingInlineSnapshot, toThrowErrorMatchingSnapshot, } from 'jest-snapshot'; -import type {Jasmine, JasmineMatchersObject, RawMatcherFn} from './types'; - -declare const global: Global.Global; +import type {JasmineMatchersObject, RawMatcherFn} from './types'; export default function jestExpect(config: {expand: boolean}): void { global.expect = expect; @@ -31,7 +28,7 @@ export default function jestExpect(config: {expand: boolean}): void { }); expect.addSnapshotSerializer = addSerializer; - const jasmine = global.jasmine as Jasmine; + const jasmine = global.jasmine; jasmine.anything = expect.anything; jasmine.any = expect.any; jasmine.objectContaining = expect.objectContaining; diff --git a/packages/jest-jasmine2/src/setup_jest_globals.ts b/packages/jest-jasmine2/src/setup_jest_globals.ts index 85473e4bf2d3..ceddb98beba6 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 type {Config, Global} from '@jest/types'; +import type {Config} from '@jest/types'; import {expect} from 'expect'; import { SnapshotState, @@ -18,9 +18,6 @@ import type { default as JasmineSpec, SpecResult, } from './jasmine/Spec'; -import type {Jasmine} from './types'; - -declare const global: Global.Global; export type SetupOptions = { config: Config.ProjectConfig; @@ -66,7 +63,7 @@ const addAssertionErrors = (result: SpecResult) => { }; const patchJasmine = () => { - (global.jasmine as Jasmine).Spec = (realSpec => { + global.jasmine.Spec = (realSpec => { class Spec extends realSpec { constructor(attr: Attributes) { const resultCallback = attr.resultCallback; @@ -85,7 +82,7 @@ const patchJasmine = () => { } return Spec; - })((global.jasmine as Jasmine).Spec); + })(global.jasmine.Spec); }; export default async function setupJestGlobals({ diff --git a/packages/jest-jasmine2/src/types.ts b/packages/jest-jasmine2/src/types.ts index 0266dcc0502c..2d8282a4be6b 100644 --- a/packages/jest-jasmine2/src/types.ts +++ b/packages/jest-jasmine2/src/types.ts @@ -96,6 +96,19 @@ declare global { namespace NodeJS { interface Global { expect: Expect; + jasmine: Jasmine; + } + } +} + +declare module '@jest/types' { + namespace Global { + interface GlobalAdditions { + jasmine: Jasmine; + fail: () => void; + pending: () => void; + spyOn: () => void; + spyOnProperty: () => void; } } } diff --git a/packages/jest-jasmine2/tsconfig.json b/packages/jest-jasmine2/tsconfig.json index 81029dc1642f..f7813a30ad7a 100644 --- a/packages/jest-jasmine2/tsconfig.json +++ b/packages/jest-jasmine2/tsconfig.json @@ -1,6 +1,8 @@ { "extends": "../../tsconfig", "compilerOptions": { + // we don't want `@types/jest` to be referenced + "types": [], "rootDir": "src", "outDir": "build" }, diff --git a/packages/jest-types/src/Global.ts b/packages/jest-types/src/Global.ts index 024d5777ca98..e0a7a1d802e5 100644 --- a/packages/jest-types/src/Global.ts +++ b/packages/jest-types/src/Global.ts @@ -51,12 +51,6 @@ export type EachTestFn = ( ...args: ReadonlyArray ) => ReturnType; -// TODO: Get rid of this at some point -type Jasmine = { - _DEFAULT_TIMEOUT_INTERVAL?: number; - addMatchers: (matchers: Record) => void; -}; - type Each = | (( table: EachTable, @@ -124,11 +118,6 @@ export interface TestFrameworkGlobals { export interface GlobalAdditions extends TestFrameworkGlobals { __coverage__: CoverageMapData; - jasmine: Jasmine; - fail: () => void; - pending: () => void; - spyOn: () => void; - spyOnProperty: () => void; } export interface Global