Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rename LolexFakeTimers to ModernFakeTimers #9960

Merged
merged 1 commit into from
May 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
- `[*]` [**BREAKING**] Drop support for Node 8 ([#9423](https://github.com/facebook/jest/pull/9423))
- `[*]` Upgrade to chalk@4 ([#9752](https://github.com/facebook/jest/pull/9752))
- `[*]` Remove usage of `realpath-native` ([#9952](https://github.com/facebook/jest/pull/9952))
- `[jest-runtime]` [**BREAKING**] Remove long-deprecated `require.requireActual` and `require.requireMock` methods ([#9854](https://github.com/facebook/jest/pull/9854))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new is on line 25, I just sorted the entries

- `[expect, jest-mock, pretty-format]` [**BREAKING**] Remove `build-es5` from package ([#9945](https://github.com/facebook/jest/pull/9945))
- `[jest-haste-map]` [**BREAKING**] removed `providesModuleNodeModules` ([#8535](https://github.com/facebook/jest/pull/8535))
- `[docs]` Fix example reference implementation to use Jest with Phabricator ([#8662](https://github.com/facebook/jest/pull/8662))
- `[docs]` Added default compiler to tranform ([#8583](https://github.com/facebook/jest/pull/8583))
- `[docs]` Updated Testing Frameworks guide with React; make it generic ([#9106](https://github.com/facebook/jest/pull/9106))
- `[expect, jest-mock, pretty-format]` [**BREAKING**] Remove `build-es5` from package ([#9945](https://github.com/facebook/jest/pull/9945))
- `[@jest/fake-timers, @jest/environment]` [**BREAKING**] Rename `LolexFakeTimers` to `ModernFakeTimers` ([#9960](https://github.com/facebook/jest/pull/9960))
- `[jest-haste-map]` [**BREAKING**] removed `providesModuleNodeModules` ([#8535](https://github.com/facebook/jest/pull/8535))
- `[jest-runtime]` [**BREAKING**] Remove long-deprecated `require.requireActual` and `require.requireMock` methods ([#9854](https://github.com/facebook/jest/pull/9854))

### Performance

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ describe('JSDomEnvironment', () => {
});
});

it('has Lolex fake timers implementation', () => {
it('has modern fake timers implementation', () => {
const env = new JSDomEnvironment(makeProjectConfig());

expect(env.fakeTimersLolex).toBeDefined();
expect(env.fakeTimersModern).toBeDefined();
});
});
15 changes: 6 additions & 9 deletions packages/jest-environment-jsdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import type {Context, Script} from 'vm';
import type {Config, Global} from '@jest/types';
import {installCommonGlobals} from 'jest-util';
import {ModuleMocker} from 'jest-mock';
import {
JestFakeTimers as LegacyFakeTimers,
LolexFakeTimers,
} from '@jest/fake-timers';
import {LegacyFakeTimers, ModernFakeTimers} from '@jest/fake-timers';
import type {EnvironmentContext, JestEnvironment} from '@jest/environment';
import {JSDOM, VirtualConsole} from 'jsdom';

Expand All @@ -28,7 +25,7 @@ type Win = Window &
class JSDOMEnvironment implements JestEnvironment {
dom: JSDOM | null;
fakeTimers: LegacyFakeTimers<number> | null;
fakeTimersLolex: LolexFakeTimers | null;
fakeTimersModern: ModernFakeTimers | null;
global: Win;
errorEventListener: ((event: Event & {error: Error}) => void) | null;
moduleMocker: ModuleMocker | null;
Expand Down Expand Up @@ -100,7 +97,7 @@ class JSDOMEnvironment implements JestEnvironment {
timerConfig,
});

this.fakeTimersLolex = new LolexFakeTimers({config, global});
this.fakeTimersModern = new ModernFakeTimers({config, global});
}

async setup(): Promise<void> {}
Expand All @@ -109,8 +106,8 @@ class JSDOMEnvironment implements JestEnvironment {
if (this.fakeTimers) {
this.fakeTimers.dispose();
}
if (this.fakeTimersLolex) {
this.fakeTimersLolex.dispose();
if (this.fakeTimersModern) {
this.fakeTimersModern.dispose();
}
if (this.global) {
if (this.errorEventListener) {
Expand All @@ -125,7 +122,7 @@ class JSDOMEnvironment implements JestEnvironment {
this.global = null;
this.dom = null;
this.fakeTimers = null;
this.fakeTimersLolex = null;
this.fakeTimersModern = null;
}

runScript<T = unknown>(script: Script): T | null {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ describe('NodeEnvironment', () => {
});
});

it('has Lolex fake timers implementation', () => {
it('has modern fake timers implementation', () => {
const env = new NodeEnvironment(makeProjectConfig());

expect(env.fakeTimersLolex).toBeDefined();
expect(env.fakeTimersModern).toBeDefined();
});

if (isTextEncoderDefined) {
Expand Down
15 changes: 6 additions & 9 deletions packages/jest-environment-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import {Context, Script, createContext, runInContext} from 'vm';
import type {Config, Global} from '@jest/types';
import {ModuleMocker} from 'jest-mock';
import {installCommonGlobals} from 'jest-util';
import {
JestFakeTimers as LegacyFakeTimers,
LolexFakeTimers,
} from '@jest/fake-timers';
import {LegacyFakeTimers, ModernFakeTimers} from '@jest/fake-timers';
import type {JestEnvironment} from '@jest/environment';

type Timer = {
Expand All @@ -24,7 +21,7 @@ type Timer = {
class NodeEnvironment implements JestEnvironment {
context: Context | null;
fakeTimers: LegacyFakeTimers<Timer> | null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could rename this to legacyFakeTimers, not sure it's worth the churn for custom envs, tho?

fakeTimersLolex: LolexFakeTimers | null;
fakeTimersModern: ModernFakeTimers | null;
global: Global.Global;
moduleMocker: ModuleMocker | null;

Expand Down Expand Up @@ -90,7 +87,7 @@ class NodeEnvironment implements JestEnvironment {
timerConfig,
});

this.fakeTimersLolex = new LolexFakeTimers({config, global});
this.fakeTimersModern = new ModernFakeTimers({config, global});
}

async setup(): Promise<void> {}
Expand All @@ -99,12 +96,12 @@ class NodeEnvironment implements JestEnvironment {
if (this.fakeTimers) {
this.fakeTimers.dispose();
}
if (this.fakeTimersLolex) {
this.fakeTimersLolex.dispose();
if (this.fakeTimersModern) {
this.fakeTimersModern.dispose();
}
this.context = null;
this.fakeTimers = null;
this.fakeTimersLolex = null;
this.fakeTimersModern = null;
}

// TS infers the return type to be `any`, since that's what `runInContext`
Expand Down
7 changes: 2 additions & 5 deletions packages/jest-environment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import type {Context, Script} from 'vm';
import type {Circus, Config, Global} from '@jest/types';
import jestMock = require('jest-mock');
import type {
JestFakeTimers as LegacyFakeTimers,
LolexFakeTimers,
} from '@jest/fake-timers';
import type {LegacyFakeTimers, ModernFakeTimers} from '@jest/fake-timers';

type JestMockFn = typeof jestMock.fn;
type JestMockSpyOn = typeof jestMock.spyOn;
Expand Down Expand Up @@ -41,7 +38,7 @@ export declare class JestEnvironment {
constructor(config: Config.ProjectConfig, context?: EnvironmentContext);
global: Global.Global;
fakeTimers: LegacyFakeTimers<unknown> | null;
fakeTimersLolex: LolexFakeTimers | null;
fakeTimersModern: ModernFakeTimers | null;
moduleMocker: jestMock.ModuleMocker | null;
/**
* @deprecated implement getVmContext instead
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-fake-timers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"types": "build/index.d.ts",
"dependencies": {
"@jest/types": "^26.0.0-alpha.0",
"@sinonjs/fake-timers": "^6.0.1",
"jest-message-util": "^26.0.0-alpha.0",
"jest-mock": "^26.0.0-alpha.0",
"jest-util": "^26.0.0-alpha.0",
"lolex": "^5.0.0"
"jest-util": "^26.0.0-alpha.0"
},
"devDependencies": {
"@types/lolex": "^5.1.0",
"@types/node": "*"
"@types/node": "*",
"@types/sinonjs__fake-timers": "^6.0.1"
},
"engines": {
"node": ">= 10.14.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as util from 'util';
import {runInNewContext} from 'vm';
import wrap from 'jest-snapshot-serializer-raw';
import mock = require('jest-mock');
import FakeTimers from '../jestFakeTimers';
import FakeTimers from '../legacyFakeTimers';

const timerConfig = {
idToRef: (id: number) => id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*/

import FakeTimers from '../FakeTimersLolex';
import FakeTimers from '../modernFakeTimers';

describe('FakeTimers', () => {
describe('construction', () => {
Expand Down Expand Up @@ -288,7 +288,7 @@ describe('FakeTimers', () => {
};

const timers = new FakeTimers({global});
// Lolex uses `setTimeout` during init to figure out if it's in Node or
// @sinonjs/fake-timers uses `setTimeout` during init to figure out if it's in Node or
// browser env. So clear its calls before we install them into the env
nativeSetTimeout.mockClear();
timers.useFakeTimers();
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-fake-timers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
* LICENSE file in the root directory of this source tree.
*/

export {default as JestFakeTimers} from './jestFakeTimers';
export {default as LolexFakeTimers} from './FakeTimersLolex';
export {default as LegacyFakeTimers} from './legacyFakeTimers';
export {default as ModernFakeTimers} from './modernFakeTimers';
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
*/

import {
FakeTimerWithContext,
InstalledClock,
LolexWithContext,
withGlobal as lolexWithGlobal,
} from 'lolex';
withGlobal,
} from '@sinonjs/fake-timers';
import {StackTraceConfig, formatStackTrace} from 'jest-message-util';

export default class FakeTimers {
private _clock!: InstalledClock;
private _config: StackTraceConfig;
private _fakingTime: boolean;
private _global: NodeJS.Global;
private _lolex: LolexWithContext;
private _fakeTimers: FakeTimerWithContext;
private _maxLoops: number;

constructor({
Expand All @@ -34,7 +34,7 @@ export default class FakeTimers {
this._maxLoops = maxLoops || 100000;

this._fakingTime = false;
this._lolex = lolexWithGlobal(global);
this._fakeTimers = withGlobal(global);
}

clearAllTimers(): void {
Expand Down Expand Up @@ -63,7 +63,7 @@ export default class FakeTimers {
if (this._checkFakeTimers()) {
for (let i = steps; i > 0; i--) {
this._clock.next();
// Fire all timers at this point: https://github.com/sinonjs/lolex/issues/250
// Fire all timers at this point: https://github.com/sinonjs/fake-timers/issues/250
this._clock.tick(0);

if (this._clock.countTimers() === 0) {
Expand Down Expand Up @@ -95,11 +95,11 @@ export default class FakeTimers {

useFakeTimers(): void {
if (!this._fakingTime) {
const toFake = Object.keys(this._lolex.timers) as Array<
keyof LolexWithContext['timers']
const toFake = Object.keys(this._fakeTimers.timers) as Array<
keyof FakeTimerWithContext['timers']
>;

this._clock = this._lolex.install({
this._clock = this._fakeTimers.install({
loopLimit: this._maxLoops,
now: Date.now(),
target: this._global,
Expand Down
17 changes: 12 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2309,6 +2309,13 @@
dependencies:
type-detect "4.0.8"

"@sinonjs/fake-timers@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-6.0.1.tgz#293674fccb3262ac782c7aadfdeca86b10c75c40"
integrity sha512-MZPUxrmFubI36XS1DI3qmI0YdN1gks62JtFZvxR67ljjSNCeK6U08Zx4msEWOXuofgqUt6zPHSi1H9fbjR/NRA==
dependencies:
"@sinonjs/commons" "^1.7.0"

"@testing-library/dom@^6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-6.0.0.tgz#34e28e69e49bd6347fc64a5dde4c4f9aabbd17d3"
Expand Down Expand Up @@ -2563,11 +2570,6 @@
resolved "https://registry.yarnpkg.com/@types/lockfile/-/lockfile-1.0.1.tgz#434a3455e89843312f01976e010c60f1bcbd56f7"
integrity sha512-65WZedEm4AnOsBDdsapJJG42MhROu3n4aSSiu87JXF/pSdlubxZxp3S1yz3kTfkJ2KBPud4CpjoHVAptOm9Zmw==

"@types/lolex@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@types/lolex/-/lolex-5.1.0.tgz#11b4c4756c007306d0feeaf2f08f88350c635d2b"
integrity sha512-hCQ2dOEQUw1LwofdIpMMGGqENd5p5ANzvcTe1nXTjcQL84r7tcLXFJlBgi0Ggz0f7BLmE2epf0C5Q07iq2gV0g==

"@types/md5-file@^4.0.1":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@types/md5-file/-/md5-file-4.0.1.tgz#5e6cfb7949dc375049b8f6fd8f91adacfc176c63"
Expand Down Expand Up @@ -2709,6 +2711,11 @@
dependencies:
"@types/node" "*"

"@types/sinonjs__fake-timers@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-6.0.1.tgz#681df970358c82836b42f989188d133e218c458e"
integrity sha512-yYezQwGWty8ziyYLdZjwxyMb0CZR49h8JALHGrxjQHWlqGgc8kLdHEgWrgL0uZ29DMvEVBDnHU2Wg36zKSIUtA==

"@types/source-map-support@^0.5.0":
version "0.5.1"
resolved "https://registry.yarnpkg.com/@types/source-map-support/-/source-map-support-0.5.1.tgz#b13e4de5bf2e5858e0dfe33fac90556b0f652dc3"
Expand Down