# puppet-call

> puppeteer utils for testing: bundler, server, browser, page

Latest version **0.2.0** (published 2019-09-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install puppet-call
pnpm add puppet-call
yarn add puppet-call
bun add puppet-call
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2019-09-26 |
| First published | 2017-11-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Hugo Villeneuve |
| Maintainers | hugov |
| Keywords | puppeteer, browser, chromium, test |

## Links

- npm: https://www.npmjs.com/package/puppet-call
- Repository: https://github.com/hville/puppet-call
- Homepage: https://github.com/hville/puppet-call#readme
- Issues: https://github.com/hville/puppet-call/issues
- npm.io page: https://npm.io/package/puppet-call

## Dependencies (3)

- [@hugov/cjs-to-iife](https://npm.io/package/@hugov/cjs-to-iife.md) ^0.1.4
- [@hugov/test-server](https://npm.io/package/@hugov/test-server.md) 0.0.4
- [@hugov/promise-wrap](https://npm.io/package/@hugov/promise-wrap.md) 0.0.3

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2019-09-26
- 0.1.7 — 2018-06-10
- 0.1.5 — 2018-06-10
- 0.1.4 — 2017-12-15
- 0.1.3 — 2017-12-07
- 0.1.2 — 2017-12-07
- 0.1.1 — 2017-12-07
- 0.1.0 — 2017-12-06
- 0.0.2 — 2017-12-02
- 0.0.1 — 2017-11-27

## README

# puppet-call

*puppeteer helpers for testing*

## Examples

```javascript
const puppetCall = require('puppet-call')
puppetCall('./commonjsmodule.js', exports => exports.myAction())
```

## Examples - server utilities

```javascript
const bundle = require('puppet-call/bundle')
const withServer = require('puppet-call/with-server')
const withPage = require('puppet-call/with-page')

withServer(
  {routes: {
    './mscript': bundle('./commonjsmodule.js')
    }
  },
  ({origin}) => withPage(origin, page=>page.evaluate(pageAction))
).then(
  result => console.log('result')
)
```

## Features, Limitations, Gotcha

* small wrapper function to properly close the server, browser and page after execution
* `puppeteer` is listed as peerDependency due to it's size and must be installed seperatly

## API

* `puppetCall(commonjsPath, exportsAction)`
  * bundles CJS modules, reroutes console.log to node and run in the browser context
* `bundle(path): code`
  * bundles CJS modules into an IIFE for the browser
* `withServer(serverOptions, serverAction): Promise`
  * `serverAction({host, port, root, origin}):Promise`
  * `serverOptions: {root: string, port: number, routes: Object: host: string}`
  * Initiates a server, evaluate `serverAction`, then closes the server before returning the `serverAction` result
* `withPuppet: (launchOptions, puppetAction): Promise`
  * `puppetAction(browser):Promise`
  * Initiates `puppeteer`, evaluate `puppetAction`, then closes the browser before returning the `puppetAction` result
* `withPage: (origin, pageAction): Promise`
  * `pageAction(page):Promise`
  * Initiates `puppeteer`, navigate to `origin`, evaluate `pageAction`, then closes the browser before returning the `pageAction` result

## License

[MIT](http://www.opensource.org/licenses/MIT) © [Hugo Villeneuve](https://github.com/hville)

---
_Source: https://npm.io/package/puppet-call · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
