0.2.0 • Published 6 years ago
puppet-call v0.2.0
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
puppeteeris 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): PromiseserverAction({host, port, root, origin}):PromiseserverOptions: {root: string, port: number, routes: Object: host: string}- Initiates a server, evaluate
serverAction, then closes the server before returning theserverActionresult
withPuppet: (launchOptions, puppetAction): PromisepuppetAction(browser):Promise- Initiates
puppeteer, evaluatepuppetAction, then closes the browser before returning thepuppetActionresult
withPage: (origin, pageAction): PromisepageAction(page):Promise- Initiates
puppeteer, navigate toorigin, evaluatepageAction, then closes the browser before returning thepageActionresult