X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=node_modules%2Fphridge%2Ftest%2Fspawn.test.js;fp=node_modules%2Fphridge%2Ftest%2Fspawn.test.js;h=d89767c4e79d3b6acdcc8c5142dd89366ce2b14c;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/node_modules/phridge/test/spawn.test.js b/node_modules/phridge/test/spawn.test.js new file mode 100644 index 000000000..d89767c4e --- /dev/null +++ b/node_modules/phridge/test/spawn.test.js @@ -0,0 +1,93 @@ +"use strict"; + +var chai = require("chai"); +var getport = require("getport"); +var net = require("net"); +var expect = chai.expect; +var spawn = require("../lib/spawn.js"); +var phridge = require("../lib/main.js"); +var Phantom = require("../lib/Phantom.js"); +var slow = require("./helpers/slow.js"); +var lift = require("../lib/lift.js"); + +require("./helpers/setup.js"); + +getport = lift(getport); + +describe("spawn(config?)", function () { + var port; + + function blockGhostDriverPort() { + return getport(10000) + .then(function (freePort) { + var server = net.createServer(); + var listen = lift(server.listen); + + port = freePort; + + // We're blocking the GhostDriver port so phantomjs crashes on startup. + // Otherwise the phantomjs processes can't be killed because it doesn't + // listen on our commands in GhostDriver-mode. + return listen.call(server, freePort); + }); + } + + after(slow(function () { + return phridge.disposeAll(); + })); + + it("should resolve to an instance of Phantom", slow(function () { + return expect(spawn()).to.eventually.be.an.instanceOf(Phantom); + })); + + it("should pass the provided config to phantomjs", slow(function (done) { + // We're setting the webdriver option to test if the config is recognized + // Setting this option does not make any sense because phantomjs is + // unusable with phantomjs in GhostDriver-mode. But it prints a nice + // message to the console which causes the promise to be rejected + blockGhostDriverPort() + .then(function () { + // Prevent PhantomJS from printing a disturbing error message to the console + phridge.config.stdout = null; + phridge.config.stderr = null; + + return expect(phridge.spawn({ + webdriver: "localhost:" + port + })).to.be.rejectedWith(/GhostDriver - main\.fail/); + }) + .then(function () { + phridge.config.stdout = process.stdout; + phridge.config.stderr = process.stderr; + + // Give phantomjs some time to exit + setTimeout(done, 100); + }); + })); + + it("should also allow CLI style config options", slow(function (done) { + // We're setting the webdriver option to test if the config is recognized + // Setting this option does not make any sense because phantomjs is + // unusable with phantomjs in GhostDriver-mode. But it prints a nice + // message to the console which causes the promise to be rejected + blockGhostDriverPort() + .then(function () { + // Prevent PhantomJS from printing a disturbing error message to the console + phridge.config.stdout = null; + phridge.config.stderr = null; + + return expect(phridge.spawn({ + "--load-images": "true", + "--webdriver": "localhost:" + port + })).to.be.rejectedWith("GhostDriver"); + }) + .then(function () { + phridge.config.stdout = process.stdout; + phridge.config.stderr = process.stderr; + + // Give phantomjs some time to exit + setTimeout(done, 100); + }) + .catch(done); + })); + +});