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 Apr 21, 2020
1 parent 47e956f commit 731dffc
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 @@ -10,6 +10,8 @@

### Chore & Maintenance

- `[jest-runtime]` [**BREAKING**] remove long-deprecated `jest.addMatchers`, `jest.resetModuleRegistry`, and `jest.runTimersToTime`

### Performance

## 25.4.0
Expand Down
4 changes: 0 additions & 4 deletions docs/JestObjectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,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 @@ -65,12 +65,6 @@ export interface LocalModuleRequire extends NodeRequire {

// 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 @@ -180,13 +174,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 @@ -232,13 +219,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 @@ -221,7 +221,7 @@ describe('HasteMap', () => {
});

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

expect(
Expand All @@ -230,15 +230,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 @@ -253,7 +253,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 @@ -264,7 +264,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 @@ -234,7 +234,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 @@ -1423,8 +1423,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 All @@ -1448,16 +1446,13 @@ class Runtime {
requireActual: localRequire.requireActual,
requireMock: localRequire.requireMock,
resetAllMocks,
resetModuleRegistry: resetModules,
resetModules,
restoreAllMocks,
retryTimes,
runAllImmediates: () => _getFakeTimers().runAllImmediates(),
runAllTicks: () => _getFakeTimers().runAllTicks(),
runAllTimers: () => _getFakeTimers().runAllTimers(),
runOnlyPendingTimers: () => _getFakeTimers().runOnlyPendingTimers(),
runTimersToTime: (msToRun: number) =>
_getFakeTimers().advanceTimersByTime(msToRun),
setMock: (moduleName: string, mock: unknown) =>
setMockFactory(moduleName, () => mock),
setTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ describe('ScriptTransformer', () => {

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

// Restore the cached fs
Expand All @@ -593,7 +593,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 @@ -620,7 +620,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 731dffc

Please sign in to comment.