puppet-call
puppeteer utils for testing: bundler, server, browser, page
Last updated 2 months ago by hugov .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install puppet-call 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.2.0                                ...           latest (2 months ago)

10 Versions

  • 0.2.0                                ...           2 months ago
  • 0.1.7                                ...           a year ago
  • 0.1.5                                ...           a year ago
  • 0.1.4                                ...           2 years ago
  • 0.1.3                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 1
Last Month 3
Dependencies (3)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |