Commit b1188bc9 by xzyfer

POC for adding unit test coverage to install

The installer is getting more complicated. The core of it is a http
request which makes testing it difficult/messy. Pulling out core
logic into small util functions that we can unit test would give me
much more confidence moving forward.

I would prefer we don't export functions from scripts so people don't
start relying on undocumented APIs. This is why I opted for helper
utils but I'm not committed to them.
parent aec7049b
......@@ -9,7 +9,7 @@ var fs = require('fs'),
sass = require('../lib/extensions'),
request = require('request'),
log = require('npmlog'),
pkg = require('../package.json');
userAgent = require('./util/useragent');
/**
* Download file, if succeeds save, if not delete
......@@ -53,7 +53,7 @@ function download(url, dest, cb) {
proxy: getProxy(),
timeout: 60000,
headers: {
'User-Agent': getUserAgent(),
'User-Agent': userAgent(),
}
};
......@@ -95,18 +95,6 @@ function download(url, dest, cb) {
}
/**
* A custom user agent use for binary downloads.
*
* @api private
*/
function getUserAgent() {
return [
'node/', process.version, ' ',
'node-sass-installer/', pkg.version
].join('');
}
/**
* Determine local proxy settings
*
* @param {Object} options
......
var pkg = require('../../package.json');
/**
* A custom user agent use for binary downloads.
*
* @api private
*/
module.exports = function() {
return [
'node/', process.version, ' ',
'node-sass-installer/', pkg.version
].join('');
};
var assert = require('assert'),
pkg = require('../package.json'),
ua = require('../scripts/util/useragent');
describe('util', function() {
describe('useragent', function() {
it('should look as we expect', function() {
var reNode = 'node/' + process.version;
var reSass = 'node-sass-installer/' + pkg.version;
var reUA = new RegExp('^' + reNode + ' ' + reSass + '$');
assert.ok(reUA.test(ua()));
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment