Skip to content

Commit

Permalink
(#1086) - Add selenium standalone as a dep
Browse files Browse the repository at this point in the history
  • Loading branch information
daleharvey committed Dec 15, 2013
1 parent 83f8c43 commit 67471e6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
25 changes: 17 additions & 8 deletions bin/dev-server.js
@@ -1,21 +1,30 @@
#!/usr/bin/env node

'use strict';

var cors_proxy = require("corsproxy");
var http_proxy = require("http-proxy");
var http_server = require("http-server");

var program = require('commander');

program
.option('-r, --remote [url]', 'Specify the remote couch host')
.parse(process.argv);

var COUCH_HOST = 'http://127.0.0.1:5984';
var HTTP_PORT = 8000;
var CORS_PORT = 2020;

var couchHost = program.remote || 'http://127.0.0.1:5984';
function startServers(remote) {
var couchHost = remote || COUCH_HOST;
http_server.createServer().listen(HTTP_PORT);
cors_proxy.options = {target: couchHost};
http_proxy.createServer(cors_proxy).listen(CORS_PORT);
}

http_server.createServer().listen(HTTP_PORT);
cors_proxy.options = {target: couchHost};

http_proxy.createServer(cors_proxy).listen(CORS_PORT);
if (require.main === module) {
program
.option('-r, --remote [url]', 'Specify the remote couch host')
.parse(process.argv);
startServers(program.remote);
} else {
module.exports.start = startServers;
}
42 changes: 27 additions & 15 deletions bin/test-browser.js
@@ -1,22 +1,12 @@
#!/usr/bin/env node

// This requires some setup, will attempt to remove steps needed

// You need to download and start selenium-server-standalone
// download from: https://code.google.com/p/selenium/downloads/list
// start with: java -jar ~/Downloads/selenium-server-standalone-2.37.0.jar

// You need chromedriver, download it @
// Download http://chromedriver.storage.googleapis.com/index.html?path=2.7/
// then add to your path

// If you are on OSX, you will need to ensure Firefox is on your path
// export PATH=/Applications/Firefox.app/Contents/MacOS/:$PATH

// Also needs $ npm run dev-server if run manually
var path = require('path');
var spawn = require('child_process').spawn;

var webdriverjs = require('webdriverjs');
var devserver = require('./dev-server.js');

var SELENIUM_PATH = '../node_modules/.bin/start-selenium';
var testUrl = 'http://127.0.0.1:8000/tests/test.html';
var testTimeout = 2 * 60 * 1000;
var testSelector = 'body.testsComplete';
Expand All @@ -32,6 +22,26 @@ var browsers = [
'chrome'
];

// Travis only has firefox
if (process.env.TRAVIS) {
browsers = ['firefox'];
}

function startServers(callback) {

// Starts the file and CORS proxy
devserver.start();

// Start selenium
var selenium = spawn(path.resolve(__dirname, SELENIUM_PATH));

selenium.stdout.on('data', function(data) {
if (/Started org.openqa.jetty.jetty/.test(data)) {
callback();
}
});
}

function testsComplete() {
var passed = Object.keys(results).every(function(x) {
return results[x].passed;
Expand Down Expand Up @@ -81,4 +91,6 @@ function startTest() {
client.url(testUrl).waitFor(testSelector, testTimeout, testComplete);
}

startTest();
startServers(function() {
startTest();
});
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -25,6 +25,7 @@
"devDependencies": {
"commander": "~2.1.0",
"webdriverjs": "~0.7.14",
"selenium-standalone": "~2.38.0",
"watchify": "~0.4.1",
"uglify-js": "~2.4.6",
"jshint": "~2.3.0",
Expand Down Expand Up @@ -54,7 +55,7 @@
"test-node": "./bin/test-node.js",
"test-browser": "npm run build-js && ./bin/test-browser.js",
"dev-server": "npm run watch-js & ./bin/dev-server.js",
"test": "npm run jshint && npm run test-node"
"test": "npm run jshint && npm run test-node && npm run test-browser"
},
"browser": {
"./adapters/leveldb": false,
Expand Down

0 comments on commit 67471e6

Please sign in to comment.