From 03971fd151b69ed980ba0997c636d930dd507587 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Sun, 6 Mar 2016 12:32:44 -0500 Subject: [PATCH 1/4] add tests work on a refactor --- .gitignore | 1 + Gulpfile.js | 25 +++++++ package.json | 23 ++++--- src/CommandBuilder.js | 47 +++++++++++++ src/exec.js | 2 +- test/unit/CommandBuilder.test.js | 109 +++++++++++++++++++++++++++++++ test/unit/index.test.js | 1 - 7 files changed, 196 insertions(+), 12 deletions(-) create mode 100644 src/CommandBuilder.js create mode 100644 test/unit/CommandBuilder.test.js delete mode 100644 test/unit/index.test.js diff --git a/.gitignore b/.gitignore index 3c3629e..ba2a97b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +coverage diff --git a/Gulpfile.js b/Gulpfile.js index a7d2b10..063e558 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -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 +}); diff --git a/package.json b/package.json index b175340..4243481 100644 --- a/package.json +++ b/package.json @@ -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": "*" } } diff --git a/src/CommandBuilder.js b/src/CommandBuilder.js new file mode 100644 index 0000000..3e87bea --- /dev/null +++ b/src/CommandBuilder.js @@ -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; diff --git a/src/exec.js b/src/exec.js index 9f5b2d5..fe4de5b 100644 --- a/src/exec.js +++ b/src/exec.js @@ -3,7 +3,7 @@ /* jshint -W097 */ 'use strict'; var fs = require('fs'), - _ = require('underscore'), + _ = require('lodash'), path = require('path'), child_process = require('child_process'); diff --git a/test/unit/CommandBuilder.test.js b/test/unit/CommandBuilder.test.js new file mode 100644 index 0000000..ccfcf7d --- /dev/null +++ b/test/unit/CommandBuilder.test.js @@ -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"); + }); + +}); diff --git a/test/unit/index.test.js b/test/unit/index.test.js deleted file mode 100644 index e69fded..0000000 --- a/test/unit/index.test.js +++ /dev/null @@ -1 +0,0 @@ -import { assert } from 'chai'; From e2ad38a5815c3af02077ea1fb08e6d5b98b4d3ff Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Sat, 12 Mar 2016 11:49:22 -0500 Subject: [PATCH 2/4] more refactors --- Gulpfile.js | 35 ++++++- package.json | 4 +- src/CommandBuilder.js | 7 +- src/exec.js | 151 ++++++++++--------------------- test/unit/CommandBuilder.test.js | 2 +- 5 files changed, 84 insertions(+), 115 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index 063e558..7c7dace 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -5,7 +5,7 @@ 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')); @@ -16,12 +16,39 @@ gulp.task('getwix',['download'], function(){ .pipe(unzip()) .pipe(gulp.dest('./lib/wixFiles')); }); +var paths = { + server: { + scripts: ['src/**/*.js'], + tests: ['test/**/*.js'], + coverage: 'coverage/' + } +}; + +gulp.task('test-coverage-server', function(cb) { + var coverageDir = paths.server.coverage; + gulp.src(paths.server.scripts) + .pipe(istanbul({ // Covering files + instrumenter: isparta.Instrumenter, + includeUntested: true + })) + .pipe(istanbul.hookRequire()) // Force `require` to return covered files + .on('finish', function() { + gulp.src(paths.server.tests, {read: false}) + .pipe(mocha({reporter: 'spec'})) + .pipe(istanbul.writeReports({ + dir: coverageDir, + reportOpts: {dir: coverageDir}, + reporters: ['text', 'text-summary', 'json', 'html'] + })) + .on('end', cb); + }); +}); gulp.task('pre-test', function () { - return gulp.src('src/**/*.js') + return gulp.src(['src/CommandBuilder.js']) // Covering files .pipe(istanbul({ - instrumenter: isparta.Instrumenter, + // instrumenter: isparta.Instrumenter, includeUntested: true} )) @@ -29,7 +56,7 @@ gulp.task('pre-test', function () { .pipe(istanbul.hookRequire()); }); -gulp.task('test', function(){ +gulp.task('test',['pre-test'], function(){ return gulp.src('test/unit/*.js') .pipe(mocha()) .pipe(istanbul.writeReports()); diff --git a/package.json b/package.json index 4243481..94bd6d3 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,11 @@ "scripts": { "compile": "babel src --out-dir lib", "coveralls": "cat ./coverage/lcov.info | coveralls", - "prepublish": "npm run compile" + "prepublish": "npm run compile", + "test": "./node_modules/.bin/isparta cover node_modules/mocha/bin/_mocha" }, "dependencies": { + "child-process-promise": "^1.1.0", "lodash": "^4.6.1" }, "devDependencies": { diff --git a/src/CommandBuilder.js b/src/CommandBuilder.js index 3e87bea..3a4c11f 100644 --- a/src/CommandBuilder.js +++ b/src/CommandBuilder.js @@ -3,12 +3,11 @@ 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" + heatPath: options.heatPath || path.normalize(__dirname + "/wixFiles/heat.exe"), + lightPath: options.lightPath || path.normalize(__dirname + "/wixFiles/light.exe"), + candlePath: options.candlePath || path.normalize(__dirname + "/wixFiles/candle.exe") } if(options.version){ process.env.BUILD_VERSION = version; diff --git a/src/exec.js b/src/exec.js index fe4de5b..0efba27 100644 --- a/src/exec.js +++ b/src/exec.js @@ -5,9 +5,10 @@ var fs = require('fs'), _ = require('lodash'), path = require('path'), - child_process = require('child_process'); + commandBuilder = require('./CommandBuilder.js'), + spawn = require('child-process-promise').spawn; -var processResults = function (stdout, stderr) { +var processResults = function (stdout) { if(stdout && _.isArray(stdout)){ _.chain(stdout) .filter((item)=>item && item.length > 0) @@ -17,114 +18,54 @@ var processResults = function (stdout, stderr) { else if(stdout && _.isString(stdout) && stdout.length > 0){ console.log(stdout); } - if(stderr && _.isString(stderr) && stderr.length > 0){ - console.log(stderr); - } }; + +var processError = function(err, cb){ + console.log(err); + if(cb && _.isFunction(cb) && err){ + cb(err) + } + else if(err){ + throw err + } +} + +var processConsole = function processConsole(childProcess) { + if(childProcess && childProcess.stdout){ + childProcess.stdout.on('data', (data)=>processResults(data.toString())); + } + if(childProcess && childProcess.stderr){ + childProcess.stderr.on('data', (data)=>processResults(data.toString())); + } + +}; + var main = function (options, callback) { - var heatFiles = options.heatFiles; - var candleFiles = options.candleFiles; - var lightFiles = options.lightFiles; - var heatCommands = options.heatCommands || null; - var candleCommands = options.candleCommands || null; - var lightCommands = options.lightCommands || null; - var heatPath = options.heatPath || __dirname + "/wixFiles/heat.exe"; - var lightPath = options.lightPath || __dirname + "/wixFiles/light.exe"; - var candlePath = options.candlePath || __dirname + "/wixFiles/candle.exe"; - var cb = callback; - var version = options.version; - if(version){ - process.env.BUILD_VERSION = version; - } - if(!heatCommands){ - if(!heatFiles || !_.isArray(heatFiles) || heatFiles.length < 1 ){ - throw "heat files are required if no commands are passed"; - } - checkFiles(heatFiles); - } - - if(!candleCommands){ - - if(!candleFiles || !_.isArray(candleFiles) || candleFiles.length < 1 ){ - throw "candle files are required"; + var commands = commandBuilder(options); + //todo redo this a little... + if(commands.heatCommands){ + return spawn(commands.heatPath, commands.heatCommands) + .progress(processConsole) + .then(()=>spawn(commands.candlePath, commands.candleCommands)) + .progress(processConsole) + .then(()=>spawn(commands.lightPath, commands.lightCommands)) + .progress(processConsole) + .then(()=>{ + if(callback && _.isFunction(callback)){ + callback(); } - - checkFiles(candleCommands); - - } - - if(!lightCommands){ - - if(!lightFiles || !_.isArray(lightFiles) || lightFiles.length < 1 ){ - throw "light files are required"; - } - - checkFiles(lightFiles); - - } - - return child_process.execFile(path.normalize(heatPath), heatCommands? heatCommands: _.map(heatFiles, (file)=>`@${path.normalize(file)}`), (err, stdout, stderr)=>{ - processResults(stdout, stderr); - if(err){ - if(cb){ - return cb(err); - }else{ - throw err; - } - - } - - return child_process.execFile(path.normalize(candlePath), candleCommands? candleCommands: _.map(candleFiles, (file)=>`@${path.normalize(file)}`), (err, stdout, stderr)=>{ - processResults(stdout, stderr); - if(err){ - if(cb){ - return cb(err); - }else{ - throw err; - } - - } - - return child_process.execFile(path.normalize(lightPath), lightCommands? lightCommands: _.map(lightFiles, (file)=>`@${path.normalize(file)}`), (err, stdout, stderr)=>{ - processResults(stdout, stderr); - if(err){ - if(cb){ - return cb(err); - }else{ - throw err; - } - - } - if(cb){ - return cb(); - } - - }); - + }); + } + return spawn(commands.candlePath, commands.candleCommands) + .progress(processConsole) + .then(()=>spawn(commands.lightPath, commands.lightCommands)) + .progress(processConsole) + .then(()=>{ + if(callback && _.isFunction(callback)){ + callback(); + } }); - - }); -}; - -var checkFiles = function(files){ - _.each(files, (file)=>{ - if(!checkFile(file)){ - throw "error finding file" + file; - } - }); -}; -var checkFile = function (file) { - if (!file || file.length < 1) { - return false; - } - try { - fs.accessSync(path.normalize(file), fs.R_OK); //will error if doesnt exist - //todo async? - return true; - } catch (error) { - return false; - } }; module.exports = main; diff --git a/test/unit/CommandBuilder.test.js b/test/unit/CommandBuilder.test.js index ccfcf7d..7400575 100644 --- a/test/unit/CommandBuilder.test.js +++ b/test/unit/CommandBuilder.test.js @@ -1,6 +1,6 @@ var assert = require('chai').assert; var expect = require('chai').expect; -var commandBuilder = require('../../src/CommandBuilder'); +var commandBuilder = require('../../src/CommandBuilder.js'); describe('CommandBuilderWorks', function(){ From 28ed26dd2987d1309476b733187d8f0dcf7e5780 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Sat, 12 Mar 2016 17:49:03 -0500 Subject: [PATCH 3/4] heavy refactor --- .gitignore | 2 ++ Gulpfile.js | 62 ++++++++------------------------ README.md | 6 ++++ package.json | 5 ++- src/CommandBuilder.js | 4 +++ src/exec.js | 56 ++++++++++------------------- test/mocha.opts | 2 +- test/unit/CommandBuilder.test.js | 12 ++++++- 8 files changed, 61 insertions(+), 88 deletions(-) diff --git a/.gitignore b/.gitignore index ba2a97b..1a36f14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules coverage +wixToolset.zip +output/ diff --git a/Gulpfile.js b/Gulpfile.js index 7c7dace..e601cbf 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -4,8 +4,10 @@ var request = require('request'); var fs = require('fs'); var mocha = require('gulp-mocha'); var istanbul = require('gulp-istanbul'); -var isparta = require('isparta'); - +var isparta = require('isparta') +var exec = require('child_process').execSync; +var hydroexec = require('./lib/exec.js'); +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')); @@ -16,50 +18,16 @@ gulp.task('getwix',['download'], function(){ .pipe(unzip()) .pipe(gulp.dest('./lib/wixFiles')); }); -var paths = { - server: { - scripts: ['src/**/*.js'], - tests: ['test/**/*.js'], - coverage: 'coverage/' - } -}; +//todo use gulp-istanbul and gulp-mocha +gulp.task('test', function(){ + return exec('npm run test'); +}) + +gulp.task('wixtest', ['getwix'], function(){ + return hydroexec({ + heatFiles: ['test/integration/heat.rsp'], + candleFiles: ['test/integration/candle.rsp'], + lightFiles: ['test/integration/light.rsp'] + }); -gulp.task('test-coverage-server', function(cb) { - var coverageDir = paths.server.coverage; - gulp.src(paths.server.scripts) - .pipe(istanbul({ // Covering files - instrumenter: isparta.Instrumenter, - includeUntested: true - })) - .pipe(istanbul.hookRequire()) // Force `require` to return covered files - .on('finish', function() { - gulp.src(paths.server.tests, {read: false}) - .pipe(mocha({reporter: 'spec'})) - .pipe(istanbul.writeReports({ - dir: coverageDir, - reportOpts: {dir: coverageDir}, - reporters: ['text', 'text-summary', 'json', 'html'] - })) - .on('end', cb); - }); -}); - -gulp.task('pre-test', function () { - return gulp.src(['src/CommandBuilder.js']) - // Covering files - .pipe(istanbul({ - // instrumenter: isparta.Instrumenter, - includeUntested: true} - - )) - // Force `require` to return covered files - .pipe(istanbul.hookRequire()); -}); - -gulp.task('test',['pre-test'], function(){ - return gulp.src('test/unit/*.js') - .pipe(mocha()) - .pipe(istanbul.writeReports()); - //.pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } })); - //usemocha }); diff --git a/README.md b/README.md index e172961..9a74f1e 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,12 @@ Default: `undefined` Sets the BUILD_VERSION environment variable to version before calling heat, candle, and light +#### suppressValidation + +Type: `bool` +Default: `false` + +If true this will supress ICE validation checks during the linking process. ## License diff --git a/package.json b/package.json index 94bd6d3..f971e98 100644 --- a/package.json +++ b/package.json @@ -14,15 +14,18 @@ }, "dependencies": { "child-process-promise": "^1.1.0", - "lodash": "^4.6.1" + "lodash": "^4.6.1", + "q": "^1.4.1" }, "devDependencies": { "babel-cli": "*", "babel-core": "^6.6.5", + "babel-preset-es2015": "^6.6.0", "babel-preset-es2015-node4": "*", "chai": "*", "coveralls": "*", "gulp": "^3.9.1", + "gulp-babel": "^6.1.2", "gulp-istanbul": "^0.10.3", "gulp-mocha": "^2.2.0", "gulp-unzip": "^0.1.3", diff --git a/src/CommandBuilder.js b/src/CommandBuilder.js index 3a4c11f..49fa7d7 100644 --- a/src/CommandBuilder.js +++ b/src/CommandBuilder.js @@ -9,6 +9,7 @@ var calculateCommands = function(options){ lightPath: options.lightPath || path.normalize(__dirname + "/wixFiles/light.exe"), candlePath: options.candlePath || path.normalize(__dirname + "/wixFiles/candle.exe") } + if(options.version){ process.env.BUILD_VERSION = version; } @@ -40,6 +41,9 @@ var calculateCommands = function(options){ } commands.lightCommands = _.map(options.lightFiles, (file)=>`@${path.normalize(file)}`) } + if(options.suppressValidation){ + commands.lightCommands.unshift('-sval'); + } return commands; }; diff --git a/src/exec.js b/src/exec.js index 0efba27..389f5fe 100644 --- a/src/exec.js +++ b/src/exec.js @@ -6,66 +6,46 @@ var fs = require('fs'), _ = require('lodash'), path = require('path'), commandBuilder = require('./CommandBuilder.js'), - spawn = require('child-process-promise').spawn; - -var processResults = function (stdout) { - if(stdout && _.isArray(stdout)){ - _.chain(stdout) - .filter((item)=>item && item.length > 0) - .each((item)=>console.log(item)) - .value(); - } - else if(stdout && _.isString(stdout) && stdout.length > 0){ - console.log(stdout); - } - -}; + spawn = require('child-process-promise').spawn, + Q = require('q'); var processError = function(err, cb){ - console.log(err); if(cb && _.isFunction(cb) && err){ cb(err) } else if(err){ - throw err + throw err.message; } } var processConsole = function processConsole(childProcess) { if(childProcess && childProcess.stdout){ - childProcess.stdout.on('data', (data)=>processResults(data.toString())); + childProcess.stdout.on('data', (data)=>console.log(data.toString())); } if(childProcess && childProcess.stderr){ - childProcess.stderr.on('data', (data)=>processResults(data.toString())); + childProcess.stderr.on('data', (data)=>console.log(data.toString())); } }; var main = function (options, callback) { var commands = commandBuilder(options); + var heat = null; + console.log(commands); //todo redo this a little... if(commands.heatCommands){ - return spawn(commands.heatPath, commands.heatCommands) - .progress(processConsole) - .then(()=>spawn(commands.candlePath, commands.candleCommands)) - .progress(processConsole) - .then(()=>spawn(commands.lightPath, commands.lightCommands)) - .progress(processConsole) - .then(()=>{ - if(callback && _.isFunction(callback)){ - callback(); - } - }); + console.log(commands.heatPath, commands.heatCommands); + heat = spawn(commands.heatPath, commands.heatCommands) + .progress(processConsole); } - return spawn(commands.candlePath, commands.candleCommands) - .progress(processConsole) - .then(()=>spawn(commands.lightPath, commands.lightCommands)) - .progress(processConsole) - .then(()=>{ - if(callback && _.isFunction(callback)){ - callback(); - } - }); + heat = heat || Q.Promise(); + + return Q.all([heat]) + .then(()=>spawn(commands.candlePath, commands.candleCommands), (err)=>processError(err, callback)) + .progress(processConsole) + .then(()=>spawn(commands.lightPath, commands.lightCommands), (err)=>processError(err, callback)) + .progress(processConsole) + .fail((err)=>processError(err, callback)); }; module.exports = main; diff --git a/test/mocha.opts b/test/mocha.opts index 916505e..5d4ff46 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,3 +1,3 @@ -./test/unit/**/*.test.js +./test/unit/*.test.js --reporter spec --recursive diff --git a/test/unit/CommandBuilder.test.js b/test/unit/CommandBuilder.test.js index 7400575..539edc1 100644 --- a/test/unit/CommandBuilder.test.js +++ b/test/unit/CommandBuilder.test.js @@ -1,6 +1,6 @@ var assert = require('chai').assert; var expect = require('chai').expect; -var commandBuilder = require('../../src/CommandBuilder.js'); +var commandBuilder = require('../../src/CommandBuilder'); describe('CommandBuilderWorks', function(){ @@ -105,5 +105,15 @@ describe('CommandBuilderWorks', function(){ var result = commandBuilder(testObject); expect(result.lightPath).to.eql("../awesome"); }); + it('should suppress validations', function(){ + var testObject = { + lightCommands: ['lightfile'], + candleCommands: ['candlefile'], + heatCommands: ['heatfile'], + suppressValidation: true + }; + var result = commandBuilder(testObject); + expect(result.lightCommands).to.eql(['-sval', 'lightfile']); + }); }); From 7c7c6891fdca359350995143b8670163f27f9608 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Sat, 12 Mar 2016 23:20:17 -0500 Subject: [PATCH 4/4] refactor complete --- .gitignore | 1 + Gulpfile.js | 51 +++++++++++++++++++++--------- package.json | 11 ++++--- src/exec.js | 22 +++++-------- src/processConsole.js | 11 +++++++ test/integration/Product.wsx | 54 ++++++++++++++++++++++++++++++++ test/integration/candle.rsp | 5 +++ test/integration/heat.rsp | 7 +++++ test/integration/hydroexec.js | 14 +++++++++ test/integration/light.rsp | 8 +++++ test/unit/CommandBuilder.test.js | 4 +-- 11 files changed, 152 insertions(+), 36 deletions(-) create mode 100644 src/processConsole.js create mode 100644 test/integration/Product.wsx create mode 100644 test/integration/candle.rsp create mode 100644 test/integration/heat.rsp create mode 100644 test/integration/hydroexec.js create mode 100644 test/integration/light.rsp diff --git a/.gitignore b/.gitignore index 1a36f14..c6556c5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules coverage wixToolset.zip output/ +test-tmp/ diff --git a/Gulpfile.js b/Gulpfile.js index e601cbf..a5d7a39 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -1,3 +1,4 @@ +//require('babel-core/register'); var gulp = require('gulp'); var unzip = require('gulp-unzip'); var request = require('request'); @@ -5,29 +6,49 @@ var fs = require('fs'); var mocha = require('gulp-mocha'); var istanbul = require('gulp-istanbul'); var isparta = require('isparta') -var exec = require('child_process').execSync; -var hydroexec = require('./lib/exec.js'); -require('babel-core/register'); +var tap = require('gulp-tap'); +var coveralls = require('gulp-coveralls'); +var babel = require('gulp-babel'); gulp.task('download', function () { return request('http://wixtoolset.org/downloads/v3.11.0.129/wix311-binaries.zip').pipe(fs.createWriteStream('wixToolset.zip')); }); -gulp.task('getwix',['download'], function(){ +gulp.task('getwix',['download', 'prepublish'], function(){ return gulp.src("wixToolset.zip") .pipe(unzip()) - .pipe(gulp.dest('./lib/wixFiles')); + .pipe(gulp.dest('./lib/wixFiles')) + .pipe(gulp.dest('./test-tmp/wixFiles')); +}); +gulp.task('pre-test', function () { + return gulp.src('src/**/*.js') + // Covering files + .pipe(istanbul({Instrumenter: isparta.Instrumenter, includeUntested: true}), {read: false}) + // Force `require` to return covered files + .pipe(gulp.dest('test-tmp/')) + .pipe(istanbul.hookRequire()); }); -//todo use gulp-istanbul and gulp-mocha -gulp.task('test', function(){ - return exec('npm run test'); -}) -gulp.task('wixtest', ['getwix'], function(){ - return hydroexec({ - heatFiles: ['test/integration/heat.rsp'], - candleFiles: ['test/integration/candle.rsp'], - lightFiles: ['test/integration/light.rsp'] - }); +gulp.task('test', ['pre-test', 'getwix'], function () { + return gulp.src(['test/**/*.js']) + .pipe(mocha()) + // Creating the reports after tests ran + .pipe(istanbul.writeReports()) + // Enforce a coverage of at least 90% + .pipe(istanbul.enforceThresholds({ thresholds: { lines: 70 } })); +}); + +//todo use babel +gulp.task('prepublish', function(){ +gulp.src('src/**/*.js') +.pipe(babel({ + presets: ['es2015'] +})) +.pipe(gulp.dest('lib')); }); + +gulp.task('coveralls', ['test'], function(){ + gulp.src('coverage/**/lcov.info') + .pipe(coveralls()) +}); diff --git a/package.json b/package.json index f971e98..8254d5a 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,15 @@ { "name": "hydrocarbon", "description": "making windows installers great again", - "version": "0.1.2", + "version": "0.3.0", "main": "index.js", "author": "tparnell8", - "repository": "tparnell8/HydroCarbon", + "repository": "http://github.com/tparnell8/Hydrocarbon", "license": "MIT", "scripts": { - "compile": "babel src --out-dir lib", "coveralls": "cat ./coverage/lcov.info | coveralls", - "prepublish": "npm run compile", - "test": "./node_modules/.bin/isparta cover node_modules/mocha/bin/_mocha" + "prepublish": "./node_modules/.bin/gulp getwix", + "test": "./node_modules/.bin/gulp test" }, "dependencies": { "child-process-promise": "^1.1.0", @@ -26,8 +25,10 @@ "coveralls": "*", "gulp": "^3.9.1", "gulp-babel": "^6.1.2", + "gulp-coveralls": "^0.1.4", "gulp-istanbul": "^0.10.3", "gulp-mocha": "^2.2.0", + "gulp-tap": "^0.1.3", "gulp-unzip": "^0.1.3", "isparta": "^4.0.0", "jscover": "^1.0.0", diff --git a/src/exec.js b/src/exec.js index 389f5fe..45cdfd7 100644 --- a/src/exec.js +++ b/src/exec.js @@ -7,7 +7,8 @@ var fs = require('fs'), path = require('path'), commandBuilder = require('./CommandBuilder.js'), spawn = require('child-process-promise').spawn, - Q = require('q'); + Q = require('q'), + processConsole = require('./processConsole.js'); var processError = function(err, cb){ if(cb && _.isFunction(cb) && err){ @@ -18,21 +19,9 @@ var processError = function(err, cb){ } } -var processConsole = function processConsole(childProcess) { - if(childProcess && childProcess.stdout){ - childProcess.stdout.on('data', (data)=>console.log(data.toString())); - } - if(childProcess && childProcess.stderr){ - childProcess.stderr.on('data', (data)=>console.log(data.toString())); - } - -}; - var main = function (options, callback) { var commands = commandBuilder(options); var heat = null; - console.log(commands); - //todo redo this a little... if(commands.heatCommands){ console.log(commands.heatPath, commands.heatCommands); heat = spawn(commands.heatPath, commands.heatCommands) @@ -45,7 +34,12 @@ var main = function (options, callback) { .progress(processConsole) .then(()=>spawn(commands.lightPath, commands.lightCommands), (err)=>processError(err, callback)) .progress(processConsole) - .fail((err)=>processError(err, callback)); + .fail((err)=>processError(err, callback)) + .then(()=>{ + if(callback){ + callback(); + } + }); }; module.exports = main; diff --git a/src/processConsole.js b/src/processConsole.js new file mode 100644 index 0000000..3c37f65 --- /dev/null +++ b/src/processConsole.js @@ -0,0 +1,11 @@ +'use strict' + +module.exports = function processConsole(childProcess) { + if(childProcess && childProcess.stdout){ + childProcess.stdout.on('data', (data)=>console.log(data.toString())); + } + if(childProcess && childProcess.stderr){ + childProcess.stderr.on('data', (data)=>console.log(data.toString())); + } + +}; diff --git a/test/integration/Product.wsx b/test/integration/Product.wsx new file mode 100644 index 0000000..a761c2b --- /dev/null +++ b/test/integration/Product.wsx @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/integration/candle.rsp b/test/integration/candle.rsp new file mode 100644 index 0000000..c859a5e --- /dev/null +++ b/test/integration/candle.rsp @@ -0,0 +1,5 @@ +-dSourceDir=test +-nologo +-out output\test\installers\ +test\integration\Product.wsx +output\test\installers\testfiles.gen.wxs diff --git a/test/integration/heat.rsp b/test/integration/heat.rsp new file mode 100644 index 0000000..caa141b --- /dev/null +++ b/test/integration/heat.rsp @@ -0,0 +1,7 @@ +dir test +-nologo +-cg files +-gg -scom -sreg -sfrag -srd +-dr INSTALLFOLDER +-out output\test\installers\testfiles.gen.wxs +-var var.SourceDir diff --git a/test/integration/hydroexec.js b/test/integration/hydroexec.js new file mode 100644 index 0000000..96246ed --- /dev/null +++ b/test/integration/hydroexec.js @@ -0,0 +1,14 @@ +var assert = require('chai').assert; +var expect = require('chai').expect; +var hydroexec = require('../../test-tmp/exec'); +describe('wix', function(){ + + it('creates an msi', function(cb){ + this.timeout(1000000); + return hydroexec({ + heatFiles: ['test/integration/heat.rsp'], + candleFiles: ['test/integration/candle.rsp'], + lightFiles: ['test/integration/light.rsp'] + }, cb); + }) +}); diff --git a/test/integration/light.rsp b/test/integration/light.rsp new file mode 100644 index 0000000..272b779 --- /dev/null +++ b/test/integration/light.rsp @@ -0,0 +1,8 @@ +-dSourceDir=test +output\test\installers\testfiles.gen.wixobj +output\test\installers\Product.wixobj +-out output\test\installers\Web.msi +-nologo +-sw1076 +-sice:ICE80 +-sice:ICE18 diff --git a/test/unit/CommandBuilder.test.js b/test/unit/CommandBuilder.test.js index 539edc1..f5f5b4c 100644 --- a/test/unit/CommandBuilder.test.js +++ b/test/unit/CommandBuilder.test.js @@ -1,10 +1,10 @@ var assert = require('chai').assert; var expect = require('chai').expect; -var commandBuilder = require('../../src/CommandBuilder'); + describe('CommandBuilderWorks', function(){ - + var commandBuilder = require('../../test-tmp/CommandBuilder'); it('Should not throw when files are passed in', function(){ var testObject = { heatFiles: ['tst'],