UNPKG

spacejam-updated

Version:

Run your meteor package tinytests and mocha tests from the command line with phantomjs.

104 lines (87 loc) 3.49 kB
// Generated by CoffeeScript 1.11.1 (function() { var ChildProcess, DEFAULT_PATH, EventEmitter, Phantomjs, _, expect, path, phantomjs, bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; _ = require("underscore"); expect = require('chai').expect; ChildProcess = require('./ChildProcess'); EventEmitter = require('events').EventEmitter; path = require('path'); phantomjs = require('phantomjs-prebuilt'); DEFAULT_PATH = process.env.PATH; Phantomjs = (function(superClass) { extend(Phantomjs, superClass); function Phantomjs() { this.run = bind(this.run, this); return Phantomjs.__super__.constructor.apply(this, arguments); } Phantomjs.prototype.childProcess = null; Phantomjs.prototype.run = function(url, options, script, pipeClass, pipeClassOptions, useSystemPhantomjs) { var env, spawnArgs, spawnOptions; if (options == null) { options = '--load-images=no --ssl-protocol=TLSv1'; } if (script == null) { script = "phantomjs-test-in-console.js"; } if (pipeClass == null) { pipeClass = void 0; } if (pipeClassOptions == null) { pipeClassOptions = void 0; } if (useSystemPhantomjs == null) { useSystemPhantomjs = false; } log.debug("Phantomjs.run()", arguments); expect(this.childProcess, "ChildProcess is already running").to.be["null"]; expect(url, "Invalid url").to.be.a('string'); expect(options, "Invalid options").to.be.a('string'); expect(script, "Invalid script").to.be.a('string'); if (pipeClass != null) { expect(pipeClass, "Invalid pipeClass").to.be.a('function'); } if (pipeClassOptions != null) { expect(pipeClassOptions, "Invalid pipeClassOptions").to.be.an('object'); } expect(useSystemPhantomjs, "Invalid useSystemPhantomjs").to.be.a('boolean'); env = _.extend(process.env, { ROOT_URL: url }); log.debug("script=" + __dirname + "/" + script); spawnArgs = options.split(' '); spawnArgs.push(script); log.debug('spawnArgs:', spawnArgs); spawnOptions = { cwd: __dirname, detached: false, env: env }; log.debug('spawnOptions:', spawnOptions); if (useSystemPhantomjs) { process.env.PATH = DEFAULT_PATH; } else { process.env.PATH = path.dirname(phantomjs.path) + ':' + DEFAULT_PATH; } this.childProcess = new ChildProcess(); this.childProcess.spawn("phantomjs", spawnArgs, spawnOptions, pipeClass, pipeClassOptions); return this.childProcess.child.on("exit", (function(_this) { return function(code, signal) { return _this.emit("exit", code, signal); }; })(this)); }; Phantomjs.prototype.kill = function(signal) { var ref; if (signal == null) { signal = "SIGTERM"; } log.debug("Phantomjs.kill()"); return (ref = this.childProcess) != null ? ref.kill(signal) : void 0; }; return Phantomjs; })(EventEmitter); module.exports = Phantomjs; }).call(this);