Skip to content
Merged
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"istanbul": "0.4.5",
"jscs": "2.11.0",
"jshint": "2.9.5",
"mocha": "5.1.1"
"mocha": "5.1.1",
"tmp": "0.0.33"
},
"license": "MIT"
}
24 changes: 18 additions & 6 deletions tests/install.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
require('chai').should();
var execSync = require('child_process').execSync;
var gitHooks = require('../lib/git-hooks');
var fsHelpers = require('../lib/fs-helpers');
var tmp = require('tmp');

var SANDBOX_PATH = __dirname + '/tmp-sandbox/';
var tmpDir = tmp.dirSync();

var SANDBOX_PATH = tmpDir.name + '/git-hooks-sandbox/';
var GIT_ROOT = SANDBOX_PATH + '.git/';
var GIT_HOOKS = GIT_ROOT + 'hooks';
var GIT_HOOKS_OLD = GIT_ROOT + 'hooks.old';

describe('--install', function () {
beforeEach(function () {
fsHelpers.makeDir(GIT_ROOT);
fsHelpers.makeDir(SANDBOX_PATH);
execSync('git init', {cwd: SANDBOX_PATH});
});

afterEach(function () {
Expand All @@ -21,6 +26,17 @@ describe('--install', function () {
fsHelpers.exists(GIT_HOOKS).should.be.true;
});

describe('when git repo is missing its hooks folder', function () {
beforeEach(function () {
fsHelpers.removeDir(GIT_ROOT + '/hooks');
});

it('should install hooks', function () {
gitHooks.install(SANDBOX_PATH);
fsHelpers.exists(GIT_HOOKS).should.be.true;
});
});

describe('when it is run not inside a git repo', function () {
beforeEach(function () {
fsHelpers.removeDir(GIT_ROOT);
Expand All @@ -35,10 +51,6 @@ describe('--install', function () {
});

describe('when some hooks already exist', function () {
beforeEach(function () {
fsHelpers.makeDir(GIT_HOOKS);
});

it('should backup hooks before installation', function () {
gitHooks.install(SANDBOX_PATH);
fsHelpers.exists(GIT_HOOKS_OLD).should.be.true;
Expand Down
10 changes: 7 additions & 3 deletions tests/run.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
require('chai').should();
var execSync = require('child_process').execSync;
var fs = require('fs');
var gitHooks = require('../lib/git-hooks');
var fsHelpers = require('../lib/fs-helpers');
var tmp = require('tmp');

var SANDBOX_PATH = __dirname + '/tmp-sandbox/';
var tmpDir = tmp.dirSync();

var SANDBOX_PATH = tmpDir.name + '/git-hooks-sandbox/';
var GIT_ROOT = SANDBOX_PATH + '.git/';
var GIT_HOOKS = GIT_ROOT + 'hooks';
var PRECOMMIT_HOOK_PATH = GIT_HOOKS + '/pre-commit';
Expand All @@ -16,8 +20,8 @@ function createHook(path, content) {

describe('git-hook runner', function () {
beforeEach(function () {
fsHelpers.makeDir(GIT_ROOT);
gitHooks.install(SANDBOX_PATH);
fsHelpers.makeDir(SANDBOX_PATH);
execSync('git init', {cwd: SANDBOX_PATH});
});

afterEach(function () {
Expand Down
7 changes: 5 additions & 2 deletions tests/uninstall.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ require('chai').should();
var execSync = require('child_process').execSync;
var gitHooks = require('../lib/git-hooks');
var fsHelpers = require('../lib/fs-helpers');
var tmp = require('tmp');

var SANDBOX_PATH = '/tmp/tmp-sandbox/';
var tmpDir = tmp.dirSync();

var SANDBOX_PATH = tmpDir.name + '/git-hooks-sandbox/';
var GIT_ROOT = SANDBOX_PATH + '.git/';
var GIT_HOOKS = GIT_ROOT + 'hooks';
var GIT_HOOKS_OLD = GIT_ROOT + 'hooks.old';
Expand Down Expand Up @@ -34,7 +37,7 @@ describe('--uninstall', function () {

it('should throw an error', function () {
var fn = function () {
gitHooks.install(SANDBOX_PATH);
gitHooks.uninstall(SANDBOX_PATH);
};
fn.should.throw(Error);
});
Expand Down