Skip to content

Commit

Permalink
fix(jest-jasmine2, jest-types): remove jasmine types from `@jest/ty…
Browse files Browse the repository at this point in the history
…pes` (#12125)
  • Loading branch information
mrazauskas committed Feb 10, 2022
1 parent 0d0844a commit a5f58b5
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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))

Expand Down
3 changes: 1 addition & 2 deletions packages/jest-jasmine2/src/errorOnPrivate.ts
Expand Up @@ -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';

Expand Down Expand Up @@ -40,7 +39,7 @@ const disabledJasmineMethods: Record<DisabledJasmineMethodsKeys, string> = {
};

export function installErrorOnPrivate(global: Global.Global): void {
const jasmine = global.jasmine as Jasmine;
const jasmine = global.jasmine;

(Object.keys(disabledGlobals) as Array<DisabledGlobalKeys>).forEach(
functionName => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/jasmineAsyncInstall.ts
Expand Up @@ -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();
Expand Down
7 changes: 2 additions & 5 deletions packages/jest-jasmine2/src/jestExpect.ts
Expand Up @@ -7,7 +7,6 @@

/* eslint-disable local/prefer-spread-eventually */

import type {Global} from '@jest/types';
import {MatcherState, expect} from 'expect';
import {
addSerializer,
Expand All @@ -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;
Expand All @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions packages/jest-jasmine2/src/setup_jest_globals.ts
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -85,7 +82,7 @@ const patchJasmine = () => {
}

return Spec;
})((global.jasmine as Jasmine).Spec);
})(global.jasmine.Spec);
};

export default async function setupJestGlobals({
Expand Down
13 changes: 13 additions & 0 deletions packages/jest-jasmine2/src/types.ts
Expand Up @@ -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;
}
}
}
2 changes: 2 additions & 0 deletions 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"
},
Expand Down
11 changes: 0 additions & 11 deletions packages/jest-types/src/Global.ts
Expand Up @@ -51,12 +51,6 @@ export type EachTestFn<EachCallback extends TestCallback> = (
...args: ReadonlyArray<any>
) => ReturnType<EachCallback>;

// TODO: Get rid of this at some point
type Jasmine = {
_DEFAULT_TIMEOUT_INTERVAL?: number;
addMatchers: (matchers: Record<string, unknown>) => void;
};

type Each<EachCallback extends TestCallback> =
| ((
table: EachTable,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a5f58b5

Please sign in to comment.