Skip to content

Commit 29d8f94

Browse files
committed
fix: remove deprecated funtions from the jest object
1 parent 7e5e27a commit 29d8f94

File tree

10 files changed

+18
-47
lines changed

10 files changed

+18
-47
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### Chore & Maintenance
88

9+
- `[jest-runtime]` [**BREAKING**] remove long-deprecated `jest.addMatchers`, `jest.resetModuleRegistry`, and `jest.runTimersToTime` ([#9853](https://github.com/facebook/jest/pull/9853))
10+
911
### Performance
1012

1113
## 26.4.2

docs/JestObjectAPI.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,6 @@ Exhausts all tasks queued by `setImmediate()`.
617617
618618
### `jest.advanceTimersByTime(msToRun)`
619619

620-
##### renamed in Jest **22.0.0+**
621-
622-
Also under the alias: `.runTimersToTime()`
623-
624620
Executes only the macro task queue (i.e. all tasks queued by `setTimeout()` or `setInterval()` and `setImmediate()`).
625621

626622
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.

docs/TimerMocks.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ describe('infiniteTimerGame', () => {
120120

121121
## Advance Timers by Time
122122

123-
##### renamed from `runTimersToTime` to `advanceTimersByTime` in Jest **22.0.0**
124-
125123
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.
126124

127125
```javascript

packages/jest-environment/src/index.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ export type Module = NodeModule;
5757

5858
// TODO: Move to some separate package
5959
export interface Jest {
60-
/**
61-
* Provides a way to add Jasmine-compatible matchers into your Jest context.
62-
*
63-
* @deprecated Use `expect.extend` instead
64-
*/
65-
addMatchers(matchers: Record<string, any>): void;
6660
/**
6761
* Advances all timers by the needed milliseconds so that only the next timeouts/intervals will run.
6862
* Optionally, you can provide steps, so it will run steps amount of next timeouts/intervals.
@@ -182,13 +176,6 @@ export interface Jest {
182176
* Equivalent to calling .mockReset() on every mocked function.
183177
*/
184178
resetAllMocks(): Jest;
185-
/**
186-
* Resets the module registry - the cache of all required modules. This is
187-
* useful to isolate modules where local state might conflict between tests.
188-
*
189-
* @deprecated Use `jest.resetModules()`
190-
*/
191-
resetModuleRegistry(): Jest;
192179
/**
193180
* Resets the module registry - the cache of all required modules. This is
194181
* useful to isolate modules where local state might conflict between tests.
@@ -236,13 +223,6 @@ export interface Jest {
236223
* executed within this timeframe will be executed.
237224
*/
238225
advanceTimersByTime(msToRun: number): void;
239-
/**
240-
* Executes only the macro task queue (i.e. all tasks queued by setTimeout()
241-
* or setInterval() and setImmediate()).
242-
*
243-
* @deprecated Use `jest.advanceTimersByTime()`
244-
*/
245-
runTimersToTime(msToRun: number): void;
246226
/**
247227
* Returns the number of fake timers still left to run.
248228
*/

packages/jest-haste-map/src/__tests__/index.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ describe('HasteMap', () => {
224224
});
225225

226226
it('creates valid cache file paths', () => {
227-
jest.resetModuleRegistry();
227+
jest.resetModules();
228228
HasteMap = require('../');
229229

230230
expect(
@@ -237,15 +237,15 @@ describe('HasteMap', () => {
237237
});
238238

239239
it('creates different cache file paths for different roots', () => {
240-
jest.resetModuleRegistry();
240+
jest.resetModules();
241241
const HasteMap = require('../');
242242
const hasteMap1 = new HasteMap({...defaultConfig, rootDir: '/root1'});
243243
const hasteMap2 = new HasteMap({...defaultConfig, rootDir: '/root2'});
244244
expect(hasteMap1.getCacheFilePath()).not.toBe(hasteMap2.getCacheFilePath());
245245
});
246246

247247
it('creates different cache file paths for different dependency extractor cache keys', () => {
248-
jest.resetModuleRegistry();
248+
jest.resetModules();
249249
const HasteMap = require('../');
250250
const dependencyExtractor = require('./dependencyExtractor');
251251
const config = {
@@ -260,7 +260,7 @@ describe('HasteMap', () => {
260260
});
261261

262262
it('creates different cache file paths for different hasteImplModulePath cache keys', () => {
263-
jest.resetModuleRegistry();
263+
jest.resetModules();
264264
const HasteMap = require('../');
265265
const hasteImpl = require('./haste_impl');
266266
hasteImpl.setCacheKey('foo');
@@ -271,7 +271,7 @@ describe('HasteMap', () => {
271271
});
272272

273273
it('creates different cache file paths for different projects', () => {
274-
jest.resetModuleRegistry();
274+
jest.resetModules();
275275
const HasteMap = require('../');
276276
const hasteMap1 = new HasteMap({...defaultConfig, name: '@scoped/package'});
277277
const hasteMap2 = new HasteMap({...defaultConfig, name: '-scoped-package'});

packages/jest-runtime/src/__tests__/runtime_mock.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('Runtime', () => {
2525
const mockReference = {isMock: true};
2626
const root = runtime.requireModule(runtime.__mockRootPath, rootJsPath);
2727
// Erase module registry because root.js requires most other modules.
28-
root.jest.resetModuleRegistry();
28+
root.jest.resetModules();
2929

3030
root.jest.mock('RegularModule', () => mockReference);
3131
root.jest.mock('ManuallyMocked', () => mockReference);
@@ -53,7 +53,7 @@ describe('Runtime', () => {
5353
const virtual = true;
5454
const root = runtime.requireModule(runtime.__mockRootPath, rootJsPath);
5555
// Erase module registry because root.js requires most other modules.
56-
root.jest.resetModuleRegistry();
56+
root.jest.resetModules();
5757

5858
root.jest.mock('NotInstalledModule', () => mockReference, {virtual});
5959
root.jest.mock('../ManuallyMocked', () => mockReference, {virtual});
@@ -87,7 +87,7 @@ describe('Runtime', () => {
8787
const virtual = true;
8888
const root = runtime.requireModule(runtime.__mockRootPath, rootJsPath);
8989
// Erase module registry because root.js requires most other modules.
90-
root.jest.resetModuleRegistry();
90+
root.jest.resetModules();
9191

9292
root.jest.mock('NotInstalledModule', () => mockReference, {virtual});
9393
root.jest.mock('../ManuallyMocked', () => mockReference, {virtual});
@@ -122,7 +122,7 @@ describe('Runtime', () => {
122122
const mockReference = {isMock: true};
123123
const root = runtime.requireModule(runtime.__mockRootPath, rootJsPath);
124124
// Erase module registry because root.js requires most other modules.
125-
root.jest.resetModuleRegistry();
125+
root.jest.resetModules();
126126

127127
root.jest.setMock('RegularModule', mockReference);
128128
root.jest.setMock('ManuallyMocked', mockReference);

packages/jest-runtime/src/__tests__/runtime_require_module.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ describe('Runtime requireModule', () => {
233233
automock: true,
234234
}).then(runtime => {
235235
const root = runtime.requireModule(runtime.__mockRootPath, './root.js');
236-
root.jest.resetModuleRegistry();
236+
root.jest.resetModules();
237237
root.jest.unmock('ManuallyMocked');
238238
const exports = runtime.requireModule(
239239
runtime.__mockRootPath,

packages/jest-runtime/src/__tests__/runtime_require_module_or_mock_transitive_deps.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('transitive dependencies', () => {
6363
);
6464

6565
// Test twice to make sure Runtime caching works properly
66-
root.jest.resetModuleRegistry();
66+
root.jest.resetModules();
6767
expectUnmocked(
6868
runtime.requireModuleOrMock(runtime.__mockRootPath, 'npm3-main-dep'),
6969
);
@@ -88,7 +88,7 @@ describe('transitive dependencies', () => {
8888
);
8989

9090
// Test twice to make sure Runtime caching works properly
91-
root.jest.resetModuleRegistry();
91+
root.jest.resetModules();
9292
expectUnmocked(
9393
runtime.requireModuleOrMock(runtime.__mockRootPath, 'npm3-main-dep'),
9494
);
@@ -114,7 +114,7 @@ describe('transitive dependencies', () => {
114114
);
115115

116116
// Test twice to make sure Runtime caching works properly
117-
root.jest.resetModuleRegistry();
117+
root.jest.resetModules();
118118
expectUnmocked(
119119
runtime.requireModuleOrMock(runtime.__mockRootPath, 'npm3-main-dep'),
120120
);

packages/jest-runtime/src/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,8 +1499,6 @@ class Runtime {
14991499
};
15001500

15011501
const jestObject: Jest = {
1502-
addMatchers: (matchers: Record<string, any>) =>
1503-
this._environment.global.jasmine.addMatchers(matchers),
15041502
advanceTimersByTime: (msToRun: number) =>
15051503
_getFakeTimers().advanceTimersByTime(msToRun),
15061504
advanceTimersToNextTimer: (steps?: number) =>
@@ -1537,7 +1535,6 @@ class Runtime {
15371535
requireActual: this.requireActual.bind(this, from),
15381536
requireMock: this.requireMock.bind(this, from),
15391537
resetAllMocks,
1540-
resetModuleRegistry: resetModules,
15411538
resetModules,
15421539
restoreAllMocks,
15431540
retryTimes,
@@ -1555,8 +1552,6 @@ class Runtime {
15551552
runAllTicks: () => _getFakeTimers().runAllTicks(),
15561553
runAllTimers: () => _getFakeTimers().runAllTimers(),
15571554
runOnlyPendingTimers: () => _getFakeTimers().runOnlyPendingTimers(),
1558-
runTimersToTime: (msToRun: number) =>
1559-
_getFakeTimers().advanceTimersByTime(msToRun),
15601555
setMock: (moduleName: string, mock: unknown) =>
15611556
setMockFactory(moduleName, () => mock),
15621557
setSystemTime: (now?: number | Date) => {

packages/jest-transform/src/__tests__/script_transformer.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ describe('ScriptTransformer', () => {
669669

670670
// Cache the state in `mockFsCopy`
671671
const mockFsCopy = mockFs;
672-
jest.resetModuleRegistry();
672+
jest.resetModules();
673673
reset();
674674

675675
// Restore the cached fs
@@ -683,7 +683,7 @@ describe('ScriptTransformer', () => {
683683
expect(writeFileAtomic.sync).not.toBeCalled();
684684

685685
// Don't read from the cache when `config.cache` is false.
686-
jest.resetModuleRegistry();
686+
jest.resetModules();
687687
reset();
688688
mockFs = mockFsCopy;
689689
transformConfig.cache = false;
@@ -710,7 +710,7 @@ describe('ScriptTransformer', () => {
710710

711711
// Cache the state in `mockFsCopy`
712712
const mockFsCopy = mockFs;
713-
jest.resetModuleRegistry();
713+
jest.resetModules();
714714
reset();
715715

716716
// Restore the cached fs

0 commit comments

Comments
 (0)