
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
chrome-stub
Advanced tools
Chrome API mocking library.
npm install chrome-stub
In most cases you will want to set this as a global at the top of your test file, because chrome is a global in your extension code.
chrome = require('chrome-stub')
To use the I18n library, chrome-stub loads a default messages.json file that has only one string in it, 'test' If you pass a string that does not exist, you will receive a blank string back.
If you want to load a different messages.json file, for example the one you use in your chrome extension then use the method below in your test file.
_locales/ru/messages.json
{
"test": {
"message": "Тест"
}
}
test.js
let path = require('path');
let config = path.resolve(process.cwd(), '_locales/ru/messages.json');
chrome.loadDefaults(config);
chrome.i18n.getMessage('test'); // Тест
All chrome APIs have been stubbed with sinon stub. You can define your own application-specific behavior of the stubs by following the sinon stub api. This allows you to define your behavior within your tests. For example:
// inside test
chrome.tabs.query.yields([{
id:0,index:0,windowId:0,highlighted:true,
active:true,pinned:false,url:'https://example.com',title:'example.com - Home',
favIconUrl:'https://example.com/favicon.ico',status:'complete',width:800,height:600
}]);
// do something that causes your code to call chrome.tabs.query, e.g.:
getFirstTab(function(tab){
// ...
// your code's callback is called with the value provided to yields()
});
Originally forked from sethmcl/chrome-mock
FAQs
Easily stub out chrome API calls for great test coverage
The npm package chrome-stub receives a total of 20 weekly downloads. As such, chrome-stub popularity was classified as not popular.
We found that chrome-stub demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.