Skip to content

Commit 731dffc

Browse files
committed
fix: remove deprecated funtions from the jest object
1 parent 47e956f commit 731dffc

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
@@ -10,6 +10,8 @@
1010

1111
### Chore & Maintenance
1212

13+
- `[jest-runtime]` [**BREAKING**] remove long-deprecated `jest.addMatchers`, `jest.resetModuleRegistry`, and `jest.runTimersToTime`
14+
1315
### Performance
1416

1517
## 25.4.0

docs/JestObjectAPI.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,6 @@ Exhausts all tasks queued by `setImmediate()`.
609609

610610
### `jest.advanceTimersByTime(msToRun)`
611611

612-
##### renamed in Jest **22.0.0+**
613-
614-
Also under the alias: `.runTimersToTime()`
615-
616612
Executes only the macro task queue (i.e. all tasks queued by `setTimeout()` or `setInterval()` and `setImmediate()`).
617613

618614
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
@@ -65,12 +65,6 @@ export interface LocalModuleRequire extends NodeRequire {
6565

6666
// TODO: Move to some separate package
6767
export interface Jest {
68-
/**
69-
* Provides a way to add Jasmine-compatible matchers into your Jest context.
70-
*
71-
* @deprecated Use `expect.extend` instead
72-
*/
73-
addMatchers(matchers: Record<string, any>): void;
7468
/**
7569
* Advances all timers by the needed milliseconds so that only the next timeouts/intervals will run.
7670
* Optionally, you can provide steps, so it will run steps amount of next timeouts/intervals.
@@ -180,13 +174,6 @@ export interface Jest {
180174
* Equivalent to calling .mockReset() on every mocked function.
181175
*/
182176
resetAllMocks(): Jest;
183-
/**
184-
* Resets the module registry - the cache of all required modules. This is
185-
* useful to isolate modules where local state might conflict between tests.
186-
*
187-
* @deprecated Use `jest.resetModules()`
188-
*/
189-
resetModuleRegistry(): Jest;
190177
/**
191178
* Resets the module registry - the cache of all required modules. This is
192179
* useful to isolate modules where local state might conflict between tests.
@@ -232,13 +219,6 @@ export interface Jest {
232219
* executed within this timeframe will be executed.
233220
*/
234221
advanceTimersByTime(msToRun: number): void;
235-
/**
236-
* Executes only the macro task queue (i.e. all tasks queued by setTimeout()
237-
* or setInterval() and setImmediate()).
238-
*
239-
* @deprecated Use `jest.advanceTimersByTime()`
240-
*/
241-
runTimersToTime(msToRun: number): void;
242222
/**
243223
* Returns the number of fake timers still left to run.
244224
*/

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

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

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

227227
expect(
@@ -230,15 +230,15 @@ describe('HasteMap', () => {
230230
});
231231

232232
it('creates different cache file paths for different roots', () => {
233-
jest.resetModuleRegistry();
233+
jest.resetModules();
234234
const HasteMap = require('../');
235235
const hasteMap1 = new HasteMap({...defaultConfig, rootDir: '/root1'});
236236
const hasteMap2 = new HasteMap({...defaultConfig, rootDir: '/root2'});
237237
expect(hasteMap1.getCacheFilePath()).not.toBe(hasteMap2.getCacheFilePath());
238238
});
239239

240240
it('creates different cache file paths for different dependency extractor cache keys', () => {
241-
jest.resetModuleRegistry();
241+
jest.resetModules();
242242
const HasteMap = require('../');
243243
const dependencyExtractor = require('./dependencyExtractor');
244244
const config = {
@@ -253,7 +253,7 @@ describe('HasteMap', () => {
253253
});
254254

255255
it('creates different cache file paths for different hasteImplModulePath cache keys', () => {
256-
jest.resetModuleRegistry();
256+
jest.resetModules();
257257
const HasteMap = require('../');
258258
const hasteImpl = require('./haste_impl');
259259
hasteImpl.setCacheKey('foo');
@@ -264,7 +264,7 @@ describe('HasteMap', () => {
264264
});
265265

266266
it('creates different cache file paths for different projects', () => {
267-
jest.resetModuleRegistry();
267+
jest.resetModules();
268268
const HasteMap = require('../');
269269
const hasteMap1 = new HasteMap({...defaultConfig, name: '@scoped/package'});
270270
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
@@ -234,7 +234,7 @@ describe('Runtime requireModule', () => {
234234
automock: true,
235235
}).then(runtime => {
236236
const root = runtime.requireModule(runtime.__mockRootPath, './root.js');
237-
root.jest.resetModuleRegistry();
237+
root.jest.resetModules();
238238
root.jest.unmock('ManuallyMocked');
239239
const exports = runtime.requireModule(
240240
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
@@ -1423,8 +1423,6 @@ class Runtime {
14231423
};
14241424

14251425
const jestObject: Jest = {
1426-
addMatchers: (matchers: Record<string, any>) =>
1427-
this._environment.global.jasmine.addMatchers(matchers),
14281426
advanceTimersByTime: (msToRun: number) =>
14291427
_getFakeTimers().advanceTimersByTime(msToRun),
14301428
advanceTimersToNextTimer: (steps?: number) =>
@@ -1448,16 +1446,13 @@ class Runtime {
14481446
requireActual: localRequire.requireActual,
14491447
requireMock: localRequire.requireMock,
14501448
resetAllMocks,
1451-
resetModuleRegistry: resetModules,
14521449
resetModules,
14531450
restoreAllMocks,
14541451
retryTimes,
14551452
runAllImmediates: () => _getFakeTimers().runAllImmediates(),
14561453
runAllTicks: () => _getFakeTimers().runAllTicks(),
14571454
runAllTimers: () => _getFakeTimers().runAllTimers(),
14581455
runOnlyPendingTimers: () => _getFakeTimers().runOnlyPendingTimers(),
1459-
runTimersToTime: (msToRun: number) =>
1460-
_getFakeTimers().advanceTimersByTime(msToRun),
14611456
setMock: (moduleName: string, mock: unknown) =>
14621457
setMockFactory(moduleName, () => mock),
14631458
setTimeout,

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

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

580580
// Cache the state in `mockFsCopy`
581581
const mockFsCopy = mockFs;
582-
jest.resetModuleRegistry();
582+
jest.resetModules();
583583
reset();
584584

585585
// Restore the cached fs
@@ -593,7 +593,7 @@ describe('ScriptTransformer', () => {
593593
expect(writeFileAtomic.sync).not.toBeCalled();
594594

595595
// Don't read from the cache when `config.cache` is false.
596-
jest.resetModuleRegistry();
596+
jest.resetModules();
597597
reset();
598598
mockFs = mockFsCopy;
599599
transformConfig.cache = false;
@@ -620,7 +620,7 @@ describe('ScriptTransformer', () => {
620620

621621
// Cache the state in `mockFsCopy`
622622
const mockFsCopy = mockFs;
623-
jest.resetModuleRegistry();
623+
jest.resetModules();
624624
reset();
625625

626626
// Restore the cached fs

0 commit comments

Comments
 (0)