パッケージの詳細

ghostface

fardog25.8kApache-2.01.5.0

Evaluate Javascript in PhantomJS, and print the output.

phantom, phantomjs, context, evaluate

readme

ghostface

Evaluate javascript in PhantomJS, and print the output.

Build Status npm install

Inspired by jsdom-eval, this module makes it trivial to run tests in a headless browser.

Installation

npm install -g ghostface will expose the ghostface command in your environment.

ghostface does not include phantomjs as a dependency; you should install that however works best in your environment, and ghostface will find it so long as it exists in your $PATH.

ghostface supports phantomjs versions ^1.9.0 or ^2.0.0.

Example

Imagine a browserify project that you're testing using tape:

// file: test.js

var test = require('tape')

test('always passes', function(t) {
  t.plan(1)
  t.pass()
})

Run it with ghostface:

$ browserify test.js | ghostface | faucet

See the output printed to the console:

✓ always passes
# tests 1
# pass  1
✓ ok

Note: In the example above, we pipe output to faucet, which parses TAP output and sets the correct exit codes; ghostface is just evaluating javascript, it doesn't know/care what the output is, or how to set the correct exit codes.

Usage

$ ghostface --help

Usage: ghostface [options] [file]

file    Javascript file to be evaluated

Options:
  -h --html            The HTML file to be used as the page template
  -t --timeout         Milliseconds to wait for output before stopping execution. Default 1000
  -f --forever         Ignore the timeout and wait forever
  -p --phantomPath     Specify the path to the phantomjs executable
  --help               Show this message
  --version            Print version and quit

You can specify the JS file to be evaluated, or pipe a JS file directly into ghostface. For an imaginary file.js in the current directory, these two commands are equivalent:

$ ghostface file.js
$ cat file.js | ghostface

The JS you are evaluating will be done in a blank web page. If you want to provide your own context, use the --html <filename> option to load your own html; the JS will be evaluated after the page loads.

By default, execution is stopped if no console output is seen for over 1000ms. You can override this timeout with --timeout <ms>, or choose to run forever with --forever. Note you will have to send a SIGHUP to end execution.

License

This project is licensed under the Apache License, Version 2.0. See LICENSE for the full license.

更新履歴

ghostface Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

1.5.0 - 2015-08-31

  • Allows version 2.0.1-development to be used

1.4.0 - 2015-08-23

  • Fixes an issue with phantomjs exit codes being ignored, and the exit code of ghostface being set incorrectly. Thanks to arjunmehta for reporting this issue, and identifying the correct fix.

1.3.0 - 2015-06-02

  • Changes the way timeouts are handled; fixes issues where stream buffering would cause incorrect timeouts to occur.

1.2.1 - 2015-06-01

  • If phantom exits or crashes for any reason other than a timeout, report a message to stderr.
  • Fixes a bad publish of 1.2.0

[1.2.0] - 2015-06-01

  • REDACTED this was the result of a bad publish

1.1.3 - 2015-05-05

  • Adds phantomjs keyword to match the phantomjs package.

1.1.2 - 2015-04-26

1.1.1 - 2015-04-24

  • Exports the correct file: Although ghostface wasn't necessarily meant to be used programmatically, you absolutely could use it as such. This corrects the package.json to export the correct file.
  • Updates the license to the OSI standard license name.

1.1.0 - 2015-04-24

  • Turns out we weren't actually loading the html we thought we were; that's corrected and a test is added for it.
  • Opens the page rather than just replacing the content on 'about:blank', avoiding SECURITY_ERR issues
  • Fixes a prone-to-failure timing test

1.0.2 - 2015-04-23

  • Documentation updates

1.0.1 - 2015-04-20

  • Supports phantomjs 2.0.0 correctly; we were using a deprecated method of accessing phatom's argv, which caused a failure.

1.0.0 - 2014-04-20

  • Adds support for source maps
  • Better stack traces

0.2.0 - 2014-04-20

  • Adds tests
  • Massive numbers of fixes caught in testing

0.1.0 - 2014-03-24

  • Initial release