UNPKG

2.6 kBJavaScriptView Raw
1require('./setup')();
2
3describe('install', function () {
4 var install = require('../lib/install');
5 var hookContent = require('../lib/hook.template').content;
6
7 it('warns when the target is not a git project', function () {
8 fsStub({});
9 console.warn = function (message) {
10 expect(message).to.match(/this does not seem to be a git project/i);
11 };
12 install();
13 });
14
15 it('creates hooks directory', function () {
16 fsStub({ '.git': {} });
17 install();
18 expect(fs.existsSync('.git/hooks')).to.be.true;
19 });
20
21 it('creates hook files', function () {
22 fsStub({ '.git/hooks': {} });
23 install();
24
25 var hooks = fs.readdirSync('.git/hooks');
26
27 expect(hooks).to.include('post-update');
28 expect(fileContent('.git/hooks/post-update')).to.equal(hookContent);
29 expect(fileMode('.git/hooks/post-update')).to.equal('755');
30
31 expect(hooks).to.include('pre-applypatch');
32 expect(fileContent('.git/hooks/pre-applypatch')).to.equal(hookContent);
33 expect(fileMode('.git/hooks/pre-applypatch')).to.equal('755');
34
35 expect(hooks).to.include('pre-commit');
36 expect(fileContent('.git/hooks/pre-commit')).to.equal(hookContent);
37 expect(fileMode('.git/hooks/pre-commit')).to.equal('755');
38
39 expect(hooks).to.include('pre-push');
40 expect(fileContent('.git/hooks/pre-push')).to.equal(hookContent);
41 expect(fileMode('.git/hooks/pre-push')).to.equal('755');
42
43 expect(hooks).to.include('pre-rebase');
44 expect(fileContent('.git/hooks/pre-rebase')).to.equal(hookContent);
45 expect(fileMode('.git/hooks/pre-rebase')).to.equal('755');
46
47 expect(hooks).to.include('update');
48 expect(fileContent('.git/hooks/update')).to.equal(hookContent);
49 expect(fileMode('.git/hooks/update')).to.equal('755');
50 });
51
52 describe('backing up existing hooks', function () {
53
54 var existingGHook = '// Generated by ghooks. Do not edit this file.';
55 var existingUserHook = '# existing content';
56
57 beforeEach(function () {
58 fsStub({ '.git/hooks': {
59 'pre-commit': existingGHook,
60 'pre-push': existingUserHook
61 }});
62
63 install();
64 this.files = fs.readdirSync('.git/hooks');
65 });
66
67 it('does not keep a copy of an existing GHook', function () {
68 expect(this.files).to.not.include('pre-commit.bkp');
69 expect(this.files).to.include('pre-commit');
70 });
71
72 it('backs up an existing user hook', function () {
73 expect(this.files).to.include('pre-push');
74 expect(this.files).to.include('pre-push.bkp');
75 expect(fileContent('.git/hooks/pre-push.bkp')).to.equal(existingUserHook);
76 });
77
78 });
79
80});