Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Mar 2, 2015
1 parent 587036f commit e932323
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ module.exports = function gulpGhPages(options) {
return;
}

var self = this;

git.prepareRepo(options.remoteUrl, origin, cacheDir)
.then(function(repo) {
gutil.log(TAG + 'Cloning repo');
Expand Down Expand Up @@ -143,8 +141,6 @@ module.exports = function gulpGhPages(options) {
cb();
}, cb);
})
.catch(function(err) {
self.emit('error', err);
});
.catch(cb);
});
};
34 changes: 22 additions & 12 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,46 +249,53 @@ describe('gulp-gh-pages', function() {
it('should emit an error when it fails to create a cache directory', function(done) {
ghPages({
remoteUrl: 'https://' + accessToken + '@github.com/shinnn/gulp-gh-pages.git',
cacheDir: __filename
cacheDir: path.join(__filename, 'dir')
})
.on('error', function(err) {
var expected = 'ENOTDIR';
/* istanbul ignore if */
if (process.platform === 'win32') {
expected = 'EEXIST';
}
assert.equal(err.code, expected);
process.nextTick(assert.bind(null, /ENOTDIR|EEXIST/.test(err.code)));
done();
})
.on('end', function() {
done(new Error('Expected an error.'));
})
.end(tmpFile);
});

it('should emit an error when the repository doesn\'t exist', function(done) {
ghPages({remoteUrl: 'https://_/_this_/_repo_/_does_/_not_/_exist_/_.git'})
.on('error', function(err) {
assert(err);
process.nextTick(assert.bind(null, err));
done();
})
.on('end', function() {
done(new Error('Expected an error.'));
})
.end(tmpFile);
});

it('should emit an error when the user has no permission to push the repo', function(done) {
ghPages({remoteUrl: 'https://' + accessToken + '@github.com/bot/move.git'})
.on('error', function(err) {
assert(err);
assert(/Permission to/.test(err.message));
process.nextTick(assert.bind(null, /Permission to/.test(err.message)));
done();
})
.on('end', function() {
done(new Error('Expected an error.'));
})
.end(tmpFile);
});

it('should emit an error when the remote URL is not a git repository\'s URL', function(done) {
ghPages({remoteUrl: 'https://example.org/'})
.on('error', function(err) {
assert(err);
assert(/'https:\/\/example\.org\/' not found/.test(err.message));
process.nextTick(
assert.bind(null, /'https:\/\/example\.org\/' not found/.test(err.message))
);
done();
})
.on('end', function() {
done(new Error('Expected an error.'));
})
.end(tmpFile);
});

Expand All @@ -301,6 +308,9 @@ describe('gulp-gh-pages', function() {
process.chdir(path.resolve(__dirname, '..'));
done();
})
.on('end', function() {
done(new Error('Expected an error.'));
})
.end(tmpFile);
});
});

0 comments on commit e932323

Please sign in to comment.