diff --git a/.travis.yml b/.travis.yml index d0880c15..1dd1a242 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,6 @@ +dist: trusty +sudo: false + language: node_js node_js: - "6" diff --git a/bin/gh-pages b/bin/gh-pages index 0cae51a4..bb2b62da 100755 --- a/bin/gh-pages +++ b/bin/gh-pages @@ -3,60 +3,69 @@ var ghpages = require('../lib/index'); var program = require('commander'); var path = require('path'); +var pkg = require('../package.json'); -program - .version(require('../package').version) - .option('-d, --dist ', 'base directory for all source files') - .option( - '-s, --src ', - 'pattern used to select which files should be published', - '**/*' - ) - .option('-r, --repo ', "URL of the repository you'll be pushing to") - .option('-x, --silent', 'Do not output the repository url') - .option( - '-b, --branch ', - "name of the branch you'll be pushing to", - 'gh-pages' - ) - .option('-o, --remote ', 'The name of the remote', 'origin') - .option('-m, --message ', 'commit message', 'Updates') - .option('-g, --tag ', 'add tag to commit') - .option('-p, --depth ', 'depth for clone', 1) - .option('-t, --dotfiles', 'Include dotfiles') - .option('-a, --add', 'Only add, and never remove existing files.') - .option( - '-v, --remove ', - 'Remove files that match the given pattern ' + - '(ignored if used together with --add).', - '.' - ) - .option('-n, --no-push', 'Commit only (with no push)') - .parse(process.argv); +function main(args) { + program + .version(pkg.version) + .option('-d, --dist ', 'base directory for all source files') + .option( + '-s, --src ', + 'pattern used to select which files should be published', + '**/*' + ) + .option('-r, --repo ', "URL of the repository you'll be pushing to") + .option('-x, --silent', 'Do not output the repository url') + .option( + '-b, --branch ', + "name of the branch you'll be pushing to", + 'gh-pages' + ) + .option('-o, --remote ', 'The name of the remote', 'origin') + .option('-m, --message ', 'commit message', 'Updates') + .option('-g, --tag ', 'add tag to commit') + .option('-p, --depth ', 'depth for clone', 1) + .option('-t, --dotfiles', 'Include dotfiles') + .option('-a, --add', 'Only add, and never remove existing files.') + .option( + '-v, --remove ', + 'Remove files that match the given pattern ' + + '(ignored if used together with --add).', + '.' + ) + .option('-n, --no-push', 'Commit only (with no push)') + .parse(args); -ghpages.publish( - path.join(process.cwd(), program.dist), - { - repo: program.repo, - silent: !!program.silent, - branch: program.branch, - src: program.src, - message: program.message, - tag: program.tag, - dotfiles: !!program.dotfiles, - add: !!program.add, - only: program.remove, - remote: program.remote, - push: !!program.push, - logger: function(message) { - process.stderr.write(message + '\n'); + ghpages.publish( + path.join(process.cwd(), program.dist), + { + repo: program.repo, + silent: !!program.silent, + branch: program.branch, + src: program.src, + message: program.message, + tag: program.tag, + dotfiles: !!program.dotfiles, + add: !!program.add, + only: program.remove, + remote: program.remote, + push: !!program.push, + logger: function(message) { + process.stderr.write(message + '\n'); + } + }, + function(err) { + if (err) { + process.stderr.write(err.message + '\n'); + return process.exit(1); + } + process.stderr.write('Published\n'); } - }, - function(err) { - if (err) { - process.stderr.write(err.message + '\n'); - return process.exit(1); - } - process.stderr.write('Published\n'); - } -); + ); +} + +if (require.main === module) { + main(process.argv); +} + +module.exports = main; diff --git a/lib/git.js b/lib/git.js index 967a3a70..23f47fc9 100644 --- a/lib/git.js +++ b/lib/git.js @@ -3,8 +3,6 @@ var fs = require('fs-extra'); var path = require('path'); var util = require('util'); -var git = 'git'; - /** * @constructor * @param {number} code Error code. @@ -34,6 +32,9 @@ function spawn(exe, args, cwd) { child.stderr.on('data', function(chunk) { buffer.push(chunk.toString()); }); + child.stdout.on('data', function(chunk) { + buffer.push(chunk.toString()); + }); child.on('close', function(code) { var output = buffer.join(''); if (code) { @@ -47,183 +48,225 @@ function spawn(exe, args, cwd) { } /** - * Execute a git command. - * @param {Array.} args Arguments (e.g. ['remote', 'update']). + * Create an object for executing git commands. * @param {string} cwd Repository directory. - * @return {Promise} A promise. The promise will be resolved with stdout output - * or rejected with an error. + * @param {string} exe Git executable (full path if not already on path). + * @constructor */ -exports = module.exports = function(args, cwd) { - return spawn(git, args, cwd); -}; +function Git(cwd, cmd) { + this.cwd = cwd; + this.cmd = cmd || 'git'; + this.output = ''; +} /** - * Set the Git executable to be used by exported methods (defaults to 'git'). - * @param {string} exe Git executable (full path if not already on path). + * Execute an arbitrary git command. + * @param {string} var_args Arguments (e.g. 'remote', 'update'). + * @return {Promise} A promise. The promise will be resolved with this instance + * or rejected with an error. */ -exports.exe = function(exe) { - git = exe; +Git.prototype.exec = function() { + return spawn(this.cmd, [].slice.call(arguments), this.cwd).then( + function(output) { + this.output = output; + return this; + }.bind(this) + ); }; /** * Initialize repository. - * @param {string} cwd Repository directory. * @return {ChildProcess} Child process. */ -exports.init = function init(cwd) { - return spawn(git, ['init'], cwd); -}; - -/** - * Clone a repo into the given dir if it doesn't already exist. - * @param {string} repo Repository URL. - * @param {string} dir Target directory. - * @param {string} branch Branch name. - * @param {options} options All options. - * @return {Promise} A promise. - */ -exports.clone = function clone(repo, dir, branch, options) { - return fs.exists(dir).then(function(exists) { - if (exists) { - return Promise.resolve(); - } else { - return fs.mkdirp(path.dirname(path.resolve(dir))).then(function() { - var args = [ - 'clone', - repo, - dir, - '--branch', - branch, - '--single-branch', - '--origin', - options.remote, - '--depth', - options.depth - ]; - return spawn(git, args).catch(function(err) { - // try again without banch options - return spawn(git, ['clone', repo, dir, '--origin', options.remote]); - }); - }); - } - }); +Git.prototype.init = function() { + return this.exec('init'); }; /** * Clean up unversioned files. - * @param {string} cwd Repository directory. * @return {Promise} A promise. */ -var clean = (exports.clean = function clean(cwd) { - return spawn(git, ['clean', '-f', '-d'], cwd); -}); +Git.prototype.clean = function() { + return this.exec('clean', '-f', '-d'); +}; /** * Hard reset to remote/branch * @param {string} remote Remote alias. * @param {string} branch Branch name. - * @param {string} cwd Repository directory. * @return {Promise} A promise. */ -var reset = (exports.reset = function reset(remote, branch, cwd) { - return spawn(git, ['reset', '--hard', remote + '/' + branch], cwd); -}); +Git.prototype.reset = function(remote, branch) { + return this.exec('reset', '--hard', remote + '/' + branch); +}; /** * Fetch from a remote. * @param {string} remote Remote alias. - * @param {string} cwd Repository directory. * @return {Promise} A promise. */ -exports.fetch = function fetch(remote, cwd) { - return spawn(git, ['fetch', remote], cwd); +Git.prototype.fetch = function(remote) { + return this.exec('fetch', remote); }; /** * Checkout a branch (create an orphan if it doesn't exist on the remote). * @param {string} remote Remote alias. * @param {string} branch Branch name. - * @param {string} cwd Repository directory. * @return {Promise} A promise. */ -exports.checkout = function checkout(remote, branch, cwd) { +Git.prototype.checkout = function(remote, branch) { var treeish = remote + '/' + branch; - return spawn(git, ['ls-remote', '--exit-code', '.', treeish], cwd).then( + return this.exec('ls-remote', '--exit-code', '.', treeish).then( function() { // branch exists on remote, hard reset - return spawn(git, ['checkout', branch], cwd) - .then(function() { - return clean(cwd); - }) - .then(function() { - return reset(remote, branch, cwd); - }); - }, + return this.exec('checkout', branch) + .then( + function() { + return this.clean(); + }.bind(this) + ) + .then( + function() { + return this.reset(remote, branch); + }.bind(this) + ); + }.bind(this), function(error) { if (error instanceof ProcessError && error.code === 2) { // branch doesn't exist, create an orphan - return spawn(git, ['checkout', '--orphan', branch], cwd); + return this.exec('checkout', '--orphan', branch); } else { // unhandled error throw error; } - } + }.bind(this) ); }; /** * Remove all unversioned files. * @param {string} files Files argument. - * @param {string} cwd Repository directory. * @return {Promise} A promise. */ -exports.rm = function rm(files, cwd) { - return spawn(git, ['rm', '--ignore-unmatch', '-r', '-f', files], cwd); +Git.prototype.rm = function(files) { + return this.exec('rm', '--ignore-unmatch', '-r', '-f', files); }; /** * Add files. * @param {string} files Files argument. - * @param {string} cwd Repository directory. * @return {Promise} A promise. */ -exports.add = function add(files, cwd) { - return spawn(git, ['add', files], cwd); +Git.prototype.add = function(files) { + return this.exec('add', files); }; /** - * Commit. + * Commit (if there are any changes). * @param {string} message Commit message. - * @param {string} cwd Repository directory. * @return {Promise} A promise. */ -exports.commit = function commit(message, cwd) { - return spawn( - git, - ['diff-index', '--quiet', 'HEAD', '.'], - cwd - ).catch(function() { - return spawn(git, ['commit', '-m', message], cwd); - }); +Git.prototype.commit = function(message) { + return this.exec('diff-index', '--quiet', 'HEAD').catch( + function() { + return this.exec('commit', '-m', message); + }.bind(this) + ); }; /** * Add tag * @param {string} name Name of tag. - * @param {string} cwd Repository directory. * @return {Promise} A promise. */ -exports.tag = function tag(name, cwd) { - return spawn(git, ['tag', name], cwd); +Git.prototype.tag = function(name) { + return this.exec('tag', name); }; /** * Push a branch. * @param {string} remote Remote alias. * @param {string} branch Branch name. - * @param {string} cwd Repository directory. * @return {Promise} A promise. */ -exports.push = function push(remote, branch, cwd) { - return spawn(git, ['push', '--tags', remote, branch], cwd); +Git.prototype.push = function(remote, branch) { + return this.exec('push', '--tags', remote, branch); +}; + +/** + * Get the URL for a remote. + * @param {string} remote Remote alias. + * @return {Promise} A promise for the remote URL. + */ +Git.prototype.getRemoteUrl = function(remote) { + return this.exec('config', '--get', 'remote.' + remote + '.url') + .then(function(git) { + var repo = git.output && git.output.split(/[\n\r]/).shift(); + if (repo) { + return repo; + } else { + throw new Error( + 'Failed to get repo URL from options or current directory.' + ); + } + }) + .catch(function(err) { + throw new Error( + 'Failed to get remote.' + + remote + + '.url (task must either be ' + + 'run in a git repository with a configured ' + + remote + + ' remote ' + + 'or must be configured with the "repo" option).' + ); + }); +}; + +/** + * Clone a repo into the given dir if it doesn't already exist. + * @param {string} repo Repository URL. + * @param {string} dir Target directory. + * @param {string} branch Branch name. + * @param {options} options All options. + * @return {Promise} A promise. + */ +Git.clone = function clone(repo, dir, branch, options) { + return fs.exists(dir).then(function(exists) { + if (exists) { + return Promise.resolve(new Git(dir, options.git)); + } else { + return fs.mkdirp(path.dirname(path.resolve(dir))).then(function() { + var args = [ + 'clone', + repo, + dir, + '--branch', + branch, + '--single-branch', + '--origin', + options.remote, + '--depth', + options.depth + ]; + return spawn(options.git, args) + .catch(function(err) { + // try again without banch or depth options + return spawn(options.git, [ + 'clone', + repo, + dir, + '--origin', + options.remote + ]); + }) + .then(function() { + return new Git(dir, options.git); + }); + }); + } + }); }; + +module.exports = Git; diff --git a/lib/index.js b/lib/index.js index 4b0a3843..01036c4c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,6 @@ var copy = require('./util').copy; var fs = require('fs-extra'); -var git = require('./git'); +var Git = require('./git'); var globby = require('globby'); var path = require('path'); @@ -8,37 +8,12 @@ function getCacheDir() { return path.relative(process.cwd(), path.resolve(__dirname, '../.cache')); } -function getRemoteUrl(dir, remote) { - var repo; - return git(['config', '--get', 'remote.' + remote + '.url'], dir) - .then(function(output) { - repo = output.split(/[\n\r]/).shift(); - if (repo) { - return repo; - } else { - throw new Error( - 'Failed to get repo URL from options or current directory.' - ); - } - }) - .catch(function(err) { - throw new Error( - 'Failed to get remote.' + - remote + - '.url (task must either be ' + - 'run in a git repository with a configured ' + - remote + - ' remote ' + - 'or must be configured with the "repo" option).' - ); - }); -} - function getRepo(options) { if (options.repo) { return Promise.resolve(options.repo); } else { - return getRemoteUrl(process.cwd(), options.remote); + var git = new Git(process.cwd(), options.git); + return git.getRemoteUrl(options.remote); } } @@ -114,23 +89,23 @@ exports.publish = function publish(basePath, config, callback) { }); if (!Array.isArray(files) || files.length === 0) { - done(new Error('Files must be provided in the "src" property.')); + done( + new Error('The pattern in the "src" property didn\'t match any files.') + ); return; } var only = globby.sync(options.only, {cwd: basePath}); - git.exe(options.git); - var repoUrl; getRepo(options) .then(function(repo) { repoUrl = repo; log('Cloning ' + repo + ' into ' + options.clone); - return git.clone(repo, options.clone, options.branch, options); + return Git.clone(repo, options.clone, options.branch, options); }) - .then(function() { - return getRemoteUrl(options.clone, options.remote).then(function(url) { + .then(function(git) { + return git.getRemoteUrl(options.remote).then(function(url) { if (url !== repoUrl) { var message = 'Remote url mismatch. Got "' + @@ -144,63 +119,74 @@ exports.publish = function publish(basePath, config, callback) { 'running the "clean" task first.'; throw new Error(message); } + return git; }); }) - .then(function() { + .then(function(git) { // only required if someone mucks with the checkout between builds log('Cleaning'); - return git.clean(options.clone); + return git.clean(); }) - .then(function() { + .then(function(git) { log('Fetching ' + options.remote); - return git.fetch(options.remote, options.clone); + return git.fetch(options.remote); }) - .then(function() { + .then(function(git) { log('Checking out ' + options.remote + '/' + options.branch); - return git.checkout(options.remote, options.branch, options.clone); + return git.checkout(options.remote, options.branch); }) - .then(function() { + .then(function(git) { if (!options.add) { log('Removing files'); - return git.rm(only.join(' '), options.clone); + return git.rm(only.join(' ')); + } else { + return git; } }) - .then(function() { + .then(function(git) { log('Copying files'); - return copy(files, basePath, options.clone); + return copy(files, basePath, options.clone).then(function() { + return git; + }); }) - .then(function() { + .then(function(git) { log('Adding all'); - return git.add('.', options.clone); + return git.add('.'); }) - .then(function() { + .then(function(git) { if (options.user) { - return git( - ['config', 'user.email', options.user.email], - options.clone - ).then(function() { - return git(['config', 'user.name', options.user.name], options.clone); - }); + return git + .exec('config', 'user.email', options.user.email) + .then(function() { + return git.exec('config', 'user.name', options.user.name); + }); + } else { + return git; } }) - .then(function() { + .then(function(git) { log('Committing'); - return git.commit(options.message, options.clone); + return git.commit(options.message); }) - .then(function() { + .then(function(git) { if (options.tag) { log('Tagging'); - return git.tag(options.tag, options.clone).catch(function(error) { + return git.tag(options.tag).catch(function(error) { // tagging failed probably because this tag alredy exists log('Tagging failed, continuing'); options.logger(error); + return git; }); + } else { + return git; } }) - .then(function() { + .then(function(git) { if (options.push) { log('Pushing'); - return git.push(options.remote, options.branch, options.clone); + return git.push(options.remote, options.branch); + } else { + return git; } }) .then( diff --git a/package.json b/package.json index 15a80187..fa5435d3 100644 --- a/package.json +++ b/package.json @@ -39,10 +39,12 @@ }, "devDependencies": { "chai": "^3.5.0", + "dir-compare": "^1.4.0", "eslint": "^3.10.2", "eslint-config-tschaub": "^7.0.0", "mocha": "^3.1.2", - "sinon": "^1.17.3" + "sinon": "^1.17.3", + "tmp": "0.0.31" }, "bin": { "gh-pages": "bin/gh-pages" diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 00000000..7eeefc33 --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,5 @@ +{ + "env": { + "mocha": true + } +} diff --git a/test/bin/gh-pages.spec.js b/test/bin/gh-pages.spec.js index ea49ea50..85d1cf29 100644 --- a/test/bin/gh-pages.spec.js +++ b/test/bin/gh-pages.spec.js @@ -1,25 +1,16 @@ -/* eslint-env mocha */ - var ghpages = require('../../lib/index'); -var stub = require('../helper').stub; -var assert = require('../helper').sinon.assert; -var cli = '../../bin/gh-pages'; +var sinon = require('sinon'); +var cli = require('../../bin/gh-pages'); describe('gh-pages', function() { beforeEach(function() { - stub(ghpages, 'publish'); + sinon.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, @@ -46,8 +37,8 @@ describe('gh-pages', function() { var config = scenario[2]; it(args.join(' '), function() { - publish(args); - assert.calledWithMatch(ghpages.publish, dist, config); + cli(['node', 'gh-pages'].concat(args)); + sinon.assert.calledWithMatch(ghpages.publish, dist, config); }); }); }); diff --git a/test/helper.js b/test/helper.js index 3a2e4e6b..60aa4380 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,5 +1,15 @@ var chai = require('chai'); -var sinon = require('sinon'); +var tmp = require('tmp'); +var path = require('path'); +var fs = require('fs-extra'); +var Git = require('../lib/git'); +var compare = require('dir-compare').compareSync; + +/** + * Turn off maxListeners warning during the tests + * See: https://nodejs.org/docs/latest/api/events.html#events_emitter_setmaxlisteners_n + */ +require('events').EventEmitter.prototype._maxListeners = 0; /** @type {boolean} */ chai.config.includeStack = true; @@ -10,32 +20,96 @@ chai.config.includeStack = true; */ exports.assert = chai.assert; -/** - * Sinon's spy function - * @type {function} - */ -exports.spy = sinon.spy; +var fixtures = path.join(__dirname, 'integration', 'fixtures'); -/** - * Sinon's stub function - * @type {function} - */ -exports.stub = sinon.stub; +function mkdtemp() { + return new Promise(function(resolve, reject) { + tmp.dir({unsafeCleanup: true}, function(err, tmpPath) { + if (err) { + return reject(err); + } + resolve(tmpPath); + }); + }); +} -/** - * Sinon's mock function - * @type {function} - */ -exports.mock = sinon.mock; +function relay(value) { + return function() { + return value; + }; +} -/** - * Sinon's API object - * @type {object} - */ -exports.sinon = sinon; +function setupRemote(fixtureName, options) { + options = options || {}; + var branch = options.branch || 'gh-pages'; + var userEmail = (options.user && options.user.email) || 'user@email.com'; + var userName = (options.name && options.user.name) || 'User Name'; + return mkdtemp() + .then(function(remote) { + return new Git(remote).exec('init', '--bare').then(relay(remote)); + }) + .then(function(remote) { + return mkdtemp() + .then(function(clone) { + const fixturePath = path.join(fixtures, fixtureName, 'remote'); + return fs.copy(fixturePath, clone).then(relay(new Git(clone))); + }) + .then(function(git) { + return git.init(); + }) + .then(function(git) { + return git.exec('config', 'user.email', userEmail); + }) + .then(function(git) { + return git.exec('config', 'user.name', userName); + }) + .then(function(git) { + return git.exec('checkout', '--orphan', branch); + }) + .then(function(git) { + return git.add('.'); + }) + .then(function(git) { + return git.commit('Initial commit'); + }) + .then(function(git) { + var url = 'file://' + remote; + return git.exec('push', url, branch).then(relay(url)); + }); + }); +} -/** - * 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; +function assertContentsMatch(dir, url, branch, matchOptions) { + return mkdtemp() + .then(function(root) { + var clone = path.join(root, 'repo'); + var options = {git: 'git', remote: 'origin', depth: 1}; + return Git.clone(url, clone, branch, options); + }) + .then(function(git) { + var options = Object.assign({}, matchOptions, {excludeFilter: '.git'}); + var comparison = compare(dir, git.cwd, options); + if (comparison.same) { + return true; + } else { + var message = comparison.diffSet + .map(function(entry) { + var state = { + equal: '==', + left: '->', + right: '<-', + distinct: '<>' + }[entry.state]; + var name1 = entry.name1 ? entry.name1 : ''; + var name2 = entry.name2 ? entry.name2 : ''; + + return [name1, state, name2].join(' '); + }) + .join('\n'); + throw new Error('Directories do not match:\n' + message); + } + }); +} + +exports.setupRemote = setupRemote; +exports.assertContentsMatch = assertContentsMatch; diff --git a/test/integration/basic.spec.js b/test/integration/basic.spec.js new file mode 100644 index 00000000..c62c0c45 --- /dev/null +++ b/test/integration/basic.spec.js @@ -0,0 +1,65 @@ +var helper = require('../helper'); +var ghPages = require('../../lib/'); +var path = require('path'); + +var fixtures = path.join(__dirname, 'fixtures'); +var fixtureName = 'basic'; + +beforeEach(function() { + ghPages.clean(); +}); + +describe('basic usage', function() { + it('pushes the contents of a directory to a gh-pages branch', function(done) { + var local = path.join(fixtures, fixtureName, 'local'); + var branch = 'gh-pages'; + + helper.setupRemote(fixtureName, branch).then(function(url) { + var options = { + repo: url, + user: { + name: 'User Name', + email: 'user@email.com' + } + }; + ghPages.publish(local, options, function(err) { + if (err) { + return done(err); + } + helper + .assertContentsMatch(local, url, branch) + .then(function() { + done(); + }) + .catch(done); + }); + }); + }); + + it('can push to a different branch', function(done) { + var local = path.join(fixtures, fixtureName, 'local'); + var branch = 'master'; + + helper.setupRemote(fixtureName, branch).then(function(url) { + var options = { + repo: url, + branch: branch, + user: { + name: 'User Name', + email: 'user@email.com' + } + }; + ghPages.publish(local, options, function(err) { + if (err) { + return done(err); + } + helper + .assertContentsMatch(local, url, branch) + .then(function() { + done(); + }) + .catch(done); + }); + }); + }); +}); diff --git a/test/integration/fixtures/basic/local/hello-world.txt b/test/integration/fixtures/basic/local/hello-world.txt new file mode 100644 index 00000000..980a0d5f --- /dev/null +++ b/test/integration/fixtures/basic/local/hello-world.txt @@ -0,0 +1 @@ +Hello World! diff --git a/test/integration/fixtures/basic/remote/initial b/test/integration/fixtures/basic/remote/initial new file mode 100644 index 00000000..e69de29b diff --git a/test/integration/fixtures/include/local/bad.coffee b/test/integration/fixtures/include/local/bad.coffee new file mode 100644 index 00000000..d700fe0c --- /dev/null +++ b/test/integration/fixtures/include/local/bad.coffee @@ -0,0 +1 @@ +# this file should not be included diff --git a/test/integration/fixtures/include/local/good.js b/test/integration/fixtures/include/local/good.js new file mode 100644 index 00000000..b4763cc5 --- /dev/null +++ b/test/integration/fixtures/include/local/good.js @@ -0,0 +1 @@ +// this file should be included diff --git a/test/integration/fixtures/include/remote/initial b/test/integration/fixtures/include/remote/initial new file mode 100644 index 00000000..e69de29b diff --git a/test/integration/include.spec.js b/test/integration/include.spec.js new file mode 100644 index 00000000..19167395 --- /dev/null +++ b/test/integration/include.spec.js @@ -0,0 +1,40 @@ +var helper = require('../helper'); +var ghPages = require('../../lib/'); +var path = require('path'); + +var fixtures = path.join(__dirname, 'fixtures'); +var fixtureName = 'include'; + +beforeEach(function() { + ghPages.clean(); +}); + +describe('the src option', function() { + it('can be used to limit which files are included', function(done) { + var local = path.join(fixtures, fixtureName, 'local'); + var branch = 'gh-pages'; + + helper.setupRemote(fixtureName, branch).then(function(url) { + var options = { + repo: url, + src: '**/*.js', + user: { + name: 'User Name', + email: 'user@email.com' + } + }; + + ghPages.publish(local, options, function(err) { + if (err) { + return done(err); + } + helper + .assertContentsMatch(local, url, branch, {includeFilter: options.src}) + .then(function() { + done(); + }) + .catch(done); + }); + }); + }); +}); diff --git a/test/lib/util.spec.js b/test/lib/util.spec.js index aa609e39..afa44fce 100644 --- a/test/lib/util.spec.js +++ b/test/lib/util.spec.js @@ -1,4 +1,3 @@ -/* eslint-env mocha */ var path = require('path'); var assert = require('../helper').assert;