Sinon: Breaking change in 10.0.1: config.target is no longer supported

Created on 8 Apr 2021  路  9Comments  路  Source: sinonjs/sinon

Describe the bug
With [email protected], if options contains target, sinon.useFakeTimers throws a TypeError. This did not occur with [email protected].

To Reproduce

Create index.js with the following content:

const sinon = require('sinon');
sinon.useFakeTimers({ target: { Date } });

Run node index.js after npm install [email protected] and after npm install [email protected]. After installing [email protected] the following error is printed:

/path/to/node_modules/@sinonjs/fake-timers/src/fake-timers-src.js:1299
            throw new TypeError(
            ^

TypeError: config.target is no longer supported. Use `withGlobal(target)` instead.
    at Object.install (/path/to/node_modules/@sinonjs/fake-timers/src/fake-timers-src.js:1299:19)
    at createClock (/path/to/node_modules/sinon/lib/sinon/util/fake-timers.js:12:31)
    at exports.useFakeTimers (/path/to/node_modules/sinon/lib/sinon/util/fake-timers.js:54:16)
    at Sandbox.useFakeTimers (/path/to/node_modules/sinon/lib/sinon/sandbox.js:396:46)
    at Object.<anonymous> (/path/to/index.js:2:7)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)

Expected behavior
No exception would occur.

Additional context
The problem was introduced by f838d783 which bumped @sinonjs/fake-timers from ^6.0.1 to ^7.0.4 which includes sinonjs/fake-timers#318.

Most helpful comment

I have a problem with [email protected]_ and _typescript_ which is surely related to this issue.

To reproduce, create _index.js_ with the following content:

const sinon = require("sinon");

And execute:

npm install [email protected]
npm install @types/[email protected]
npm install [email protected]
npx tsc index.js --declaration --allowJs --emitDeclarationOnly

The result is:

node_modules/@types/sinon/index.d.ts:778:36 - error TS2694: Namespace '"/tmp/testcase/node_modules/@sinonjs/fake-timers/types/fake-timers-src"' has no exported member 'TimerId'.

778     type SinonTimerId = FakeTimers.TimerId;
                                       ~~~~~~~

node_modules/@types/sinon/index.d.ts:780:39 - error TS2694: Namespace '"/tmp/testcase/node_modules/@sinonjs/fake-timers/types/fake-timers-src"' has no exported member 'InstalledMethods'.

780     type SinonFakeTimers = FakeTimers.InstalledMethods &
                                          ~~~~~~~~~~~~~~~~

node_modules/@types/sinon/index.d.ts:781:20 - error TS2694: Namespace '"/tmp/testcase/node_modules/@sinonjs/fake-timers/types/fake-timers-src"' has no exported member 'NodeClock'.

781         FakeTimers.NodeClock &
                       ~~~~~~~~~

node_modules/@types/sinon/index.d.ts:782:20 - error TS2694: Namespace '"/tmp/testcase/node_modules/@sinonjs/fake-timers/types/fake-timers-src"' has no exported member 'BrowserClock'.

782         FakeTimers.BrowserClock & {
                       ~~~~~~~~~~~~


Found 4 errors.

All 9 comments

I have a problem with [email protected]_ and _typescript_ which is surely related to this issue.

To reproduce, create _index.js_ with the following content:

const sinon = require("sinon");

And execute:

npm install [email protected]
npm install @types/[email protected]
npm install [email protected]
npx tsc index.js --declaration --allowJs --emitDeclarationOnly

The result is:

node_modules/@types/sinon/index.d.ts:778:36 - error TS2694: Namespace '"/tmp/testcase/node_modules/@sinonjs/fake-timers/types/fake-timers-src"' has no exported member 'TimerId'.

778     type SinonTimerId = FakeTimers.TimerId;
                                       ~~~~~~~

node_modules/@types/sinon/index.d.ts:780:39 - error TS2694: Namespace '"/tmp/testcase/node_modules/@sinonjs/fake-timers/types/fake-timers-src"' has no exported member 'InstalledMethods'.

780     type SinonFakeTimers = FakeTimers.InstalledMethods &
                                          ~~~~~~~~~~~~~~~~

node_modules/@types/sinon/index.d.ts:781:20 - error TS2694: Namespace '"/tmp/testcase/node_modules/@sinonjs/fake-timers/types/fake-timers-src"' has no exported member 'NodeClock'.

781         FakeTimers.NodeClock &
                       ~~~~~~~~~

node_modules/@types/sinon/index.d.ts:782:20 - error TS2694: Namespace '"/tmp/testcase/node_modules/@sinonjs/fake-timers/types/fake-timers-src"' has no exported member 'BrowserClock'.

782         FakeTimers.BrowserClock & {
                       ~~~~~~~~~~~~


Found 4 errors.

@regseb ~we don't maintain those typescript bindings, but ship our own~. Ah, sorry, I saw the problem is the fake-timer definitions which we DO maintain. This change needs to be reverted.

Hi thanks for fixing. what's the ETA on this?

We'll pin our version, if it's going to take a few days.

@nicoleczhu pin your version. no one is paid to do this, so it will be when someone does the work to fix and test this manually. that being said, I think this has a high priority, so it will be looked at soon by someone in @sinonjs/sinon-core

@fatso83 I empathize with the _no one is paid to do this argument_, as someone who's sunk countless hours into handling CVEs for injection bugs logged against yargs.

But just wanted to make sure you knew about this feature on npm:

npm dist-tag add [email protected] latest

鈽濓笍 this would get folks unblocked who are broken by 10.0.1, but doesn't require a hard unpublish of 10.0.1.

But just wanted to make sure you knew about this feature on npm:

npm dist-tag add [email protected] latest

鈽濓笍 this would get folks unblocked who are broken by 10.0.1, but doesn't require a hard unpublish of 10.0.1.

Top tip! Thank you @bcoe

Thank you for the very accurate bug report @kevinoid 馃憤

Your analysis is correct: the updated version of @sinonjs/fake-timers does indeed introduce a breaking change.

In the npm registry the 10.0.1 package is deprecated and 10.0.0 is marked as latest, so this should not affect any more users (hat tip @bcoe).

Once #2351 is merged and #2353 is resolved, I'll release a new major version detailing the breaking change in the changelog

@mroderick thank you for getting us unblocked 馃憦

Once #2351 is merged and #2353 is resolved, I'll release a new major version detailing the breaking change in the changelog

@mroderick are we there? I am not sure what is needed to get #2353 resolved. The NPM fix seemed like it resolved the issue and #2351 prevents it, or ...?

Was this page helpful?
0 / 5 - 0 ratings