A helper tool for unit-testing Chrome and Firefox extensions and apps in Node.js by mocking the browser API.
Sinon-chrome is a Node.js library for unit-testing Chrome and Firefox browser extensions and apps. It mocks the entire browser API using Sinon stubs and mock events, allowing developers to run tests without a real browser. It solves the problem of testing extension logic in isolation by providing a controlled, schema-accurate simulation of the Chrome and Firefox extension environments.
Developers building Chrome or Firefox extensions and apps who need to write unit tests in Node.js without browser dependency. It's particularly useful for teams integrating extension testing into CI/CD pipelines.
Developers choose Sinon-chrome because it provides accurate, schema-based API mocks that match real browser behavior, integrates seamlessly with Sinon.js for familiar testing patterns, and eliminates the need for browser automation in unit tests.
Testing chrome extensions with Node.js
Generates mocks using official Chromium and Firefox WebExtensions schemas, ensuring consistency with real browser APIs, as stated in the README under 'Schema support'.
Replaces Chrome API methods with Sinon stubs and events with mockable classes, enabling familiar testing patterns like .calledOnce and .withArgs, as shown in the examples.
Supports plugins like Cookie and i18n to emulate browser-specific behaviors, providing more realistic testing environments, as mentioned in the Plugins section.
Includes a flush method to reset stub behavior and properties to defaults, simplifying test cleanup, demonstrated in the stubs api examples.
The README admits schemas are from Chrome 53 and Firefox 49, which are old versions, potentially missing newer APIs and leading to inaccurate mocks for modern extensions.
Primarily designed for Node.js testing, making it unsuitable for browser-based unit tests or environments that require actual browser execution, as highlighted in the 'How it works' section.
Plugins like Cookie and i18n have minimal documentation on the wiki, which can hinder setup and usage for developers needing to emulate complex browser behaviors.
Accurate emulation often requires registering additional plugins, adding complexity compared to simpler mocking libraries, as noted in the Plugins section.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.