Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.
/ chrome-mock Public archive

💬 Chrome messaging mock for integration testing

Notifications You must be signed in to change notification settings

mikesteele/chrome-mock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chrome-mock

A Chrome messaging mock for integration testing.

It allows testing message passing between content_scripts, background pages, and browser_actions.

Currently supports:

chrome.tabs.query
chrome.tabs.sendMessage
chrome.runtime.onMessage
chrome.runtime.sendMessage

See chrome-mock.test.js for examples of usage in tests.

API

const ChromeMock = require('chrome-mock');

Tabs

Create a tab

const tab = ChromeMock.createTab({
  content_scripts?: [String],
  html?: String
});

Tab API

tab.id
tab.window

Browser Action

const browserAction = ChromeMock.createBrowserAction({
  script?: String  
});

Current limits

No isolated world

Unlike real content_scripts, content_scripts in ChromeMock Tabs aren't run in an "isolated world". That means they can interact with JS created in the HTML passed to ChromeMock.createTab({ html: <> }). If your content_script behavior relies on an isolated world, it will not work.

Risk of Self-XSS

This uses JSDOM's "run scripts dangerously", which can cause self-XSS if running against content_scripts you do not control. See https://github.com/jsdom/jsdom#executing-scripts

Single window

No support yet for Tabs in multiple windows.

Influences

For unit testing, I recommend https://github.com/sethmcl/chrome-mock or https://github.com/acvetkov/sinon-chrome.

This library targets integration testing.

License

MIT

About

💬 Chrome messaging mock for integration testing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published