Mockeer
Mocking library for Puppeteer!
Mockeer is a Puppeteer helper library to run chrome headless browser in isolation.
Mockeer works by overriding Puppeteer's Request event and providing mock responses.
Mockeer works in Record and Play mode. In record mode it intercepts browser requests and saves them as json fixtures. In play mode it just replay those saved responses.
$ npm install mockeerconst mockeer = require('mockeer');
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await mockeer(browser);
await page.goto('https://www.example.com');
await page.close();
await browser.close();
})();Save above script as index.js
Recordmode
> node index.jsPlaymode
> CI=true node index.jsSee more examples here
See full list of configs below
See API.md for full list of API calls
| Parameter | type | required | description | default |
|---|---|---|---|---|
page |
object |
no | If puppeteer page object passed, only mock responses for that page will be recorded | null |
fixturesDir |
string |
no | Path to generated fixture files | ./__mockeer_fixture__ |
fixtureName |
string |
no | Path to generated fixture name | chrome-http-mocks |
replaceImage |
boolean |
no | Replace images with template image | false |
replaceIfExists |
boolean |
no | Replace fixtures even when they already recorded | true |
allowImageRecourses |
boolean |
no | If enabled image resources will be fetched from origin and not intercepted in play mode | false |
svgTemplate |
string |
no | A SVG image template that will replace images in the page | A solid gray svg image. Source here |
See examples for usages and CI integration with jest
Visit project Slack Chat for general Q/A around project
See CONTRIBUTING.md if you want to contribute.
Gist example with vanilla node