Fix noPush command argument and include regression tests for the

gh-pages cli

fixes #56
This commit is contained in:
Thiago Felix 2016-04-05 09:55:46 -03:00
parent 7310e1979a
commit 1c5e804817
4 changed files with 89 additions and 2 deletions

View file

@ -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');
}

View file

@ -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"

53
test/bin/gh-pages.spec.js Normal file
View file

@ -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);
})
})
});

View file

@ -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;