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

fix(jest-jasmine2, jest-types): remove jasmine types from @jest/types #12125

Merged
merged 8 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
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 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
Original file line number Diff line number Diff line change
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about pending etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied them all here for completeness. They were not necessary internally, but might be useful for something else.

fail: () => void;
pending: () => void;
spyOn: () => void;
spyOnProperty: () => void;
}
}
}
2 changes: 2 additions & 0 deletions packages/jest-jasmine2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addMatchers implementation was removed in #9853

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think addMatchers still exist on jasmine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I had in mind Jest globals. It was removed from Jest globals, but Jasmin types still have addMatchers here: https://github.com/facebook/jest/blob/0d0844a249a179197e82bd1ea097a4cb6dad9f32/packages/jest-jasmine2/src/types.ts#L91

};

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