Skip to content

Commit 2fa34c4

Browse files
authored
fix: remove deprecated functions from the jest object (#9853)
1 parent 3079f29 commit 2fa34c4

File tree

11 files changed

+17
-51
lines changed

11 files changed

+17
-51
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
- `[jest-resolve]` Replace read-pkg-up with escalade package ([#10781](https://github.com/facebook/jest/pull/10781))
1111
- `[jest-runtime]` [**BREAKING**] Do not inject `global` variable into module wrapper ([#10644](https://github.com/facebook/jest/pull/10644))
12-
- `[jest-runtime]` [**BREAKING**] Convert to ESM ([#10325](https://github.com/facebook/jest/pull/10325))
12+
- `[jest-runtime]` [**BREAKING**] remove long-deprecated `jest.addMatchers`, `jest.resetModuleRegistry`, and `jest.runTimersToTime` ([#9853](https://github.com/facebook/jest/pull/9853))
1313
- `[jest-transform]` Show enhanced `SyntaxError` message for all `SyntaxError`s ([#10749](https://github.com/facebook/jest/pull/10749))
1414
- `[jest-transform]` [**BREAKING**] Refactor API to pass an options bag around rather than multiple boolean options ([#10753](https://github.com/facebook/jest/pull/10753))
1515

docs/JestObjectAPI.md

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

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

625621
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
@@ -56,12 +56,6 @@ export type Module = NodeModule;
5656

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

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
@@ -237,7 +237,7 @@ describe('Runtime requireModule', () => {
237237
automock: true,
238238
}).then(runtime => {
239239
const root = runtime.requireModule(runtime.__mockRootPath, './root.js');
240-
root.jest.resetModuleRegistry();
240+
root.jest.resetModules();
241241
root.jest.unmock('ManuallyMocked');
242242
const exports = runtime.requireModule(
243243
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
@@ -1561,8 +1561,6 @@ export default class Runtime {
15611561
};
15621562

15631563
const jestObject: Jest = {
1564-
addMatchers: (matchers: Record<string, unknown>) =>
1565-
this._environment.global.jasmine.addMatchers(matchers),
15661564
advanceTimersByTime: (msToRun: number) =>
15671565
_getFakeTimers().advanceTimersByTime(msToRun),
15681566
advanceTimersToNextTimer: (steps?: number) =>
@@ -1599,7 +1597,6 @@ export default class Runtime {
15991597
requireActual: this.requireActual.bind(this, from),
16001598
requireMock: this.requireMock.bind(this, from),
16011599
resetAllMocks,
1602-
resetModuleRegistry: resetModules,
16031600
resetModules,
16041601
restoreAllMocks,
16051602
retryTimes,
@@ -1617,8 +1614,6 @@ export default class Runtime {
16171614
runAllTicks: () => _getFakeTimers().runAllTicks(),
16181615
runAllTimers: () => _getFakeTimers().runAllTimers(),
16191616
runOnlyPendingTimers: () => _getFakeTimers().runOnlyPendingTimers(),
1620-
runTimersToTime: (msToRun: number) =>
1621-
_getFakeTimers().advanceTimersByTime(msToRun),
16221617
setMock: (moduleName: string, mock: unknown) =>
16231618
setMockFactory(moduleName, () => mock),
16241619
setSystemTime: (now?: number | Date) => {

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

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

694694
// Cache the state in `mockFsCopy`
695695
const mockFsCopy = mockFs;
696-
jest.resetModuleRegistry();
696+
jest.resetModules();
697697
reset();
698698

699699
// Restore the cached fs
@@ -707,7 +707,7 @@ describe('ScriptTransformer', () => {
707707
expect(writeFileAtomic.sync).not.toBeCalled();
708708

709709
// Don't read from the cache when `config.cache` is false.
710-
jest.resetModuleRegistry();
710+
jest.resetModules();
711711
reset();
712712
mockFs = mockFsCopy;
713713
transformConfig.cache = false;
@@ -737,7 +737,7 @@ describe('ScriptTransformer', () => {
737737

738738
// Cache the state in `mockFsCopy`
739739
const mockFsCopy = mockFs;
740-
jest.resetModuleRegistry();
740+
jest.resetModules();
741741
reset();
742742

743743
// Restore the cached fs

0 commit comments

Comments
 (0)