diff --git a/bin/gh-pages b/bin/gh-pages index 5049585d..0cae51a4 100755 --- a/bin/gh-pages +++ b/bin/gh-pages @@ -47,7 +47,7 @@ ghpages.publish( add: !!program.add, only: program.remove, remote: program.remote, - push: !program.noPush, + push: !!program.push, logger: function(message) { process.stderr.write(message + '\n'); } diff --git a/package.json b/package.json index b4da31fd..15a80187 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "chai": "^3.5.0", "eslint": "^3.10.2", "eslint-config-tschaub": "^7.0.0", - "mocha": "^3.1.2" + "mocha": "^3.1.2", + "sinon": "^1.17.3" }, "bin": { "gh-pages": "bin/gh-pages" diff --git a/test/bin/gh-pages.spec.js b/test/bin/gh-pages.spec.js new file mode 100644 index 00000000..ea49ea50 --- /dev/null +++ b/test/bin/gh-pages.spec.js @@ -0,0 +1,53 @@ +/* eslint-env mocha */ + +var ghpages = require('../../lib/index'); +var stub = require('../helper').stub; +var assert = require('../helper').sinon.assert; +var cli = '../../bin/gh-pages'; + +describe('gh-pages', function() { + beforeEach(function() { + stub(ghpages, 'publish'); + }); + + afterEach(function() { + ghpages.publish.restore(); + }); + + var publish = function publish(args) { + process.argv = ['node', 'gh-pages'].concat(args); + require(cli); + delete require.cache[require.resolve(cli)]; + }; + + var defaults = { + repo: undefined, + silent: false, + branch: 'gh-pages', + src: '**/*', + message: 'Updates', + dotfiles: false, + add: false, + remote: 'origin', + push: true + }; + + var scenarions = [ + ['--dist lib', 'lib', defaults], + ['--dist lib -n', 'lib', {push: false}], + ['--dist lib -x', 'lib', {silent: true}], + ['--dist lib --dotfiles', 'lib', {dotfiles: true}], + ['--dist lib -a', 'lib', {add: true}] + ]; + + scenarions.forEach(function(scenario) { + var args = scenario[0].split(' '); + var dist = scenario[1]; + var config = scenario[2]; + + it(args.join(' '), function() { + publish(args); + assert.calledWithMatch(ghpages.publish, dist, config); + }); + }); +}); diff --git a/test/helper.js b/test/helper.js index d5011ceb..3a2e4e6b 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,4 +1,5 @@ var chai = require('chai'); +var sinon = require('sinon'); /** @type {boolean} */ chai.config.includeStack = true; @@ -8,3 +9,33 @@ chai.config.includeStack = true; * @type {function} */ exports.assert = chai.assert; + +/** + * Sinon's spy function + * @type {function} + */ +exports.spy = sinon.spy; + +/** + * Sinon's stub function + * @type {function} + */ +exports.stub = sinon.stub; + +/** + * Sinon's mock function + * @type {function} + */ +exports.mock = sinon.mock; + +/** + * Sinon's API object + * @type {object} + */ +exports.sinon = sinon; + +/** + * Turn of maxListeners warning during the tests + * See: https://nodejs.org/docs/latest/api/events.html#events_emitter_setmaxlisteners_n + */ +require('events').EventEmitter.prototype._maxListeners = 0;