JSPM

  • Created
  • Published
  • Downloads 3903
  • Score
    100M100P100Q120836F
  • License MIT

Turns a stream of JavaScript into a stream of console output it creates in a real browser environment.

Package Exports

  • browser-run

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (browser-run) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

browser-run

Write JavaScript to it and receive the console output of that code run in a real browser environment.

Usage

$ echo "console.log('foo')" | browser-run
# => foo

Or use browser-run programmatically:

var run = require('browser-run');

// create a browser
var browser = run();

// console output comes in
browser.on('data', function (data) {
  console.log(data);
  // => foo
  // when finished, call stop()
  browser.stop();
});

// write some javascript to it
browser.write('console.log("foo")');
// close the input stream
browser.end();

Example with browserify

$ browserify main.js | browser-run

or

var browserify = require('browserify');
var run = require('browser-run');

var browser = run();
browserify('main.js').bundle().pipe(browser);

browser.on('data', function (data) {
  console.log('data', data);
  if (finished) {
    browser.stop();
  }
});

CLI

$ browser-run --help
Run JavaScript in a browser.
Write code to stdin and receive console output on stdout.
Usage: browser-run [OPTIONS]

Options:
  --port, -p  Start listening on that port
  --help, -h  Print help

API

run([port])

Returns a duplex stream and starts a webserver.

If you don't specify port a random port will be chosen and phantomjs will be pointed at the server for headless testing.

If you speficy port you will have to point a browser to "http://localhost/" + port.

run#stop()

Stop the underlying webserver.

Installation

With npm do

$ npm install browser-run    # for library
$ npm install -g browser-run # for cli

License

(MIT)