Permalink
Browse files

linting files, fixing coverage

  • Loading branch information...
1 parent 7156677 commit 202d543d090f4e85968542208afdafa056693a5a Alexander Early committed Jul 2, 2013
Showing with 97 additions and 94 deletions.
  1. +1 −0 .jshintrc
  2. +2 −2 Makefile
  3. +3 −0 index.js
  4. +33 −33 lib/sauce-connect-launcher.js
  5. +1 −1 package.json
  6. +57 −58 test/sauce-connect-launcher.test.js
View
@@ -18,6 +18,7 @@
"browser": true,
"node": true,
"indent": 2,
+ "quotmark": "double",
"onevar": true,
"white": true,
"strict": false,
View
@@ -12,10 +12,10 @@ test:
mocha
test-instrument:
- jscoverage js js-cov
+ jscoverage lib/ lib-cov/
test-clean-instrument:
- rm -rf js-cov
+ rm -rf lib-cov/
test-coverage-report:
COVERAGE=1 mocha --reporter html-cov > test/coverage.html
View
@@ -0,0 +1,3 @@
+module.exports = (process.env.COVERAGE ?
+ require("./lib-cov/sauce-connect-launcher") :
+ require("./lib/sauce-connect-launcher"));
@@ -1,14 +1,14 @@
var
- fs = require('fs'),
- path = require('path'),
- ProgressBar = require('progress'),
- http = require('http'),
- unzip = require('unzip'),
- spawn = require('child_process').spawn,
- EventEmitter = require('events').EventEmitter,
- util = require('util'),
- jarfile = path.normalize(__dirname + '/Sauce-Connect.jar'),
- outfile = path.normalize(__dirname + '/Sauce-Connect-latest.zip'),
+ fs = require("fs"),
+ path = require("path"),
+ ProgressBar = require("progress"),
+ http = require("http"),
+ unzip = require("unzip"),
+ spawn = require("child_process").spawn,
+ EventEmitter = require("events").EventEmitter,
+ util = require("util"),
+ jarfile = path.normalize(__dirname + "/Sauce-Connect.jar"),
+ outfile = path.normalize(__dirname + "/Sauce-Connect-latest.zip"),
openProcesses = [],
logger = console.log,
cleanup_registered = false;
@@ -21,61 +21,61 @@ function closeOnProcessTermination() {
return;
}
cleanup_registered = true;
- process.on('exit', function (err) {
+ process.on("exit", function (err) {
logger("Shutting down");
while (openProcesses.length) {
var fakeProcess = openProcesses.pop();
try {
fakeProcess.emit("exit");
- fakeProcess.kill('SIGTERM');
+ fakeProcess.kill("SIGTERM");
} catch (e) {}
}
});
}
function download(options, callback) {
var req = http.request({
- host: 'saucelabs.com',
+ host: "saucelabs.com",
port: 80,
- path: '/downloads/Sauce-Connect-latest.zip'
+ path: "/downloads/Sauce-Connect-latest.zip"
});
logger("Missing Sauce Connect local proxy, downloading dependency");
logger("This will only happen once.");
- req.on('response', function (res) {
+ req.on("response", function (res) {
- logger("Downloading ", res.headers['content-length'], "bytes");
+ logger("Downloading ", res.headers["content-length"], "bytes");
- var bar, len = parseInt(res.headers['content-length'], 10);
+ var bar, len = parseInt(res.headers["content-length"], 10);
res.pipe(fs.createWriteStream(outfile));
logger();
if (!options.no_progress) {
- bar = new ProgressBar(' downloading Sauce-Connect-latest.zip [:bar] :percent :etas', {
- complete: '=',
- incomplete: ' ',
+ bar = new ProgressBar(" downloading Sauce-Connect-latest.zip [:bar] :percent :etas", {
+ complete: "=",
+ incomplete: " ",
width: 20,
total: len
});
- res.on('data', function (chunk) {
+ res.on("data", function (chunk) {
bar.tick(chunk.length);
});
}
- res.on('end', function () {
- logger('\n');
+ res.on("end", function () {
+ logger("\n");
logger("Unzipping Sauce-Connect-latest.zip");
setTimeout(function () {
fs.createReadStream(outfile)
.pipe(unzip.Parse())
- .on('entry', function (entry) {
+ .on("entry", function (entry) {
if (entry.path.match(/Sauce-Connect\.jar$/)) {
logger("Saving Sauce-Connect.jar");
var jar = fs.createWriteStream(jarfile);
- entry.on('end', function (err) {
+ entry.on("end", function (err) {
// write queued data before closing the stream
logger("Removing Sauce-Connect-latest.zip");
fs.unlink(outfile, function (err) {
@@ -108,17 +108,17 @@ function run(options, callback) {
args.push("-P", options.port);
}
- if(options.logfile) {
- args.push('-l',options.logfile);
- }
+ if (options.logfile) {
+ args.push("-l", options.logfile);
+ }
if (options.tunnelIdentifier) {
- args.push('--tunnel-identifier', options.tunnelIdentifier);
+ args.push("--tunnel-identifier", options.tunnelIdentifier);
}
child = spawn("java", args);
child.stdout.on("data", function (data) {
- var connectingText = 'Please wait for "You may start your tests" to start your tests',
+ var connectingText = "Please wait for 'You may start your tests' to start your tests",
readyText = "Connected! You may start your tests",
outdatedText = "This version of Sauce Connect is outdated",
errorText = "Exception: ",
@@ -144,7 +144,7 @@ function run(options, callback) {
callback(new Error(data), child);
}
});
- child.on('exit', function (code, signal) {
+ child.on("exit", function (code, signal) {
if (code > 0) {
callback(new Error("Could not start Sauce Connect. Exit code " + code));
}
@@ -153,7 +153,7 @@ function run(options, callback) {
openProcesses.push(child);
child.close = function () {
- child.kill('SIGTERM');
+ child.kill("SIGTERM");
};
}
@@ -180,7 +180,7 @@ function downloadAndStartProcess(options, callback) {
} else {
// The file is already being downloaded
// by another process, lets poll until
- // it's available to be used
+ // it"s available to be used
setTimeout(function () {
downloadAndStartProcess(options, callback);
}, 1000);
View
@@ -21,7 +21,7 @@
},
"dependencies": {
"unzip": "0.0.4",
- "progress": "~0.1.0"
+ "progress": "~1.0.0"
},
"devDependencies": {
"mocha": "~1.7.0",
@@ -1,59 +1,58 @@
-var sauceConnectLauncher = require('../lib/sauce-connect-launcher'),
- expect = require('expect.js'),
- fs = require('fs'),
- path = require('path');
-
-describe('Sauce Connect Launcher', function () {
- var removeSauceConnect = function (done) {
- try {
- fs.unlinkSync(path.normalize(__dirname + '/../lib/Sauce-Connect.jar'));
- } catch (e) { }
- done();
- };
-
- before(removeSauceConnect);
- after(removeSauceConnect);
-
- it('should download Sauce Connect', function (done) {
- // We need to allow enough time for downloading Sauce Connect
- this.timeout(3600 * 10000);
- var log = [];
- sauceConnectLauncher({
- // We wont use real credentials, the point is to
- // know that we have the required jar to connect to
- // sauce
- username: 'bermi',
- accessKey: '12345678-1234-1234-1234-1234567890ab',
- verbose: true,
- logger: function (message) {
- console.log('[info] ', message);
- log.push(message);
- }
- }, function (err, sauceConnectProcess) {
-
- sauceConnectProcess.close();
-
- // Expected command sequence
- expect(log).to.be.eql([
- 'Missing Sauce Connect local proxy, downloading dependency',
- 'This will only happen once.',
- 'Downloading ',
- undefined,
- '\n',
- 'Unzipping Sauce-Connect-latest.zip',
- 'Saving Sauce-Connect.jar',
- 'Removing Sauce-Connect-latest.zip',
- 'Sauce Connect installed correctly',
- 'Opening local tunnel using Sauce Connect',
- 'Creating tunnel with Sauce Labs',
- 'Invalid Sauce Connect Credentials'
- ]);
-
- expect(err).to.be.an(Error);
-
- done();
- });
- });
-
-});
+var sauceConnectLauncher = require("../"),
+ expect = require("expect.js"),
+ fs = require("fs"),
+ path = require("path");
+
+describe("Sauce Connect Launcher", function () {
+ var removeSauceConnect = function (done) {
+ try {
+ fs.unlinkSync(path.normalize(__dirname + "/../lib/Sauce-Connect-latest.jar"));
+ } catch (e) { }
+ done();
+ };
+
+ before(removeSauceConnect);
+ after(removeSauceConnect);
+
+ it("should download Sauce Connect", function (done) {
+ // We need to allow enough time for downloading Sauce Connect
+ this.timeout(3600 * 10000);
+ var log = [];
+ sauceConnectLauncher({
+ // We wont use real credentials, the point is to
+ // know that we have the required jar to connect to
+ // sauce
+ username: "bermi",
+ accessKey: "12345678-1234-1234-1234-1234567890ab",
+ verbose: true,
+ logger: function (message) {
+ console.log("[info] ", message);
+ log.push(message);
+ }
+ }, function (err, sauceConnectProcess) {
+
+ sauceConnectProcess.close();
+
+ // Expected command sequence
+ expect(log).to.be.eql([
+ "Missing Sauce Connect local proxy, downloading dependency",
+ "This will only happen once.",
+ "Downloading ",
+ undefined,
+ "\n",
+ "Unzipping Sauce-Connect-latest.zip",
+ "Saving Sauce-Connect.jar",
+ "Removing Sauce-Connect-latest.zip",
+ "Sauce Connect installed correctly",
+ "Opening local tunnel using Sauce Connect",
+ "Invalid Sauce Connect Credentials"
+ ]);
+
+ expect(err).to.be.an(Error);
+
+ done();
+ });
+ });
+
+});

0 comments on commit 202d543

Please sign in to comment.