add tests work on a refactor

This commit is contained in:
Tommy Parnell
2016-03-06 12:32:44 -05:00
parent 4c41b4a216
commit 03971fd151
7 changed files with 196 additions and 12 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
node_modules
coverage

View File

@@ -2,6 +2,11 @@ var gulp = require('gulp');
var unzip = require('gulp-unzip');
var request = require('request');
var fs = require('fs');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var isparta = require('isparta');
require('babel-core/register');
gulp.task('download', function () {
return request('http://wixtoolset.org/downloads/v3.11.0.129/wix311-binaries.zip').pipe(fs.createWriteStream('wixToolset.zip'));
});
@@ -11,3 +16,23 @@ gulp.task('getwix',['download'], function(){
.pipe(unzip())
.pipe(gulp.dest('./lib/wixFiles'));
});
gulp.task('pre-test', function () {
return gulp.src('src/**/*.js')
// Covering files
.pipe(istanbul({
instrumenter: isparta.Instrumenter,
includeUntested: true}
))
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});
gulp.task('test', function(){
return gulp.src('test/unit/*.js')
.pipe(mocha())
.pipe(istanbul.writeReports());
//.pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } }));
//usemocha
});

View File

@@ -9,23 +9,26 @@
"scripts": {
"compile": "babel src --out-dir lib",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"prepublish": "npm run compile",
"test": "babel-node ./node_modules/.bin/isparta cover _mocha"
"prepublish": "npm run compile"
},
"dependencies": {
"underscore": "^1.8.3"
"dependencies": {
"lodash": "^4.6.1"
},
"devDependencies": {
"babel-cli": "*",
"babel-core": "^6.6.5",
"babel-preset-es2015-node4": "*",
"coveralls": "*",
"chai": "*",
"isparta": "*",
"mocha": "*",
"sinon": "*",
"coveralls": "*",
"gulp": "^3.9.1",
"gulp-istanbul": "^0.10.3",
"gulp-mocha": "^2.2.0",
"gulp-unzip": "^0.1.3",
"request": "^2.69.0"
"isparta": "^4.0.0",
"jscover": "^1.0.0",
"mocha": "*",
"mocha-lcov-reporter": "^1.2.0",
"request": "^2.69.0",
"sinon": "*"
}
}

47
src/CommandBuilder.js Normal file
View File

@@ -0,0 +1,47 @@
'use strict';
var fs = require('fs'),
_ = require('lodash'),
path = require('path');
var calculateCommands = function(options){
var commands = {
heatPath: options.heatPath || __dirname + "/wixFiles/heat.exe",
lightPath: options.lightPath || __dirname + "/wixFiles/light.exe",
candlePath: options.candlePath || __dirname + "/wixFiles/candle.exe"
}
if(options.version){
process.env.BUILD_VERSION = version;
}
if(options.heatCommands && _.isArray(options.heatCommands)){
commands.heatCommands = options.heatCommands
}
else{
if(options.heatFiles && _.isArray(options.heatFiles) && options.heatFiles.length > 0 ){
commands.heatCommands = _.map(options.heatFiles, (file)=>`@${path.normalize(file)}`) //heat commands can be empty as heat is a harvester and thus optional
}
}
if(options.candleCommands && _.isArray(options.candleCommands)){
commands.candleCommands = options.candleCommands
}
else{
if(!options.candleFiles || !_.isArray(options.candleFiles) || options.candleFiles.length < 1 ){
throw "light files are required if light commands are not specified";
}
commands.candleCommands = _.map(options.candleFiles, (file)=>`@${path.normalize(file)}`)
}
if(options.lightCommands && _.isArray(options.lightCommands)){
commands.lightCommands = options.lightCommands
}
else{
if(!options.lightFiles || !_.isArray(options.lightFiles) || options.lightFiles.length < 1 ){
throw "light files are required if light commands are not specified";
}
commands.lightCommands = _.map(options.lightFiles, (file)=>`@${path.normalize(file)}`)
}
return commands;
};
module.exports = calculateCommands;

View File

@@ -3,7 +3,7 @@
/* jshint -W097 */
'use strict';
var fs = require('fs'),
_ = require('underscore'),
_ = require('lodash'),
path = require('path'),
child_process = require('child_process');

View File

@@ -0,0 +1,109 @@
var assert = require('chai').assert;
var expect = require('chai').expect;
var commandBuilder = require('../../src/CommandBuilder');
describe('CommandBuilderWorks', function(){
it('Should not throw when files are passed in', function(){
var testObject = {
heatFiles: ['tst'],
candleFiles: ['awesome'],
lightFiles: ['filesss']
};
commandBuilder(testObject)
});
it('Should not throw when commands are passed in', function(){
var testObject = {
heatCommands: ['tst'],
candleCommands: ['awesome'],
lightCommands: ['filesss']
};
commandBuilder(testObject)
});
it('Should Throw if missing light files', function(){
var testObject = {
heatFiles: ['tst'],
candleFiles: ['awesome']
};
assert.throws(()=>commandBuilder(testObject));
});
it('Should Throw if missing candle files', function(){
var testObject = {
heatFiles: ['tst'],
lightFiles: ['awesome']
};
assert.throws(()=>commandBuilder(testObject));
});
it('Should not Throw if missing heat files or commands', function(){
var testObject = {
lightFiles: ['awesome'],
candleFiles: ['awesome']
};
assert.doesNotThrow(()=>commandBuilder(testObject));
});
it('should run as expected with files', function(){
var testObject = {
lightFiles: ['lightfile'],
candleFiles: ['candlefile'],
heatFiles: ['heatfile']
};
var result = commandBuilder(testObject);
expect(result.heatCommands).to.eql(['@heatfile']);
expect(result.lightCommands).to.eql(['@lightfile']);
expect(result.candleCommands).to.eql(['@candlefile']);
});
it('should run as expected with commands', function(){
var testObject = {
lightCommands: ['lightfile'],
candleCommands: ['candlefile'],
heatCommands: ['heatfile']
};
var result = commandBuilder(testObject);
expect(result.heatCommands).to.eql(['heatfile']);
expect(result.lightCommands).to.eql(['lightfile']);
expect(result.candleCommands).to.eql(['candlefile']);
});
it('should use alternate heat location', function(){
var testObject = {
lightCommands: ['lightfile'],
candleCommands: ['candlefile'],
heatCommands: ['heatfile'],
heatPath: "../awesome"
};
var result = commandBuilder(testObject);
expect(result.heatPath).to.eql("../awesome");
});
it('should use alternate candle location', function(){
var testObject = {
lightCommands: ['lightfile'],
candleCommands: ['candlefile'],
heatCommands: ['heatfile'],
candlePath: "../awesome"
};
var result = commandBuilder(testObject);
expect(result.candlePath).to.eql("../awesome");
});
it('should use alternate light location', function(){
var testObject = {
lightCommands: ['lightfile'],
candleCommands: ['candlefile'],
heatCommands: ['heatfile'],
lightPath: "../awesome"
};
var result = commandBuilder(testObject);
expect(result.lightPath).to.eql("../awesome");
});
});

View File

@@ -1 +0,0 @@
import { assert } from 'chai';