0.2.0 • Published 5 years ago

puppet-call v0.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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 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 © Hugo Villeneuve

0.2.0

5 years ago

0.1.7

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago