Skip to content

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

@kevinoid

Description

@kevinoid

Describe the bug
With sinon@10.0.1, if options contains target, sinon.useFakeTimers throws a TypeError. This did not occur with sinon@10.0.0.

To Reproduce

Create index.js with the following content:

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

Run node index.js after npm install sinon@10.0.0 and after npm install sinon@10.0.1. After installing sinon@10.0.1 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 f838d78 which bumped @sinonjs/fake-timers from ^6.0.1 to ^7.0.4 which includes sinonjs/fake-timers#318.

Activity

regseb

regseb commented on Apr 8, 2021

@regseb

I have a problem with sinon@10.0.1 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 sinon@10.0.1
npm install @types/sinon@9.0.11
npm install typescript@4.2.4
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.
fatso83

fatso83 commented on Apr 8, 2021

@fatso83
Contributor

@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.

freelerobot

freelerobot commented on Apr 8, 2021

@freelerobot

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

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

fatso83

fatso83 commented on Apr 9, 2021

@fatso83
Contributor

@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

bcoe

bcoe commented on Apr 9, 2021

@bcoe

@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 sinon@10.0.0 latest

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

added a commit that references this issue on Apr 9, 2021

15 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mroderick@bcoe@kevinoid@fatso83@regseb

        Issue actions

          Breaking change in 10.0.1: config.target is no longer supported · Issue #2352 · sinonjs/sinon