Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix noPush command argument #137

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/gh-pages
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ghpages.publish(path.join(process.cwd(), program.dist), {
add: !!program.add,
only: program.remove,
remote: program.remote,
push: !program.noPush,
push: !!program.push,
logger: function(message) {
process.stderr.write(message + '\n');
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"chai": "^3.5.0",
"eslint": "^3.10.2",
"eslint-config-tschaub": "^6.0.0",
"mocha": "^3.1.2"
"mocha": "^3.1.2",
"sinon": "^1.17.3"
},
"bin": {
"gh-pages": "bin/gh-pages"
Expand Down
53 changes: 53 additions & 0 deletions test/bin/gh-pages.spec.js
Original file line number Diff line number Diff line change
@@ -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);
})
})
});
33 changes: 33 additions & 0 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var chai = require('chai');
var sinon = require('sinon');


/** @type {boolean} */
Expand All @@ -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;