Skip to content
Browse files

Simplify download command - fix tests

  • Loading branch information...
1 parent 2038555 commit bf6247500f2cb9375eaf5459c3f962b20ad42acc @lightsofapollo lightsofapollo committed Jun 11, 2013
Showing with 55 additions and 52 deletions.
  1. +1 −0 .gitignore
  2. +2 −2 Makefile
  3. +10 −6 README.md
  4. +3 −12 examples/download-b2g/index.js
  5. +3 −12 examples/download-firefox/index.js
  6. +28 −10 lib/download.js
  7. +0 −1 lib/extract.js
  8. +2 −2 test/detectos-test.js
  9. +6 −7 test/download-test.js
View
1 .gitignore
@@ -1 +1,2 @@
/node_modules
+.DS_Store
View
4 Makefile
@@ -1,9 +1,9 @@
.PHONY: test
test:
./node_modules/mocha/bin/mocha --ui tdd \
- test/index-test.js \
+ test/detect-os.js \
test/extract-test.js
.PHONY: test-full
test-full:
- ./node_modules/mocha/bin/mocha --ui tdd
+ ./node_modules/mocha/bin/mocha --reporter spec --ui tdd -t 100s
View
16 README.md
@@ -11,11 +11,9 @@ var moz = require('mozilla-download');
moz.detectOS('firefox'); // platform for firefox
moz.detectOS('b2g'); // platform for b2g
-// download firefox nightly
+// download firefox
moz.download(
'firefox', // product can be either firefox or b2g
- moz.detectOS('firefox'), // helper to determine OS based on process see firefox-get for options
- 'nightly', // channel
__dirname + '/firefox', // save target
functon(err, path) {
// path is the same as save targe
@@ -25,16 +23,22 @@ moz.download(
// download b2g desktop nightly
moz.download(
'b2g', // product can be either firefox or b2g
- moz.detectOS('b2g'), // helper to determine OS based on process see firefox-get for options
- 'nightly', // channel
__dirname + '/b2g', // save target
functon(err, path) {
// path is the same as save targe
}
);
-```
+// with options
+moz.download(
+ 'b2g',
+ __dirname,
+ // see firefox-get
+ { version: 'xxx', os: 'xxx' }
+);
+
+```
## License
View
15 examples/download-b2g/index.js
@@ -3,19 +3,13 @@ var moz = require('../../index'),
spawn = require('child_process').spawn,
fs = require('fs');
-var os = moz.detectOS('b2g');
-
function download(callback) {
if (fs.existsSync(binaryPath)) {
return process.nextTick(callback);
}
- console.log('download start', os);
-
moz.download(
'b2g',
- os,
- 'nightly',
binaryPath,
function(err, path) {
if (err) throw err;
@@ -26,16 +20,13 @@ function download(callback) {
function launch() {
var bin = 'b2g-bin';
-
- if (os.indexOf('mac') === 0)
+ if (process.platform.indexOf('darwin') === 0)
bin = 'Contents/MacOS/b2g-bin';
console.log('launching binary', bin);
-
- var process = spawn(binaryPath + bin);
-
+ var child = spawn(binaryPath + bin);
setTimeout(function() {
- process.kill();
+ child.kill();
}, 5000);
}
View
15 examples/download-firefox/index.js
@@ -3,19 +3,13 @@ var moz = require('../../index'),
spawn = require('child_process').spawn,
fs = require('fs');
-var os = moz.detectOS('firefox');
-
function download(callback) {
if (fs.existsSync(binaryPath)) {
return process.nextTick(callback);
}
- console.log('download start', os);
-
moz.download(
'firefox',
- os,
- 'nightly',
binaryPath,
function(err, path) {
if (err) throw err;
@@ -26,16 +20,13 @@ function download(callback) {
function launch() {
var bin = 'firefox-bin';
-
- if (os.indexOf('mac') === 0)
+ if (process.platform.indexOf('darwin') === 0)
bin = 'Contents/MacOS/firefox';
console.log('launching binary', bin);
-
- var process = spawn(binaryPath + bin);
-
+ var child = spawn(binaryPath + bin);
setTimeout(function() {
- process.kill();
+ child.kill();
}, 5000);
}
View
38 lib/download.js
@@ -3,24 +3,42 @@ var mozget = require('firefox-get'),
fs = require('fs'),
http = require('http'),
debug = require('debug')('mozilla-runner:download'),
+ detectOS = require('./detectos'),
extract = require('./extract');
+var DEFAULT_VERSION = 'nightly';
+
/**
* Downloads a mozilla product to a given path.
*
- * runner.download(
- * 'b2g',
- * runner.detectOS(),
- * 'release',
- * path,
- * function() {
- * // do stuff with runtime
- * }
- * );
+ * runner.download('firefox', path, function(err) {
+ * // do amazing things!
+ * });
+ *
+ * Options:
+ * - os: to download for (see firefox-get)
+ * - version: or channel (like 18 or 'nightly')
*
+ * @param {String} product to download (like firefox)
+ * @param {String} path to download file to.
+ * @param {Object} [options] optional set of configuration options.
+ * @param {Function} callback [err, path];
*/
-function download(product, os, version, path, callback) {
+function download(product, path, options, callback) {
+ if (typeof options === 'function') {
+ callback = options;
+ options = undefined;
+ }
+
+ if (!options) {
+ options = {};
+ }
+
+ var os = options.os || detectOS(product);
+ var version = options.version || DEFAULT_VERSION;
+
debug('download', product, os, version);
+
function saveToTemp(err, url) {
if (err) return callback(err);
debug('got ftp download location', url);
View
1 lib/extract.js
@@ -99,7 +99,6 @@ function extractDmg(product, source, target, callback) {
*/
function unmount(mountPath) {
debug('dmg', 'unmount', mountPath);
- console.log(mountPath);
dmg.unmount(mountPath, function(err) {
if (err) return callback(err);
callback(null, target);
View
4 test/detectos-test.js
@@ -1,5 +1,5 @@
suite('detect', function() {
- var runner = require('../lib/detectos');
+ var detectOS = require('../lib/detectos');
var assert = require('assert');
suite('#detectOS', function() {
@@ -18,7 +18,7 @@ suite('detect', function() {
var name = input.platform + ' arch ' + input.arch;
test(name, function() {
- assert.equal(runner.detectOS('b2g', input), expected);
+ assert.equal(detectOS('b2g', input), expected);
});
});
});
View
13 test/download-test.js
@@ -1,6 +1,6 @@
suite('download', function() {
var assert = require('assert');
- var runner = require('../lib/download');
+ var runner = require('../index');
var fs = require('fs');
suite('mac64', function() {
@@ -9,21 +9,23 @@ suite('download', function() {
return test('cannot run mac64 tests on non darwin platforms');
test('package expansion', function(done) {
- runner.download('b2g', 'mac64', 'release', path, function(err, path) {
+ var options = { os: 'mac64', version: 'release' };
+ runner.download('b2g', path, options, function(err, path) {
var stat = fs.statSync(path);
assert.ok(stat.isDirectory());
done();
});
});
});
- suite.only('linux-x86', function() {
+ suite('linux-x86', function() {
var path = __dirname + '/linux-out/';
if (process.platform === 'win32')
return test('cannot run on windows');
test('package expansion', function(done) {
- runner.download('b2g', 'linux-x86_64', 'release', path, function(err, path) {
+ var options = { os: 'linux-x86_64', version: 'release' };
+ runner.download('b2g', path, options, function(err, path) {
var stat = fs.statSync(path);
assert.ok(stat.isDirectory());
done();
@@ -32,7 +34,4 @@ suite('download', function() {
});
- suite('win32', function() {
- });
-
});

0 comments on commit bf62475

Please sign in to comment.
Something went wrong with that request. Please try again.