diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e21fe0afb67..130cfdad2da8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ - `[jest-resolve]` Replace read-pkg-up with escalade package ([#10781](https://github.com/facebook/jest/pull/10781)) - `[jest-runtime]` [**BREAKING**] Do not inject `global` variable into module wrapper ([#10644](https://github.com/facebook/jest/pull/10644)) -- `[jest-runtime]` [**BREAKING**] Convert to ESM ([#10325](https://github.com/facebook/jest/pull/10325)) +- `[jest-runtime]` [**BREAKING**] remove long-deprecated `jest.addMatchers`, `jest.resetModuleRegistry`, and `jest.runTimersToTime` ([#9853](https://github.com/facebook/jest/pull/9853)) - `[jest-transform]` Show enhanced `SyntaxError` message for all `SyntaxError`s ([#10749](https://github.com/facebook/jest/pull/10749)) - `[jest-transform]` [**BREAKING**] Refactor API to pass an options bag around rather than multiple boolean options ([#10753](https://github.com/facebook/jest/pull/10753)) diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index b62c319e33d4..5553a5d58561 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -616,10 +616,6 @@ Exhausts all tasks queued by `setImmediate()`. ### `jest.advanceTimersByTime(msToRun)` -##### renamed in Jest **22.0.0+** - -Also under the alias: `.runTimersToTime()` - Executes only the macro task queue (i.e. all tasks queued by `setTimeout()` or `setInterval()` and `setImmediate()`). When this API is called, all timers are advanced by `msToRun` milliseconds. All pending "macro-tasks" that have been queued via `setTimeout()` or `setInterval()`, and would be executed within this time frame will be executed. Additionally, if those macro-tasks schedule new macro-tasks that would be executed within the same time frame, those will be executed until there are no more macro-tasks remaining in the queue, that should be run within `msToRun` milliseconds. diff --git a/docs/TimerMocks.md b/docs/TimerMocks.md index 75d875ea08fe..5ab344ba81a2 100644 --- a/docs/TimerMocks.md +++ b/docs/TimerMocks.md @@ -120,8 +120,6 @@ describe('infiniteTimerGame', () => { ## Advance Timers by Time -##### renamed from `runTimersToTime` to `advanceTimersByTime` in Jest **22.0.0** - Another possibility is use `jest.advanceTimersByTime(msToRun)`. When this API is called, all timers are advanced by `msToRun` milliseconds. All pending "macro-tasks" that have been queued via setTimeout() or setInterval(), and would be executed during this time frame, will be executed. Additionally, if those macro-tasks schedule new macro-tasks that would be executed within the same time frame, those will be executed until there are no more macro-tasks remaining in the queue that should be run within msToRun milliseconds. ```javascript diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index bdc833d5e73d..f83d0cb5c595 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -56,12 +56,6 @@ export type Module = NodeModule; // TODO: Move to some separate package export interface Jest { - /** - * Provides a way to add Jasmine-compatible matchers into your Jest context. - * - * @deprecated Use `expect.extend` instead - */ - addMatchers(matchers: Record): void; /** * Advances all timers by the needed milliseconds so that only the next timeouts/intervals will run. * Optionally, you can provide steps, so it will run steps amount of next timeouts/intervals. @@ -183,13 +177,6 @@ export interface Jest { * Equivalent to calling .mockReset() on every mocked function. */ resetAllMocks(): Jest; - /** - * Resets the module registry - the cache of all required modules. This is - * useful to isolate modules where local state might conflict between tests. - * - * @deprecated Use `jest.resetModules()` - */ - resetModuleRegistry(): Jest; /** * Resets the module registry - the cache of all required modules. This is * useful to isolate modules where local state might conflict between tests. @@ -237,13 +224,6 @@ export interface Jest { * executed within this timeframe will be executed. */ advanceTimersByTime(msToRun: number): void; - /** - * Executes only the macro task queue (i.e. all tasks queued by setTimeout() - * or setInterval() and setImmediate()). - * - * @deprecated Use `jest.advanceTimersByTime()` - */ - runTimersToTime(msToRun: number): void; /** * Returns the number of fake timers still left to run. */ diff --git a/packages/jest-haste-map/src/__tests__/index.test.js b/packages/jest-haste-map/src/__tests__/index.test.js index 6dba04a9a81e..a711d89c35f0 100644 --- a/packages/jest-haste-map/src/__tests__/index.test.js +++ b/packages/jest-haste-map/src/__tests__/index.test.js @@ -224,7 +224,7 @@ describe('HasteMap', () => { }); it('creates valid cache file paths', () => { - jest.resetModuleRegistry(); + jest.resetModules(); HasteMap = require('../'); expect( @@ -237,7 +237,7 @@ describe('HasteMap', () => { }); it('creates different cache file paths for different roots', () => { - jest.resetModuleRegistry(); + jest.resetModules(); const HasteMap = require('../'); const hasteMap1 = new HasteMap({...defaultConfig, rootDir: '/root1'}); const hasteMap2 = new HasteMap({...defaultConfig, rootDir: '/root2'}); @@ -245,7 +245,7 @@ describe('HasteMap', () => { }); it('creates different cache file paths for different dependency extractor cache keys', () => { - jest.resetModuleRegistry(); + jest.resetModules(); const HasteMap = require('../'); const dependencyExtractor = require('./dependencyExtractor'); const config = { @@ -260,7 +260,7 @@ describe('HasteMap', () => { }); it('creates different cache file paths for different hasteImplModulePath cache keys', () => { - jest.resetModuleRegistry(); + jest.resetModules(); const HasteMap = require('../'); const hasteImpl = require('./haste_impl'); hasteImpl.setCacheKey('foo'); @@ -271,7 +271,7 @@ describe('HasteMap', () => { }); it('creates different cache file paths for different projects', () => { - jest.resetModuleRegistry(); + jest.resetModules(); const HasteMap = require('../'); const hasteMap1 = new HasteMap({...defaultConfig, name: '@scoped/package'}); const hasteMap2 = new HasteMap({...defaultConfig, name: '-scoped-package'}); diff --git a/packages/jest-runtime/src/__tests__/runtime_mock.test.js b/packages/jest-runtime/src/__tests__/runtime_mock.test.js index 4b20d996e0fd..bfc6f0da0b08 100644 --- a/packages/jest-runtime/src/__tests__/runtime_mock.test.js +++ b/packages/jest-runtime/src/__tests__/runtime_mock.test.js @@ -25,7 +25,7 @@ describe('Runtime', () => { const mockReference = {isMock: true}; const root = runtime.requireModule(runtime.__mockRootPath, rootJsPath); // Erase module registry because root.js requires most other modules. - root.jest.resetModuleRegistry(); + root.jest.resetModules(); root.jest.mock('RegularModule', () => mockReference); root.jest.mock('ManuallyMocked', () => mockReference); @@ -53,7 +53,7 @@ describe('Runtime', () => { const virtual = true; const root = runtime.requireModule(runtime.__mockRootPath, rootJsPath); // Erase module registry because root.js requires most other modules. - root.jest.resetModuleRegistry(); + root.jest.resetModules(); root.jest.mock('NotInstalledModule', () => mockReference, {virtual}); root.jest.mock('../ManuallyMocked', () => mockReference, {virtual}); @@ -87,7 +87,7 @@ describe('Runtime', () => { const virtual = true; const root = runtime.requireModule(runtime.__mockRootPath, rootJsPath); // Erase module registry because root.js requires most other modules. - root.jest.resetModuleRegistry(); + root.jest.resetModules(); root.jest.mock('NotInstalledModule', () => mockReference, {virtual}); root.jest.mock('../ManuallyMocked', () => mockReference, {virtual}); @@ -122,7 +122,7 @@ describe('Runtime', () => { const mockReference = {isMock: true}; const root = runtime.requireModule(runtime.__mockRootPath, rootJsPath); // Erase module registry because root.js requires most other modules. - root.jest.resetModuleRegistry(); + root.jest.resetModules(); root.jest.setMock('RegularModule', mockReference); root.jest.setMock('ManuallyMocked', mockReference); diff --git a/packages/jest-runtime/src/__tests__/runtime_require_module.test.js b/packages/jest-runtime/src/__tests__/runtime_require_module.test.js index 244222b294a1..2de938a3132a 100644 --- a/packages/jest-runtime/src/__tests__/runtime_require_module.test.js +++ b/packages/jest-runtime/src/__tests__/runtime_require_module.test.js @@ -237,7 +237,7 @@ describe('Runtime requireModule', () => { automock: true, }).then(runtime => { const root = runtime.requireModule(runtime.__mockRootPath, './root.js'); - root.jest.resetModuleRegistry(); + root.jest.resetModules(); root.jest.unmock('ManuallyMocked'); const exports = runtime.requireModule( runtime.__mockRootPath, diff --git a/packages/jest-runtime/src/__tests__/runtime_require_module_or_mock_transitive_deps.test.js b/packages/jest-runtime/src/__tests__/runtime_require_module_or_mock_transitive_deps.test.js index abddb0c16f13..22ab22c7cef5 100644 --- a/packages/jest-runtime/src/__tests__/runtime_require_module_or_mock_transitive_deps.test.js +++ b/packages/jest-runtime/src/__tests__/runtime_require_module_or_mock_transitive_deps.test.js @@ -63,7 +63,7 @@ describe('transitive dependencies', () => { ); // Test twice to make sure Runtime caching works properly - root.jest.resetModuleRegistry(); + root.jest.resetModules(); expectUnmocked( runtime.requireModuleOrMock(runtime.__mockRootPath, 'npm3-main-dep'), ); @@ -88,7 +88,7 @@ describe('transitive dependencies', () => { ); // Test twice to make sure Runtime caching works properly - root.jest.resetModuleRegistry(); + root.jest.resetModules(); expectUnmocked( runtime.requireModuleOrMock(runtime.__mockRootPath, 'npm3-main-dep'), ); @@ -114,7 +114,7 @@ describe('transitive dependencies', () => { ); // Test twice to make sure Runtime caching works properly - root.jest.resetModuleRegistry(); + root.jest.resetModules(); expectUnmocked( runtime.requireModuleOrMock(runtime.__mockRootPath, 'npm3-main-dep'), ); diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 0b679ee3f47f..65376a7c7403 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -1561,8 +1561,6 @@ export default class Runtime { }; const jestObject: Jest = { - addMatchers: (matchers: Record) => - this._environment.global.jasmine.addMatchers(matchers), advanceTimersByTime: (msToRun: number) => _getFakeTimers().advanceTimersByTime(msToRun), advanceTimersToNextTimer: (steps?: number) => @@ -1599,7 +1597,6 @@ export default class Runtime { requireActual: this.requireActual.bind(this, from), requireMock: this.requireMock.bind(this, from), resetAllMocks, - resetModuleRegistry: resetModules, resetModules, restoreAllMocks, retryTimes, @@ -1617,8 +1614,6 @@ export default class Runtime { runAllTicks: () => _getFakeTimers().runAllTicks(), runAllTimers: () => _getFakeTimers().runAllTimers(), runOnlyPendingTimers: () => _getFakeTimers().runOnlyPendingTimers(), - runTimersToTime: (msToRun: number) => - _getFakeTimers().advanceTimersByTime(msToRun), setMock: (moduleName: string, mock: unknown) => setMockFactory(moduleName, () => mock), setSystemTime: (now?: number | Date) => { diff --git a/packages/jest-transform/src/__tests__/script_transformer.test.ts b/packages/jest-transform/src/__tests__/script_transformer.test.ts index 998c07d4579b..02ea4ed4351c 100644 --- a/packages/jest-transform/src/__tests__/script_transformer.test.ts +++ b/packages/jest-transform/src/__tests__/script_transformer.test.ts @@ -693,7 +693,7 @@ describe('ScriptTransformer', () => { // Cache the state in `mockFsCopy` const mockFsCopy = mockFs; - jest.resetModuleRegistry(); + jest.resetModules(); reset(); // Restore the cached fs @@ -707,7 +707,7 @@ describe('ScriptTransformer', () => { expect(writeFileAtomic.sync).not.toBeCalled(); // Don't read from the cache when `config.cache` is false. - jest.resetModuleRegistry(); + jest.resetModules(); reset(); mockFs = mockFsCopy; transformConfig.cache = false; @@ -737,7 +737,7 @@ describe('ScriptTransformer', () => { // Cache the state in `mockFsCopy` const mockFsCopy = mockFs; - jest.resetModuleRegistry(); + jest.resetModules(); reset(); // Restore the cached fs diff --git a/test-types/top-level-jest-namespace.test.ts b/test-types/top-level-jest-namespace.test.ts index b00e69b62021..3839613967a1 100644 --- a/test-types/top-level-jest-namespace.test.ts +++ b/test-types/top-level-jest-namespace.test.ts @@ -11,7 +11,6 @@ import {expectError, expectType} from 'mlh-tsd'; import {jest} from '@jest/globals'; import type {Mock} from 'jest-mock'; -expectType(jest.addMatchers({})); expectType(jest.autoMockOff()); expectType(jest.autoMockOn()); expectType(jest.clearAllMocks()); @@ -33,7 +32,6 @@ expectType(jest.mock('moduleName')); expectType(jest.mock('moduleName', jest.fn())); expectType(jest.mock('moduleName', jest.fn(), {})); expectType(jest.mock('moduleName', jest.fn(), {virtual: true})); -expectType(jest.resetModuleRegistry()); expectType(jest.resetModules()); expectType(jest.isolateModules(() => {})); expectType(jest.retryTimes(3)); @@ -62,7 +60,6 @@ expectType(jest.runAllImmediates()); expectType(jest.runAllTicks()); expectType(jest.runAllTimers()); expectType(jest.runOnlyPendingTimers()); -expectType(jest.runTimersToTime(9001)); expectType(jest.advanceTimersByTime(9001)); expectType(jest.setMock('moduleName', {}));