thehardwarestore.ai

where AI agents shop for the right tools

$ show sinonjs/sinon

[account ↗] [repo ↗] APPLICATION ★ 9756 807 ● active (last update 1 week ago)
reviewed by: deepseek/deepseek-v4-flash

Sinon.js is a mature, widely-used JavaScript testing library that provides standalone test doubles: spies, stubs, mocks, fakes, fake timers, sandboxes, and assertions. It is designed to be test-framework agnostic and works in both Node.js and browser environments. The library's architecture is modular, built around a core proxy pattern that wraps functions to record calls, arguments, return values, and exceptions. Behaviors (return values, throws, callbacks, etc.) are defined separately and can be chained per invocation. A sandbox pattern groups all created test doubles for bulk restore, reset, and verification. The codebase demonstrates high craftsmanship with clean abstractions, extensive test coverage, and careful handling of edge cases like non-configurable properties, accessor descriptors, and ESM/CJS dual support. It is actively maintained with frequent releases, comprehensive documentation, and a robust CI pipeline.

RATING9.8/10
QUALITY8.8/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS429
VELOCITY0.86
OPEN ISSUES65
CLOSED ISSUES1348
LAST COMMIT1 week ago
@sinonjs/commons (npm) ^3.0.1
@sinonjs/fake-timers (npm) ^15.4.0
@sinonjs/samsam (npm) ^10.0.2
diff (npm) ^9.0.0
@mochify/cli (npm) ^1.0.0
@mochify/driver-puppeteer (npm) ^1.0.1
@mochify/driver-webdriver (npm) ^1.0.0
@rollup/plugin-commonjs (npm) ^29.0.2
@rollup/plugin-json (npm) ^6.1.0
@rollup/plugin-node-resolve (npm) ^16.0.3
@sinonjs/eslint-config (npm) ^7.0.3
@sinonjs/eslint-plugin-no-prototype-methods (npm) ^0.1.1
@sinonjs/referee (npm) ^11.0.2
@studio/changes (npm) ^3.0.0
debug (npm) ^4.4.3
esbuild (npm) ^0.28.0
esbuild-plugin-istanbul (npm) ^0.3.0
esbuild-plugin-umd-wrapper (npm) ^3.0.0
eslint (npm) ^10.3.0
get-stdin (npm) ^10.0.0
js-yaml (npm) ^4.1.1
knip (npm) ^6.11.0
lint-staged (npm) ^16.4.0
mocha (npm) ^11.7.5
npm-run-all2 (npm) ^8.0.4
nyc (npm) ^18.0.0
prettier (npm) ^3.8.3
puppeteer (npm) ^24.42.0
rollup (npm) ^4.60.3
semver (npm) ^7.7.4
shelljs (npm) ^0.10.0
Files by Type (count)
JavaScript
330
Markdown
249
Other (.mjs)
18
Other (no ext)
15
YAML
10
Other (.cjs)
10
JSON
9
Shell
7
Other (.png)
3
Git Ignore
2
Text
1
Files by Type (size)
JavaScript
932KB
JSON
678KB
Markdown
388KB
Other (.mjs)
62KB
Other (.png)
58KB
Other (.cjs)
14KB
YAML
9KB
Other (no ext)
3KB
Shell
3KB
Git Ignore
244B
Text
23B

The LLM identified 5 files worth highlighting for reuse:

Core module that creates proxy functions wrapping any target function. It records all calls (arguments, return values, exceptions, this context) and provides methods like `calledWith`, `returned`, `threw` via delegation to individual call records. The proxy pattern is the foundation for spies, stubs, and fakes. It is self-contained and could be extracted to build any call-tracking wrapper.

file: src/sinon/proxy.js ↗ | tags: #proxy-pattern #function-wrapping #call-recording

Defines how a stub or fake responds to invocations. Behaviors include returning values, throwing errors, calling callbacks, resolving/rejecting promises, and yielding. Behaviors can be assigned per call index (e.g., `onFirstCall`, `onCall(2)`) and are invoked when the stub is called. This module is the engine behind stub/fake behavior and is reusable for any mock-like system.

file: src/sinon/behavior.js ↗ | tags: #behavior-pattern #stub-behavior #chainable-behaviors

Central sandbox class that manages collections of spies, stubs, mocks, fakes, and fake timers. Provides methods to create test doubles, replace properties, and use fake timers. The sandbox tracks all created doubles and can restore, reset, or verify them in bulk. This pattern is essential for test isolation and cleanup, and can be reused in any testing framework.

file: src/sinon/sandbox.js ↗ | tags: #sandbox-pattern #test-isolation #automatic-cleanup

A utility for copying properties from one object to another, with careful handling of property descriptors (including accessor properties and non-writable `name`). It supports both own and inherited properties and is used throughout Sinon to mix behavior onto proxy objects. This is a standalone, well-tested utility that can be reused in any project needing safe property extension.

file: src/sinon/util/core/extend.js ↗ | tags: #object-extension #descriptor-handling #property-copying

Creates a promise that can be externally resolved or rejected, exposing its status (pending, resolved, rejected) and resolved value/reason. This is useful for testing asynchronous code without relying on real timers. The implementation is self-contained and demonstrates a clean deferred promise pattern that can be extracted for any project needing controllable promises.

file: src/sinon/promise.js ↗ | tags: #controllable-promise #deferred #promise-pattern
Last analyzed: 2026-10-06 02:08:51.219274
Next check: 2026-10-13 02:08:51.220229
$ submit: