From ff3fc0b3a39ccbcaf6cd5d2585eb7d53cb2e3b43 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Thu, 22 May 2014 19:34:42 +0200 Subject: [PATCH] Renamed create() to spawn() --- .istanbul.yml | 1 + lib/main.js | 2 +- lib/request.js | 2 +- lib/{create.js => spawn.js} | 6 +++--- test/Page.test.js | 2 +- test/Phantom.test.js | 20 ++++++++++---------- test/disposeAll.test.js | 6 +++--- test/main.test.js | 8 ++++---- test/{create.test.js => spawn.test.js} | 10 +++++----- 9 files changed, 29 insertions(+), 28 deletions(-) rename lib/{create.js => spawn.js} (95%) rename test/{create.test.js => spawn.test.js} (91%) diff --git a/.istanbul.yml b/.istanbul.yml index 7a7b846..84225c2 100644 --- a/.istanbul.yml +++ b/.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/**'] \ No newline at end of file diff --git a/lib/main.js b/lib/main.js index b39b491..c892fd5 100644 --- a/lib/main.js +++ b/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"); \ No newline at end of file diff --git a/lib/request.js b/lib/request.js index 4dafd2b..ca0edf8 100644 --- a/lib/request.js +++ b/lib/request.js @@ -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 diff --git a/lib/create.js b/lib/spawn.js similarity index 95% rename from lib/create.js rename to lib/spawn.js index 7f51666..9ac2a42 100644 --- a/lib/create.js +++ b/lib/spawn.js @@ -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, @@ -123,4 +123,4 @@ function create(phantomJsConfig) { }); } -module.exports = create; \ No newline at end of file +module.exports = spawn; \ No newline at end of file diff --git a/test/Page.test.js b/test/Page.test.js index c5e387c..6318659 100644 --- a/test/Page.test.js +++ b/test/Page.test.js @@ -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; }); })); diff --git a/test/Phantom.test.js b/test/Phantom.test.js index 3f0c585..964b631 100644 --- a/test/Phantom.test.js +++ b/test/Phantom.test.js @@ -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; }); }); @@ -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; @@ -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"); @@ -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"); @@ -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 () { @@ -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); @@ -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); @@ -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; diff --git a/test/disposeAll.test.js b/test/disposeAll.test.js index 81beaa0..5fe5b6c 100644 --- a/test/disposeAll.test.js +++ b/test/disposeAll.test.js @@ -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); }); diff --git a/test/main.test.js b/test/main.test.js index b774016..4a08b88 100644 --- a/test/main.test.js +++ b/test/main.test.js @@ -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"); @@ -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); }); }); diff --git a/test/create.test.js b/test/spawn.test.js similarity index 91% rename from test/create.test.js rename to test/spawn.test.js index af2d86a..101e7f8 100644 --- a/test/create.test.js +++ b/test/spawn.test.js @@ -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"), @@ -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 () { @@ -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; @@ -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,