Skip to content

Commit

Permalink
Renamed create() to spawn()
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnns committed May 22, 2014
1 parent e5a33bc commit ff3fc0b
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions .istanbul.yml
@@ -1,2 +1,3 @@
instrumentation:
# everything under lib/phantom/** runs within phantomjs and hence is difficult to include into our test coverage
excludes: ['lib/phantom/**']
2 changes: 1 addition & 1 deletion lib/main.js
@@ -1,3 +1,3 @@
exports.config = require("./config.js");
exports.create = require("./create.js");
exports.spawn = require("./spawn.js");
exports.disposeAll = require("./disposeAll.js");
2 changes: 1 addition & 1 deletion lib/request.js
Expand Up @@ -4,7 +4,7 @@ var http = require("http"),
when = require("when");

/**
* Configures and stats the http request so it can be understood by the phantomjs process.
* Configures and starts the http request so it can be understood by the phantomjs process.
*
* @private
* @param {Object} options
Expand Down
6 changes: 3 additions & 3 deletions lib/create.js → lib/spawn.js
Expand Up @@ -20,14 +20,14 @@ open = node.lift(temp.open);
writeFile = node.lift(fs.writeFile);

/**
* Creates a new phantomjs process with the given phantom config. Returns a Promises/A+ compliant promise
* Spawns a new phantomjs process with the given phantom config. Returns a Promises/A+ compliant promise
* which resolves when the process is ready to execute commands.
*
* @see http://phantomjs.org/api/command-line.html
* @param {Object} phantomJsConfig
* @returns {Promise}
*/
function create(phantomJsConfig) {
function spawn(phantomJsConfig) {
var configPath,
stdout,
stderr,
Expand Down Expand Up @@ -123,4 +123,4 @@ function create(phantomJsConfig) {
});
}

module.exports = create;
module.exports = spawn;
2 changes: 1 addition & 1 deletion test/Page.test.js
Expand Up @@ -32,7 +32,7 @@ describe("Page", function () {

before(slow(function () {
phridge.config.stderr = fakeStderr;
return phridge.create({}).then(function (newPhantom) {
return phridge.spawn({}).then(function (newPhantom) {
phantom = newPhantom;
});
}));
Expand Down
20 changes: 10 additions & 10 deletions test/Phantom.test.js
Expand Up @@ -24,15 +24,15 @@ describe("Phantom", function () {
},
port = 3000,
secret = "super secret",
createPhantom,
spawnPhantom,
exitPhantom;

createPhantom = slow(function () {
spawnPhantom = slow(function () {
if (phantom && phantom.childProcess) {
return;
}
phridge.config.stderr = fakeStderr;
return phridge.create().then(function (newPhantom) {
return phridge.spawn().then(function (newPhantom) {
phantom = newPhantom;
});
});
Expand All @@ -50,7 +50,7 @@ describe("Phantom", function () {
describe(".constructor(childProcess, port, secret)", function () {

after(function () {
// Null out phantom so createPhantom() will create a fresh one
// Null out phantom so spawnPhantom() will spawn a fresh one
phantom = null;
// Remove mocked Phantom instances from the instances-array
instances.length = 0;
Expand All @@ -76,7 +76,7 @@ describe("Phantom", function () {

describe(".childProcess", function () {

beforeEach(createPhantom);
beforeEach(spawnPhantom);

it("should provide a reference on the child process object created by node", function () {
expect(phantom.childProcess).to.be.an("object");
Expand All @@ -89,7 +89,7 @@ describe("Phantom", function () {

describe(".port", function () {

beforeEach(createPhantom);
beforeEach(spawnPhantom);

it("should be a number", function () {
expect(phantom.port).to.be.a("number");
Expand All @@ -99,7 +99,7 @@ describe("Phantom", function () {

describe(".run(arg1, arg2, arg3, fn)", function () {

beforeEach(createPhantom);
beforeEach(spawnPhantom);

describe("with fn being an asynchronous function", function () {

Expand Down Expand Up @@ -303,7 +303,7 @@ describe("Phantom", function () {

describe(".createPage()", function () {

beforeEach(createPhantom);
beforeEach(spawnPhantom);

it("should return an instance of Page", function () {
expect(phantom.createPage()).to.be.an.instanceof(Page);
Expand All @@ -313,7 +313,7 @@ describe("Phantom", function () {

describe(".openPage(url)", function () {

beforeEach(createPhantom);
beforeEach(spawnPhantom);

it("should resolve to an instance of Page", function () {
return expect(phantom.openPage(this.testServerUrl)).to.eventually.be.an.instanceof(Page);
Expand Down Expand Up @@ -348,7 +348,7 @@ describe("Phantom", function () {

describe(".dispose()", function () {

beforeEach(createPhantom);
beforeEach(spawnPhantom);

it("should terminate the child process with exit-code 0 and then resolve", slow(function () {
var exit = false;
Expand Down
6 changes: 3 additions & 3 deletions test/disposeAll.test.js
Expand Up @@ -17,9 +17,9 @@ describe("disposeAll()", function () {
var exited = [];

return when.all([
phridge.create(),
phridge.create(),
phridge.create()
phridge.spawn(),
phridge.spawn(),
phridge.spawn()
])
.then(function (p) {
p[0].childProcess.on("exit", function () { exited.push(0); });
Expand Down
8 changes: 4 additions & 4 deletions test/main.test.js
Expand Up @@ -3,7 +3,7 @@
var chai = require("chai"),
expect = chai.expect,
config = require("../lib/config"),
create = require("../lib/create"),
spawn = require("../lib/spawn"),
disposeAll = require("../lib/disposeAll"),
phridge = require("../lib/main.js");

Expand All @@ -19,10 +19,10 @@ describe("phridge", function () {

});

describe(".create", function () {
describe(".spawn", function () {

it("should be the create-module", function () {
expect(phridge.create).to.equal(create);
it("should be the spawn-module", function () {
expect(phridge.spawn).to.equal(spawn);
});

});
Expand Down
10 changes: 5 additions & 5 deletions test/create.test.js → test/spawn.test.js
Expand Up @@ -7,7 +7,7 @@ var chai = require("chai"),
getport = require("getport"),
net = require("net"),
expect = chai.expect,
create = rewire("../lib/create.js"),
spawn = rewire("../lib/spawn.js"),
phridge = require("../lib/main.js"),
Phantom = require("../lib/Phantom.js"),
slow = require("./helpers/slow.js"),
Expand All @@ -19,14 +19,14 @@ chai.use(require("chai-as-promised"));

getport = node.lift(getport);

describe("create(config?)", function () {
describe("spawn(config?)", function () {

after(slow(function () {
return phridge.disposeAll();
}));

it("should resolve to an instance of Phantom", slow(function () {
return expect(create()).to.eventually.be.an.instanceOf(Phantom);
return expect(spawn()).to.eventually.be.an.instanceOf(Phantom);
}));

it("should pass the provided config to phantomjs", slow(function () {
Expand All @@ -43,7 +43,7 @@ describe("create(config?)", function () {
server.listen(port);

phridge.config.stdout = fakeStdout;
phridge.create({
phridge.spawn({
webdriver: "localhost:" + port
});
phridge.config.stdout = process.stdout;
Expand All @@ -63,7 +63,7 @@ describe("create(config?)", function () {
it("should share a secret with the phantomjs process so no untrusted code can be executed", slow(function () {
var evilCode = "resolve('harharhar')";

return expect(create()
return expect(spawn()
.then(function (phantom) {
return request({
port: phantom.port,
Expand Down

0 comments on commit ff3fc0b

Please sign in to comment.