Skip to content

Commit

Permalink
fix: remove deprecated funtions from the jest object
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Aug 23, 2020
1 parent 7e5e27a commit 29d8f94
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 47 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Chore & Maintenance

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

### Performance

## 26.4.2
Expand Down
4 changes: 0 additions & 4 deletions docs/JestObjectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,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.
Expand Down
2 changes: 0 additions & 2 deletions docs/TimerMocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions packages/jest-environment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,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<string, any>): 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.
Expand Down Expand Up @@ -182,13 +176,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.
Expand Down Expand Up @@ -236,13 +223,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.
*/
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-haste-map/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ describe('HasteMap', () => {
});

it('creates valid cache file paths', () => {
jest.resetModuleRegistry();
jest.resetModules();
HasteMap = require('../');

expect(
Expand All @@ -237,15 +237,15 @@ 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'});
expect(hasteMap1.getCacheFilePath()).not.toBe(hasteMap2.getCacheFilePath());
});

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 = {
Expand All @@ -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');
Expand All @@ -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'});
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-runtime/src/__tests__/runtime_mock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
Expand All @@ -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'),
);
Expand All @@ -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'),
);
Expand Down
5 changes: 0 additions & 5 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1499,8 +1499,6 @@ class Runtime {
};

const jestObject: Jest = {
addMatchers: (matchers: Record<string, any>) =>
this._environment.global.jasmine.addMatchers(matchers),
advanceTimersByTime: (msToRun: number) =>
_getFakeTimers().advanceTimersByTime(msToRun),
advanceTimersToNextTimer: (steps?: number) =>
Expand Down Expand Up @@ -1537,7 +1535,6 @@ class Runtime {
requireActual: this.requireActual.bind(this, from),
requireMock: this.requireMock.bind(this, from),
resetAllMocks,
resetModuleRegistry: resetModules,
resetModules,
restoreAllMocks,
retryTimes,
Expand All @@ -1555,8 +1552,6 @@ 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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ describe('ScriptTransformer', () => {

// Cache the state in `mockFsCopy`
const mockFsCopy = mockFs;
jest.resetModuleRegistry();
jest.resetModules();
reset();

// Restore the cached fs
Expand All @@ -683,7 +683,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;
Expand All @@ -710,7 +710,7 @@ describe('ScriptTransformer', () => {

// Cache the state in `mockFsCopy`
const mockFsCopy = mockFs;
jest.resetModuleRegistry();
jest.resetModules();
reset();

// Restore the cached fs
Expand Down

0 comments on commit 29d8f94

Please sign in to comment.