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 Nov 4, 2020
1 parent 30b6cee commit 86da663
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@

### Fixes

- `[jest-runtime]` [**BREAKING**] remove long-deprecated `jest.addMatchers`, `jest.resetModuleRegistry`, and `jest.runTimersToTime` ([#9853](https://github.com/facebook/jest/pull/9853))
- `[jest-transform]` Show enhanced `SyntaxError` message for all `SyntaxError`s ([#10749](https://github.com/facebook/jest/pull/10749))

### Chore & Maintenance
Expand Down
4 changes: 0 additions & 4 deletions docs/JestObjectAPI.md
Expand Up @@ -616,10 +616,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
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
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, unknown>): 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 @@ -184,13 +178,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 @@ -238,13 +225,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
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
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
Expand Up @@ -237,7 +237,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
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
Expand Up @@ -1566,8 +1566,6 @@ class Runtime {
};

const jestObject: Jest = {
addMatchers: (matchers: Record<string, unknown>) =>
this._environment.global.jasmine.addMatchers(matchers),
advanceTimersByTime: (msToRun: number) =>
_getFakeTimers().advanceTimersByTime(msToRun),
advanceTimersToNextTimer: (steps?: number) =>
Expand Down Expand Up @@ -1604,7 +1602,6 @@ class Runtime {
requireActual: this.requireActual.bind(this, from),
requireMock: this.requireMock.bind(this, from),
resetAllMocks,
resetModuleRegistry: resetModules,
resetModules,
restoreAllMocks,
retryTimes,
Expand All @@ -1622,8 +1619,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
Expand Up @@ -693,7 +693,7 @@ describe('ScriptTransformer', () => {

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

// Restore the cached fs
Expand All @@ -707,7 +707,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 Down Expand Up @@ -737,7 +737,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 86da663

Please sign in to comment.