From e2f541b0b099933b0fae268e587430e541c5588c Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 3 May 2020 16:24:09 +0200 Subject: [PATCH] chore: rename LolexFakeTimers to ModernFakeTimers --- CHANGELOG.md | 7 ++++--- .../src/__tests__/jsdom_environment.test.ts | 4 ++-- packages/jest-environment-jsdom/src/index.ts | 15 ++++++--------- .../src/__tests__/node_environment.test.ts | 4 ++-- packages/jest-environment-node/src/index.ts | 15 ++++++--------- packages/jest-environment/src/index.ts | 7 ++----- packages/jest-fake-timers/package.json | 8 ++++---- ...t.ts.snap => legacyFakeTimers.test.ts.snap} | 0 ...t.ts.snap => modernFakeTimers.test.ts.snap} | 0 ...Timers.test.ts => legacyFakeTimers.test.ts} | 2 +- ...sLolex.test.ts => modernFakeTimers.test.ts} | 4 ++-- packages/jest-fake-timers/src/index.ts | 4 ++-- .../{jestFakeTimers.ts => legacyFakeTimers.ts} | 0 ...{FakeTimersLolex.ts => modernFakeTimers.ts} | 18 +++++++++--------- yarn.lock | 17 ++++++++++++----- 15 files changed, 52 insertions(+), 53 deletions(-) rename packages/jest-fake-timers/src/__tests__/__snapshots__/{jestFakeTimers.test.ts.snap => legacyFakeTimers.test.ts.snap} (100%) rename packages/jest-fake-timers/src/__tests__/__snapshots__/{fakeTimersLolex.test.ts.snap => modernFakeTimers.test.ts.snap} (100%) rename packages/jest-fake-timers/src/__tests__/{jestFakeTimers.test.ts => legacyFakeTimers.test.ts} (99%) rename packages/jest-fake-timers/src/__tests__/{fakeTimersLolex.test.ts => modernFakeTimers.test.ts} (99%) rename packages/jest-fake-timers/src/{jestFakeTimers.ts => legacyFakeTimers.ts} (100%) rename packages/jest-fake-timers/src/{FakeTimersLolex.ts => modernFakeTimers.ts} (89%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d7baa8b35cb..e1e8071ec11b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) -- `[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` +- `[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 diff --git a/packages/jest-environment-jsdom/src/__tests__/jsdom_environment.test.ts b/packages/jest-environment-jsdom/src/__tests__/jsdom_environment.test.ts index d3b2439ec7a8..528ed5620cbc 100644 --- a/packages/jest-environment-jsdom/src/__tests__/jsdom_environment.test.ts +++ b/packages/jest-environment-jsdom/src/__tests__/jsdom_environment.test.ts @@ -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(); }); }); diff --git a/packages/jest-environment-jsdom/src/index.ts b/packages/jest-environment-jsdom/src/index.ts index 595ba752c56b..fc30e7e50833 100644 --- a/packages/jest-environment-jsdom/src/index.ts +++ b/packages/jest-environment-jsdom/src/index.ts @@ -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'; @@ -28,7 +25,7 @@ type Win = Window & class JSDOMEnvironment implements JestEnvironment { dom: JSDOM | null; fakeTimers: LegacyFakeTimers | null; - fakeTimersLolex: LolexFakeTimers | null; + fakeTimersModern: ModernFakeTimers | null; global: Win; errorEventListener: ((event: Event & {error: Error}) => void) | null; moduleMocker: ModuleMocker | null; @@ -100,7 +97,7 @@ class JSDOMEnvironment implements JestEnvironment { timerConfig, }); - this.fakeTimersLolex = new LolexFakeTimers({config, global}); + this.fakeTimersModern = new ModernFakeTimers({config, global}); } async setup(): Promise {} @@ -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) { @@ -125,7 +122,7 @@ class JSDOMEnvironment implements JestEnvironment { this.global = null; this.dom = null; this.fakeTimers = null; - this.fakeTimersLolex = null; + this.fakeTimersModern = null; } runScript(script: Script): T | null { diff --git a/packages/jest-environment-node/src/__tests__/node_environment.test.ts b/packages/jest-environment-node/src/__tests__/node_environment.test.ts index e43df37a1bf5..0e760db861e4 100644 --- a/packages/jest-environment-node/src/__tests__/node_environment.test.ts +++ b/packages/jest-environment-node/src/__tests__/node_environment.test.ts @@ -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) { diff --git a/packages/jest-environment-node/src/index.ts b/packages/jest-environment-node/src/index.ts index d5faba29e8f6..51a803cc5e9b 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -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 = { @@ -24,7 +21,7 @@ type Timer = { class NodeEnvironment implements JestEnvironment { context: Context | null; fakeTimers: LegacyFakeTimers | null; - fakeTimersLolex: LolexFakeTimers | null; + fakeTimersModern: ModernFakeTimers | null; global: Global.Global; moduleMocker: ModuleMocker | null; @@ -90,7 +87,7 @@ class NodeEnvironment implements JestEnvironment { timerConfig, }); - this.fakeTimersLolex = new LolexFakeTimers({config, global}); + this.fakeTimersModern = new ModernFakeTimers({config, global}); } async setup(): Promise {} @@ -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` diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index f48f1131ac39..df3e0f856bd6 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -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; @@ -41,7 +38,7 @@ export declare class JestEnvironment { constructor(config: Config.ProjectConfig, context?: EnvironmentContext); global: Global.Global; fakeTimers: LegacyFakeTimers | null; - fakeTimersLolex: LolexFakeTimers | null; + fakeTimersModern: ModernFakeTimers | null; moduleMocker: jestMock.ModuleMocker | null; /** * @deprecated implement getVmContext instead diff --git a/packages/jest-fake-timers/package.json b/packages/jest-fake-timers/package.json index aeebf7229c23..6aeb4ef8dab4 100644 --- a/packages/jest-fake-timers/package.json +++ b/packages/jest-fake-timers/package.json @@ -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" diff --git a/packages/jest-fake-timers/src/__tests__/__snapshots__/jestFakeTimers.test.ts.snap b/packages/jest-fake-timers/src/__tests__/__snapshots__/legacyFakeTimers.test.ts.snap similarity index 100% rename from packages/jest-fake-timers/src/__tests__/__snapshots__/jestFakeTimers.test.ts.snap rename to packages/jest-fake-timers/src/__tests__/__snapshots__/legacyFakeTimers.test.ts.snap diff --git a/packages/jest-fake-timers/src/__tests__/__snapshots__/fakeTimersLolex.test.ts.snap b/packages/jest-fake-timers/src/__tests__/__snapshots__/modernFakeTimers.test.ts.snap similarity index 100% rename from packages/jest-fake-timers/src/__tests__/__snapshots__/fakeTimersLolex.test.ts.snap rename to packages/jest-fake-timers/src/__tests__/__snapshots__/modernFakeTimers.test.ts.snap diff --git a/packages/jest-fake-timers/src/__tests__/jestFakeTimers.test.ts b/packages/jest-fake-timers/src/__tests__/legacyFakeTimers.test.ts similarity index 99% rename from packages/jest-fake-timers/src/__tests__/jestFakeTimers.test.ts rename to packages/jest-fake-timers/src/__tests__/legacyFakeTimers.test.ts index 453b28ae83fa..28a335152a11 100644 --- a/packages/jest-fake-timers/src/__tests__/jestFakeTimers.test.ts +++ b/packages/jest-fake-timers/src/__tests__/legacyFakeTimers.test.ts @@ -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, diff --git a/packages/jest-fake-timers/src/__tests__/fakeTimersLolex.test.ts b/packages/jest-fake-timers/src/__tests__/modernFakeTimers.test.ts similarity index 99% rename from packages/jest-fake-timers/src/__tests__/fakeTimersLolex.test.ts rename to packages/jest-fake-timers/src/__tests__/modernFakeTimers.test.ts index bba8df289496..a731c594104c 100644 --- a/packages/jest-fake-timers/src/__tests__/fakeTimersLolex.test.ts +++ b/packages/jest-fake-timers/src/__tests__/modernFakeTimers.test.ts @@ -6,7 +6,7 @@ * */ -import FakeTimers from '../FakeTimersLolex'; +import FakeTimers from '../modernFakeTimers'; describe('FakeTimers', () => { describe('construction', () => { @@ -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(); diff --git a/packages/jest-fake-timers/src/index.ts b/packages/jest-fake-timers/src/index.ts index 295edc2bee29..8e4daf764dda 100644 --- a/packages/jest-fake-timers/src/index.ts +++ b/packages/jest-fake-timers/src/index.ts @@ -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'; diff --git a/packages/jest-fake-timers/src/jestFakeTimers.ts b/packages/jest-fake-timers/src/legacyFakeTimers.ts similarity index 100% rename from packages/jest-fake-timers/src/jestFakeTimers.ts rename to packages/jest-fake-timers/src/legacyFakeTimers.ts diff --git a/packages/jest-fake-timers/src/FakeTimersLolex.ts b/packages/jest-fake-timers/src/modernFakeTimers.ts similarity index 89% rename from packages/jest-fake-timers/src/FakeTimersLolex.ts rename to packages/jest-fake-timers/src/modernFakeTimers.ts index 56a767f4cab5..b0cd8c479a65 100644 --- a/packages/jest-fake-timers/src/FakeTimersLolex.ts +++ b/packages/jest-fake-timers/src/modernFakeTimers.ts @@ -6,10 +6,10 @@ */ 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 { @@ -17,7 +17,7 @@ export default class FakeTimers { private _config: StackTraceConfig; private _fakingTime: boolean; private _global: NodeJS.Global; - private _lolex: LolexWithContext; + private _fakeTimers: FakeTimerWithContext; private _maxLoops: number; constructor({ @@ -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 { @@ -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) { @@ -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, diff --git a/yarn.lock b/yarn.lock index abaad9b68bd8..b01763533183 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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"