From 1c5e804817826736beeafba219f54e9c512cf1b6 Mon Sep 17 00:00:00 2001 From: Thiago Felix Date: Tue, 5 Apr 2016 09:55:46 -0300 Subject: [PATCH] Fix noPush command argument and include regression tests for the gh-pages cli fixes #56 --- bin/gh-pages | 2 +- package.json | 3 ++- test/bin/gh-pages.spec.js | 53 +++++++++++++++++++++++++++++++++++++++ test/helper.js | 33 ++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 test/bin/gh-pages.spec.js diff --git a/bin/gh-pages b/bin/gh-pages index e5305d3..22a97d0 100755 --- a/bin/gh-pages +++ b/bin/gh-pages @@ -33,7 +33,7 @@ ghpages.publish(path.join(process.cwd(), program.dist), { dotfiles: !!program.dotfiles, add: !!program.add, 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 ae00992..fda1157 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "chai": "^3.4.1", "eslint": "2.4.0", "eslint-config-tschaub": "4.0.0", - "mocha": "^2.3.4" + "mocha": "^2.3.4", + "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 0000000..7afdc37 --- /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(dist, args) { + process.argv = ['node', 'gh-pages', '-d', dist].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 = [ + ['-d lib', defaults], + ['-d lib -n', {push: false}], + ['-d lib -x', {silent: true}], + ['-d lib -t', {dotfiles: true}], + ['-d lib -a', {add: true}] + ] + + scenarions.forEach(function(scenario) { + var args = scenario[0].split(' ') + var config = scenario[1] + var dist = args[1] + + it(args.join(' '), function() { + publish(dist, args) + assert.calledWithMatch(ghpages.publish, dist, config); + }) + }) +}); diff --git a/test/helper.js b/test/helper.js index de6adf3..2133cbc 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,4 +1,5 @@ var chai = require('chai'); +var sinon = require('sinon'); /** @type {boolean} */ @@ -10,3 +11,35 @@ 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; +