Skip to content

Update the sinon library. - #10499

Open
desrosj wants to merge 2 commits into
WordPress:trunkfrom
desrosj:update/sinon
Open

desrosj wants to merge 2 commits into
WordPress:trunkfrom
desrosj:update/sinon

Conversation

@desrosj

@desrosj desrosj commented Nov 10, 2025 •

Copy link
Copy Markdown
Member

This updates sinon from 16.1.3 to 22.1.0 and removes the sinon-test dependency.

Update sinon to 22.1.0

Sinon 22 ships @sinonjs/fake-timers 15, which fakes the global Intl object when a clock is installed. The faked object cannot be stubbed (Intl.hasOwnProperty is overwritten with a boolean), which breaks the communityEvents.getTimeZone tests that stub Intl.DateTimeFormat.prototype.resolvedOptions(). Intl is now excluded from faking with toNotFake: [ 'Intl' ].

The upgrade also drops nise and its dependencies (just-extend, path-to-regexp, lodash.get, @sinonjs/text-encoding) from the lockfile.

Remove sinon-test

sinon-test was only used to wrap every QUnit test in a sandbox with fake timers. Sinon 20 removed the fake server that sinon-test 3.x enabled by default, and since Sinon 21.1, sinon-test 3.x leaves injected properties such as this.clock on the test context after restoring. Instead of updating to sinon-test 4.0.0, the same behavior is now provided by QUnit's global hooks in tests/qunit/index.html:

QUnit.hooks.beforeEach( function() {
	this.clock = sinon.useFakeTimers( {
		toNotFake: [ 'Intl' ]
	} );
} );

QUnit.hooks.afterEach( function() {
	this.clock.restore();
	sinon.restore();
} );

Behavior changes to be aware of

  • Fake XHR is gone. With Sinon 16, sinon-test faked XMLHttpRequest for every test. Sinon 20 removed the fake server, so that no longer happens with either sinon-test version. The wp.updates tests spy on jQuery.ajax without stubbing it, so those requests are now real.
  • The fake clock covers more of each test. sinon-test only faked timers while the test callback ran (or until a returned promise settled). For assert.async() tests, timers became real again as soon as the callback returned. The global hooks keep timers faked from before a module's beforeEach until after its afterEach, including the asynchronous part of assert.async() tests.
  • Stubs and spies are restored after every test through sinon.restore(), even when a test forgets to restore them.
  • this.stub(), this.spy(), this.mock(), etc. are no longer injected into the test context, and mock expectations are no longer verified automatically. None of the current tests use these.

Testing

npm run grunt qunit:compiled passes locally (713/713 assertions for both index.html and compiled.html) with QUnit 3.0.0.

Trac ticket: https://core.trac.wordpress.org/ticket/64228

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Investigating the Sinon 22 test failures, rebasing, removing sinon-test, running the QUnit suite, and drafting this description. All changes were reviewed by me.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

🤖 Generated with Claude Code

@desrosj desrosj self-assigned this Nov 10, 2025
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sinon 22 includes `@sinonjs/fake-timers` 15, which fakes the global `Intl` object when a clock is installed. The faked object cannot be stubbed because `Intl.hasOwnProperty` is overwritten with a boolean, which breaks the `communityEvents.getTimeZone` tests that stub `Intl.DateTimeFormat.prototype.resolvedOptions()`. Since `sinon-test` installs fake timers for every QUnit test, `Intl` is now excluded from faking through `toNotFake`.
`sinon-test` was only used to wrap every QUnit test in a sandbox with fake timers. Sinon 20 removed the fake server that `sinon-test` also enabled by default, and since Sinon 21.1 `sinon-test` 3.x leaves injected properties on the test context after restoring.

The same behavior is now provided through QUnit's global `beforeEach` and `afterEach` hooks, which install sinon's fake timers as `this.clock` before each test and restore them, along with any stubs and spies, afterward.
@desrosj
desrosj marked this pull request as ready for review November 17, 2026 15:23
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props desrosj.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The dependency update preserves the existing assertions, but removing fake XHR also removes isolation from the plugin/theme update tests.

I compared the same 13 existing tests in a reduced browser runner with a local HTTP server:

  • Base: 38 assertions passed, 10 fake XHRs, zero HTTP POSTs.
  • This head: 38 assertions passed, 10 native HTTP POSTs.
  • This head with a module-scoped Ajax stub: 38 assertions passed, zero POSTs.

With controlled 503 responses, all 10 completion callbacks ran after QUnit finished; nine error paths called addAdminNotice. I did not observe cross-test failures or changed lock/queue values, so this is evidence of lost transport isolation and late callbacks, not a demonstrated intermittent test failure.

Please replace the jQuery.ajax call-through spies in the plugin and theme module setups with stubs returning a fresh pending jQuery.Deferred().promise( { abort: jQuery.noop } ). This preserves their URL/action/slug assertions and the old unanswered-fake-XHR behavior. Keep teardown restoring the stub, then run both full QUnit pages on the final patch. My comparison was a reduced runner, not a full-suite validation.

AI review · gpt-6

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

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

2 participants