From 8ca365e071a0bbe6e04b7252fa2c2695ce017855 Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Thu, 12 Oct 2023 16:55:36 +0200 Subject: [PATCH] Make Prettier happy --- README.md | 2 +- .../fake-clock-integration-test.js | 2 +- src/fake-timers-src.js | 64 +++++----- test/fake-timers-test.js | 110 +++++++++--------- 4 files changed, 89 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index be5994c8..6bdcb920 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ var clock = FakeTimers.createClock(); clock.setTimeout(function () { console.log( - "The poblano is a mild chili pepper originating in the state of Puebla, Mexico." + "The poblano is a mild chili pepper originating in the state of Puebla, Mexico.", ); }, 15); diff --git a/integration-test/fake-clock-integration-test.js b/integration-test/fake-clock-integration-test.js index 3c75a565..4964b133 100644 --- a/integration-test/fake-clock-integration-test.js +++ b/integration-test/fake-clock-integration-test.js @@ -76,7 +76,7 @@ describe("globally configured browser objects", function () { const srcDescriptors = Object.getOwnPropertyDescriptors(src); Object.keys(srcDescriptors).forEach((key) => // This is required to make it possible to remove/delete them afterwards - makeMutable(srcDescriptors[key]) + makeMutable(srcDescriptors[key]), ); Object.defineProperties(target, { ...srcDescriptors, diff --git a/src/fake-timers-src.js b/src/fake-timers-src.js index 11b587d2..7691504a 100644 --- a/src/fake-timers-src.js +++ b/src/fake-timers-src.js @@ -244,7 +244,7 @@ function withGlobal(_global) { if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) { throw new Error( - "tick only understands numbers, 'm:s' and 'h:m:s'. Each part must be two digits" + "tick only understands numbers, 'm:s' and 'h:m:s'. Each part must be two digits", ); } @@ -313,7 +313,7 @@ function withGlobal(_global) { */ function getInfiniteLoopError(clock, job) { const infiniteLoopError = new Error( - `Aborting after running ${clock.loopLimit} timers, assuming an infinite loop!` + `Aborting after running ${clock.loopLimit} timers, assuming an infinite loop!`, ); if (!job.error) { @@ -323,13 +323,13 @@ function withGlobal(_global) { // pattern never matched in Node const computedTargetPattern = /target\.*[<|(|[].*?[>|\]|)]\s*/; let clockMethodPattern = new RegExp( - String(Object.keys(clock).join("|")) + String(Object.keys(clock).join("|")), ); if (addTimerReturnsObject) { // node.js environment clockMethodPattern = new RegExp( - `\\s+at (Object\\.)?(?:${Object.keys(clock).join("|")})\\s+` + `\\s+at (Object\\.)?(?:${Object.keys(clock).join("|")})\\s+`, ); } @@ -463,7 +463,7 @@ function withGlobal(_global) { date, hour, minute, - second + second, ); default: return new NativeDate( @@ -473,7 +473,7 @@ function withGlobal(_global) { hour, minute, second, - ms + ms, ); } } @@ -497,7 +497,7 @@ function withGlobal(_global) { * to do a bit of work to get them out. */ Object.getOwnPropertyNames(NativeIntl).forEach( - (property) => (ClockIntl[property] = NativeIntl[property]) + (property) => (ClockIntl[property] = NativeIntl[property]), ); ClockIntl.DateTimeFormat = function (...args) { @@ -508,7 +508,7 @@ function withGlobal(_global) { (method) => { formatter[method] = realFormatter[method].bind(realFormatter); - } + }, ); ["format", "formatToParts"].forEach((method) => { @@ -521,7 +521,7 @@ function withGlobal(_global) { }; ClockIntl.DateTimeFormat.prototype = Object.create( - NativeIntl.DateTimeFormat.prototype + NativeIntl.DateTimeFormat.prototype, ); ClockIntl.DateTimeFormat.supportedLocalesOf = @@ -574,7 +574,7 @@ function withGlobal(_global) { throw new TypeError( `[ERR_INVALID_CALLBACK]: Callback must be a function. Received ${ timer.func - } of type ${typeof timer.func}` + } of type ${typeof timer.func}`, ); } } @@ -857,7 +857,7 @@ function withGlobal(_global) { } warnOnce( `FakeTimers: ${handlerName} was invoked to clear a native timer instead of one created by this library.` + - "\nTo automatically clean-up native timers, use `shouldClearNativeTimers`." + "\nTo automatically clean-up native timers, use `shouldClearNativeTimers`.", ); } @@ -874,7 +874,7 @@ function withGlobal(_global) { const clear = getClearHandler(ttype); const schedule = getScheduleHandler(timer.type); throw new Error( - `Cannot clear timer: timer created with ${schedule}() but cleared with ${clear}()` + `Cannot clear timer: timer created with ${schedule}() but cleared with ${clear}()`, ); } } @@ -899,7 +899,7 @@ function withGlobal(_global) { } else if (method === "performance") { const originalPerfDescriptor = Object.getOwnPropertyDescriptor( clock, - `_${method}` + `_${method}`, ); if ( originalPerfDescriptor && @@ -909,7 +909,7 @@ function withGlobal(_global) { Object.defineProperty( _global, method, - originalPerfDescriptor + originalPerfDescriptor, ); } else if (originalPerfDescriptor.configurable) { _global[method] = clock[`_${method}`]; @@ -957,7 +957,7 @@ function withGlobal(_global) { function hijackMethod(target, method, clock) { clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call( target, - method + method, ); clock[`_${method}`] = target[method]; @@ -969,7 +969,7 @@ function withGlobal(_global) { } else if (method === "performance") { const originalPerfDescriptor = Object.getOwnPropertyDescriptor( target, - method + method, ); // JSDOM has a read only performance field so we have to save/copy it differently if ( @@ -980,12 +980,12 @@ function withGlobal(_global) { Object.defineProperty( clock, `_${method}`, - originalPerfDescriptor + originalPerfDescriptor, ); const perfDescriptor = Object.getOwnPropertyDescriptor( clock, - method + method, ); Object.defineProperty(target, method, perfDescriptor); } else { @@ -998,7 +998,7 @@ function withGlobal(_global) { Object.defineProperties( target[method], - Object.getOwnPropertyDescriptors(clock[method]) + Object.getOwnPropertyDescriptors(clock[method]), ); } @@ -1101,7 +1101,7 @@ function withGlobal(_global) { if (NativeDate === undefined) { throw new Error( "The global scope doesn't have a `Date` object" + - " (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780)" + " (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780)", ); } @@ -1130,7 +1130,7 @@ function withGlobal(_global) { if (Array.isArray(prev)) { if (prev[1] > 1e9) { throw new TypeError( - "Number of nanoseconds can't exceed a billion" + "Number of nanoseconds can't exceed a billion", ); } @@ -1179,7 +1179,7 @@ function withGlobal(_global) { clock.requestIdleCallback = function requestIdleCallback( func, - timeout + timeout, ) { let timeToNextIdlePeriod = 0; @@ -1215,7 +1215,7 @@ function withGlobal(_global) { clock.setTimeout[utilPromisify.custom] = function promisifiedSetTimeout(timeout, arg) { return new _global.Promise(function setTimeoutExecutor( - resolve + resolve, ) { addTimer(clock, { func: resolve, @@ -1276,7 +1276,7 @@ function withGlobal(_global) { args: [arg], immediate: true, }); - } + }, ); }; } @@ -1587,7 +1587,7 @@ function withGlobal(_global) { } numTimers = Object.keys( - clock.timers + clock.timers, ).length; if (numTimers === 0) { resetIsNearInfiniteLimit(); @@ -1720,8 +1720,8 @@ function withGlobal(_global) { ) { throw new TypeError( `FakeTimers.install called with ${String( - config - )} install requires an object parameter` + config, + )} install requires an object parameter`, ); } @@ -1729,7 +1729,7 @@ function withGlobal(_global) { // Timers are already faked; this is a problem. // Make the user reset timers before continuing. throw new TypeError( - "Can't install fake timers twice on the same global object." + "Can't install fake timers twice on the same global object.", ); } @@ -1742,7 +1742,7 @@ function withGlobal(_global) { if (config.target) { throw new TypeError( - "config.target is no longer supported. Use `withGlobal(target)` instead." + "config.target is no longer supported. Use `withGlobal(target)` instead.", ); } @@ -1767,11 +1767,11 @@ function withGlobal(_global) { const intervalTick = doIntervalTick.bind( null, clock, - config.advanceTimeDelta + config.advanceTimeDelta, ); const intervalId = _global.setInterval( intervalTick, - config.advanceTimeDelta + config.advanceTimeDelta, ); clock.attachedInterval = intervalId; } @@ -1797,7 +1797,7 @@ function withGlobal(_global) { } else if ((config.toFake || []).includes("performance")) { // user explicitly tried to fake performance when not present throw new ReferenceError( - "non-existent performance object cannot be faked" + "non-existent performance object cannot be faked", ); } } diff --git a/test/fake-timers-test.js b/test/fake-timers-test.js index b71a1a08..6ed62f16 100644 --- a/test/fake-timers-test.js +++ b/test/fake-timers-test.js @@ -293,7 +293,7 @@ describe("FakeTimers", function () { }.bind(this), { message: `[ERR_INVALID_CALLBACK]: Callback must be a function. Received ${notTypeofFunction} of type ${typeof notTypeofFunction}`, - } + }, ); }); }); @@ -321,7 +321,7 @@ describe("FakeTimers", function () { utilPromisify(this.clock.setTimeout)( 100, "the first", - "the second" + "the second", ).then(function (value) { resolvedValue = value; }); @@ -435,7 +435,7 @@ describe("FakeTimers", function () { let resolvedValue; utilPromisify(this.clock.setImmediate)( "the first", - "the second" + "the second", ).then(function (value) { resolvedValue = value; }); @@ -477,7 +477,7 @@ describe("FakeTimers", function () { { message: "Cannot clear timer: timer created with setTimeout() but cleared with clearImmediate()", - } + }, ); this.clock.tick(55); @@ -495,7 +495,7 @@ describe("FakeTimers", function () { { message: "Cannot clear timer: timer created with setInterval() but cleared with clearImmediate()", - } + }, ); this.clock.tick(55); @@ -941,7 +941,7 @@ describe("FakeTimers", function () { function () { clock.tick(-500); }, - { message: "Negative ticks are not supported" } + { message: "Negative ticks are not supported" }, ); }); }); @@ -2691,7 +2691,7 @@ describe("FakeTimers", function () { assert.isTrue(spies[0].called); assert.isFalse(spies[1].called); }); - } + }, ); it("new timers added with a call time ealier than the last existing timer are run", function () { @@ -2741,7 +2741,7 @@ describe("FakeTimers", function () { assert.isTrue(spies[1].called); assert.isTrue(spies[2].called); }); - } + }, ); it("new timers cannot cause an infinite loop", function () { @@ -2883,7 +2883,7 @@ describe("FakeTimers", function () { { message: "Cannot clear timer: timer created with setImmediate() but cleared with clearTimeout()", - } + }, ); this.clock.tick(50); @@ -3069,7 +3069,7 @@ describe("FakeTimers", function () { { message: "Cannot clear timer: timer created with setImmediate() but cleared with clearInterval()", - } + }, ); this.clock.tick(50); @@ -3118,7 +3118,7 @@ describe("FakeTimers", function () { assert.same( date.constructor.prototype, - realDate.constructor.prototype + realDate.constructor.prototype, ); }); @@ -3167,7 +3167,7 @@ describe("FakeTimers", function () { it("creates regular date when passing a date as RFC 2822 string", function () { const date = new Date("Sat Apr 12 2014 12:22:00 GMT+1000"); const fakeDate = new this.clock.Date( - "Sat Apr 12 2014 12:22:00 GMT+1000" + "Sat Apr 12 2014 12:22:00 GMT+1000", ); assert.equals(fakeDate.getTime(), date.getTime()); @@ -3268,7 +3268,7 @@ describe("FakeTimers", function () { it("mirrors toUTCString method", function () { assert.same( this.clock.Date.prototype.toUTCString, - Date.prototype.toUTCString + Date.prototype.toUTCString, ); }); @@ -3513,7 +3513,7 @@ describe("FakeTimers", function () { { name: "ReferenceError", message: "non-existent performance object cannot be faked", - } + }, ); }); @@ -3625,7 +3625,7 @@ describe("FakeTimers", function () { Object.defineProperty( Performance.prototype, key, - backupDescriptors[key] + backupDescriptors[key], ); }); }); @@ -3890,7 +3890,7 @@ describe("FakeTimers", function () { } const timer = globalObject.setImmediate( - createCallback(done, false) + createCallback(done, false), ); globalObject.setImmediate(createCallback(done, true)); this.clock = FakeTimers.install({ shouldClearNativeTimers: true }); @@ -3903,7 +3903,7 @@ describe("FakeTimers", function () { } const timer = globalObject.requestAnimationFrame( - createCallback(done, false) + createCallback(done, false), ); globalObject.requestAnimationFrame(createCallback(done, true)); this.clock = FakeTimers.install({ shouldClearNativeTimers: true }); @@ -3916,7 +3916,7 @@ describe("FakeTimers", function () { } const timer = globalObject.requestIdleCallback( - createCallback(done, false) + createCallback(done, false), ); globalObject.requestIdleCallback(createCallback(done, true)); this.clock = FakeTimers.install({ shouldClearNativeTimers: true }); @@ -4065,7 +4065,7 @@ describe("FakeTimers", function () { { message: "Cannot clear timer: timer created with setTimeout() but cleared with cancelAnimationFrame()", - } + }, ); this.clock.tick(50); @@ -4082,7 +4082,7 @@ describe("FakeTimers", function () { { message: "Cannot clear timer: timer created with setInterval() but cleared with cancelAnimationFrame()", - } + }, ); this.clock.tick(50); @@ -4103,7 +4103,7 @@ describe("FakeTimers", function () { { message: "Cannot clear timer: timer created with setImmediate() but cleared with cancelAnimationFrame()", - } + }, ); this.clock.tick(50); @@ -4738,7 +4738,7 @@ describe("FakeTimers", function () { it("should install all timers", function () { const toFake = getIntersection( Object.getOwnPropertyNames(timersModule), - Object.getOwnPropertyNames(FakeTimers.timers) + Object.getOwnPropertyNames(FakeTimers.timers), ); const originals = getOriginals(toFake); @@ -4752,7 +4752,7 @@ describe("FakeTimers", function () { it("should uninstall all timers", function () { const toFake = getIntersection( Object.getOwnPropertyNames(timersModule), - Object.getOwnPropertyNames(FakeTimers.timers) + Object.getOwnPropertyNames(FakeTimers.timers), ); const originals = getOriginals(toFake); @@ -4860,9 +4860,9 @@ describe("loop limit stack trace", function () { assert.equals(err.message, expectedMessage); assert.equals( new RegExp( - `Error: ${expectedMessage}\\s+Microtask - recursiveQueueMicroTask\\s+(at )*recursiveQueueMicroTask` + `Error: ${expectedMessage}\\s+Microtask - recursiveQueueMicroTask\\s+(at )*recursiveQueueMicroTask`, ).test(err.stack), - true + true, ); } assert.equals(caughtError, true); @@ -4888,9 +4888,9 @@ describe("loop limit stack trace", function () { assert.equals(err.message, expectedMessage); assert.equals( new RegExp( - `Error: ${expectedMessage}\\s+Microtask - recursiveQueueMicroTask\\s+(at )*recursiveQueueMicroTask` + `Error: ${expectedMessage}\\s+Microtask - recursiveQueueMicroTask\\s+(at )*recursiveQueueMicroTask`, ).test(err.stack), - true + true, ); } assert.equals(caughtError, true); @@ -4920,9 +4920,9 @@ describe("loop limit stack trace", function () { assert.equals(err.message, expectedMessage); assert.equals( new RegExp( - `Error: ${expectedMessage}\\s+Timeout - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer` + `Error: ${expectedMessage}\\s+Timeout - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer`, ).test(err.stack), - true + true, ); }); }); @@ -4937,9 +4937,9 @@ describe("loop limit stack trace", function () { assert.equals(err.message, expectedMessage); assert.equals( new RegExp( - `Error: ${expectedMessage}\\s+Timeout - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer` + `Error: ${expectedMessage}\\s+Timeout - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer`, ).test(err.stack), - true + true, ); } assert.equals(caughtError, true); @@ -4953,7 +4953,7 @@ describe("loop limit stack trace", function () { function recursiveCreateTimerTimeout() { recursiveCreateTimer(); }, - 10 + 10, ); } @@ -4972,9 +4972,9 @@ describe("loop limit stack trace", function () { assert.equals(err.message, expectedMessage); assert.equals( new RegExp( - `Error: ${expectedMessage}\\s+IdleCallback - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer` + `Error: ${expectedMessage}\\s+IdleCallback - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer`, ).test(err.stack), - true + true, ); }); }); @@ -4989,9 +4989,9 @@ describe("loop limit stack trace", function () { assert.equals(err.message, expectedMessage); assert.equals( new RegExp( - `Error: ${expectedMessage}\\s+IdleCallback - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer` + `Error: ${expectedMessage}\\s+IdleCallback - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer`, ).test(err.stack), - true + true, ); } assert.equals(caughtError, true); @@ -5021,9 +5021,9 @@ describe("loop limit stack trace", function () { assert.equals(err.message, expectedMessage); assert.equals( new RegExp( - `Error: ${expectedMessage}\\s+Interval - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer` + `Error: ${expectedMessage}\\s+Interval - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer`, ).test(err.stack), - true + true, ); }); }); @@ -5038,9 +5038,9 @@ describe("loop limit stack trace", function () { assert.equals(err.message, expectedMessage); assert.equals( new RegExp( - `Error: ${expectedMessage}\\s+Interval - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer` + `Error: ${expectedMessage}\\s+Interval - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer`, ).test(err.stack), - true + true, ); } assert.equals(caughtError, true); @@ -5076,9 +5076,9 @@ describe("loop limit stack trace", function () { assert.equals(err.message, expectedMessage); assert.equals( new RegExp( - `Error: ${expectedMessage}\\s+Immediate - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer` + `Error: ${expectedMessage}\\s+Immediate - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer`, ).test(err.stack), - true + true, ); }); }); @@ -5093,9 +5093,9 @@ describe("loop limit stack trace", function () { assert.equals(err.message, expectedMessage); assert.equals( new RegExp( - `Error: ${expectedMessage}\\s+Immediate - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer` + `Error: ${expectedMessage}\\s+Immediate - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer`, ).test(err.stack), - true + true, ); } assert.equals(caughtError, true); @@ -5108,7 +5108,7 @@ describe("loop limit stack trace", function () { test.clock.requestAnimationFrame( function recursiveCreateTimerTimeout() { recursiveCreateTimer(); - } + }, ); } @@ -5127,9 +5127,9 @@ describe("loop limit stack trace", function () { assert.equals(err.message, expectedMessage); assert.equals( new RegExp( - `Error: ${expectedMessage}\\s+AnimationFrame - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer` + `Error: ${expectedMessage}\\s+AnimationFrame - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer`, ).test(err.stack), - true + true, ); }); }); @@ -5144,9 +5144,9 @@ describe("loop limit stack trace", function () { assert.equals(err.message, expectedMessage); assert.equals( new RegExp( - `Error: ${expectedMessage}\\s+AnimationFrame - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer` + `Error: ${expectedMessage}\\s+AnimationFrame - recursiveCreateTimerTimeout\\s+(at )*recursiveCreateTimer`, ).test(err.stack), - true + true, ); } assert.equals(caughtError, true); @@ -5244,7 +5244,7 @@ describe("Intl API", function () { }; assert.equals( new Intl.DateTimeFormat("en-GB", options).formatRange(start, end), - "00:00–00:01" + "00:00–00:01", ); }); @@ -5260,7 +5260,7 @@ describe("Intl API", function () { assert.equals( new Intl.DateTimeFormat("en-GB", options).formatRangeToParts( start, - end + end, ), [ { type: "hour", value: "00", source: "startRange" }, @@ -5270,7 +5270,7 @@ describe("Intl API", function () { { type: "hour", value: "00", source: "endRange" }, { type: "literal", value: ":", source: "endRange" }, { type: "minute", value: "01", source: "endRange" }, - ] + ], ); }); @@ -5292,14 +5292,14 @@ describe("Intl API", function () { hourCycle: "h23", hour: "2-digit", minute: "2-digit", - } + }, ); }); it("formatToParts via isFirstOfMonth -> Returns true when passed a timestamp argument that is first of the month", function () { // June 1 04:00 UTC - Toronto is June 1 00:00 assert.isTrue( - isFirstOfMonth("America/Toronto", Date.UTC(2022, 5, 1, 4)) + isFirstOfMonth("America/Toronto", Date.UTC(2022, 5, 1, 4)), ); }); @@ -5324,7 +5324,7 @@ describe("Intl API", function () { assert.equals( Intl.DateTimeFormat.supportedLocalesOf(), //eslint-disable-next-line no-underscore-dangle - clock._Intl.DateTimeFormat.supportedLocalesOf() + clock._Intl.DateTimeFormat.supportedLocalesOf(), ); });