From 1bf56dd14bd7eb7be68673dcc7af5e4438707bce Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Mon, 29 Apr 2024 13:43:06 +0300 Subject: [PATCH] refactor!: remove deprecated `jest.genMockFromModule()` (#15042) --- CHANGELOG.md | 1 + packages/jest-environment/src/index.ts | 11 ---------- .../lib/__tests__/dependencyExtractor.test.js | 22 ------------------- .../src/lib/dependencyExtractor.ts | 2 +- packages/jest-runtime/src/index.ts | 1 - 5 files changed, 2 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 010d1482061b..9ebd22a9a606 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - `[@jest/core]` [**BREAKING**] Changed `--filter` to accept an object with shape `{ filtered: Array }` to match [documentation](https://jestjs.io/docs/cli#--filterfile) ([#13319](https://github.com/jestjs/jest/pull/13319)) - `[@jest/core]` Support `--outputFile` option for [`--listTests`](https://jestjs.io/docs/cli#--listtests) ([#14980](https://github.com/jestjs/jest/pull/14980)) - `[@jest/core, @jest/test-sequencer]` [**BREAKING**] Exposes `globalConfig` & `contexts` to `TestSequencer` ([#14535](https://github.com/jestjs/jest/pull/14535), & [#14543](https://github.com/jestjs/jest/pull/14543)) +- `[@jest/environment]` [**BREAKING**] Remove deprecated `jest.genMockFromModule()` ([#15042](https://github.com/jestjs/jest/pull/15042)) - `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM to v22 ([#13825](https://github.com/jestjs/jest/pull/13825)) - `[@jest/environment-jsdom-abstract]` Introduce new package which abstracts over the `jsdom` environment, allowing usage of custom versions of JSDOM ([#14717](https://github.com/jestjs/jest/pull/14717)) - `[jest-environment-node]` Update jest environment with dispose symbols `Symbol` ([#14888](https://github.com/jestjs/jest/pull/14888) & [#14909](https://github.com/jestjs/jest/pull/14909)) diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index eed42adcffd7..aee80f545df4 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -153,17 +153,6 @@ export interface Jest { * Creates a mock function. Optionally takes a mock implementation. */ fn: ModuleMocker['fn']; - // TODO remove `genMockFromModule()` in Jest 30 - /** - * Given the name of a module, use the automatic mocking system to generate a - * mocked version of the module for you. - * - * This is useful when you want to create a manual mock that extends the - * automatic mock's behavior. - * - * @deprecated Use `jest.createMockFromModule()` instead - */ - genMockFromModule(moduleName: string): Mocked; /** * When mocking time, `Date.now()` will also be mocked. If you for some reason * need access to the real current time, you can invoke this function. diff --git a/packages/jest-haste-map/src/lib/__tests__/dependencyExtractor.test.js b/packages/jest-haste-map/src/lib/__tests__/dependencyExtractor.test.js index d07cb7b5187b..c1e4c574ddc4 100644 --- a/packages/jest-haste-map/src/lib/__tests__/dependencyExtractor.test.js +++ b/packages/jest-haste-map/src/lib/__tests__/dependencyExtractor.test.js @@ -231,28 +231,6 @@ describe('dependencyExtractor', () => { ); }); - it('should extract dependencies from `jest.genMockFromModule` calls', () => { - const code = ` - // Good - jest.genMockFromModule('dep1'); - const dep2 = jest.genMockFromModule( - "dep2", - ); - if (jest.genMockFromModule(\`dep3\`).cond) {} - jest - .requireMock('dep4'); - - // Bad - foo . jest.genMockFromModule('inv1') - xjest.genMockFromModule('inv2'); - jest.genMockFromModulex('inv3'); - jest.genMockFromModule('inv4', 'inv5'); - `; - expect(extractor.extract(code)).toEqual( - new Set(['dep1', 'dep2', 'dep3', 'dep4']), - ); - }); - it('should extract dependencies from `jest.createMockFromModule` calls', () => { const code = ` // Good diff --git a/packages/jest-haste-map/src/lib/dependencyExtractor.ts b/packages/jest-haste-map/src/lib/dependencyExtractor.ts index 0b7fa2ea4bf8..4983c70b6832 100644 --- a/packages/jest-haste-map/src/lib/dependencyExtractor.ts +++ b/packages/jest-haste-map/src/lib/dependencyExtractor.ts @@ -60,7 +60,7 @@ const IMPORT_OR_EXPORT_RE = createRegExp( const JEST_EXTENSIONS_RE = createRegExp( [ ...functionCallStart( - 'jest\\s*\\.\\s*(?:requireActual|requireMock|genMockFromModule|createMockFromModule)', + 'jest\\s*\\.\\s*(?:requireActual|requireMock|createMockFromModule)', ), CAPTURE_STRING_LITERAL(1), WHITESPACE, diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 551bce13a28b..0e81d0894bbe 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -2359,7 +2359,6 @@ export default class Runtime { dontMock: unmock, enableAutomock, fn, - genMockFromModule: moduleName => this._generateMock(from, moduleName), getRealSystemTime: () => { const fakeTimers = _getFakeTimers();