@mihon/spacejam
Version:
Run your meteor package tinytests and mocha tests from the command line with phantomjs.
104 lines (87 loc) • 3.5 kB
JavaScript
// Generated by CoffeeScript 1.8.0
(function() {
var ChildProcess, DEFAULT_PATH, EventEmitter, Phantomjs, expect, path, phantomjs, _,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = 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; };
_ = 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(_super) {
__extends(Phantomjs, _super);
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);