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'],