puppet-call
v0.2.0
Published
puppeteer utils for testing: bundler, server, browser, page
Downloads
2
Readme
puppet-call
puppeteer helpers for testing
Examples
const puppetCall = require('puppet-call')
puppetCall('./commonjsmodule.js', exports => exports.myAction())
Examples - server utilities
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 theserverAction
result
withPuppet: (launchOptions, puppetAction): Promise
puppetAction(browser):Promise
- Initiates
puppeteer
, evaluatepuppetAction
, then closes the browser before returning thepuppetAction
result
withPage: (origin, pageAction): Promise
pageAction(page):Promise
- Initiates
puppeteer
, navigate toorigin
, evaluatepageAction
, then closes the browser before returning thepageAction
result