0.0.1 • Published 5 years ago

nocketeer v0.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

About

Nocketeer is a Puppeteer helper library to run chrome headless browser in isolation. It is inspired by Nock.back library.

How it works

Nocketeer works by overriding Puppeteer's Request event and providing mock responses.

Nocketeer works in Record and Play mode. In record mode it intercepts http calls and saves them as json fixtures. In play mode it just replay those saved responses.

Installation

$ npm install nocketeer

Usage

const nocketeer = require('nocketeer');
const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await nocketeer(browser);
  await page.goto('https://www.example.com');
  await page.close();
  await browser.close();
})();

Save above script as index.js

  • Record mode
> node index.js
  • Play mode
> CI=true node index.js

See more examples here

See full list of configs below

API

See API.md for full list of API calls

GlobalOptions

Parametertyperequireddescriptiondefault
pageobjectnoIf puppeteer page object passed, only mock responses for that page will be recordednull
fixturesDirstringnoPath to generated fixture files./__nocketeer_fixture__
fixtureNamestringnoPath to generated fixture namechrome-http-mocks
replaceImagebooleannoReplace images with template imagefalse
allowImageRecoursesbooleannoIf enabled image resources will be fetched from origin and not intercepted in play modefalse
svgTemplatestringnoA SVG image template that will replace images in the pageA solid gray svg image. Source here

Links

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