Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 78 lines (57 sloc) 2.785 kb
5dbd942 Vojta Jina chore(scripts): add commit-msg hook (validation)
vojtajina authored
1 describe('validate-commit-msg.js', function() {
2 var m = require('./validate-commit-msg');
3 var errors = [];
4 var logs = [];
5
6 var VALID = true;
7 var INVALID = false;
8
9 beforeEach(function() {
10 errors.length = 0;
11 logs.length = 0;
12
13 spyOn(console, 'error').andCallFake(function(msg) {
14 errors.push(msg.replace(/\x1B\[\d+m/g, '')); // uncolor
15 });
16
17 spyOn(console, 'log').andCallFake(function(msg) {
18 logs.push(msg.replace(/\x1B\[\d+m/g, '')); // uncolor
19 });
20 });
21
22 describe('validateMessage', function() {
23
24 it('should be valid', function() {
6131521 Miško Hevery fix(git-validator): support fixup and better errors
mhevery authored
25 expect(m.validateMessage('fixup! fix($compile): something')).toBe(VALID);
5dbd942 Vojta Jina chore(scripts): add commit-msg hook (validation)
vojtajina authored
26 expect(m.validateMessage('fix($compile): something')).toBe(VALID);
27 expect(m.validateMessage('feat($location): something')).toBe(VALID);
28 expect(m.validateMessage('docs($filter): something')).toBe(VALID);
29 expect(m.validateMessage('style($http): something')).toBe(VALID);
30 expect(m.validateMessage('refactor($httpBackend): something')).toBe(VALID);
31 expect(m.validateMessage('test($resource): something')).toBe(VALID);
32 expect(m.validateMessage('chore($controller): something')).toBe(VALID);
175e727 Igor Minar chore(validate-commit-msg): allow * and - in scope string
IgorMinar authored
33 expect(m.validateMessage('chore(foo-bar): something')).toBe(VALID);
34 expect(m.validateMessage('chore(*): something')).toBe(VALID);
7b52a97 Igor Minar chore(validate-commit-msg): allow '/' in scope
IgorMinar authored
35 expect(m.validateMessage('chore(guide/location): something')).toBe(VALID);
cfe13b5 Igor Minar chore(validate-commit-msg): recognize 'revert' as valid commit type
IgorMinar authored
36 expect(m.validateMessage('revert(foo): something')).toBe(VALID);
5dbd942 Vojta Jina chore(scripts): add commit-msg hook (validation)
vojtajina authored
37 expect(errors).toEqual([]);
38 });
39
40
1ae34aa Igor Minar chore(validate-commit-msg.js): increase the max line limit for commit me...
IgorMinar authored
41 it('should validate 100 characters length', function() {
42 var msg = "fix($compile): something super mega extra giga tera long, maybe even longer and longer and longer... ";
5dbd942 Vojta Jina chore(scripts): add commit-msg hook (validation)
vojtajina authored
43
44 expect(m.validateMessage(msg)).toBe(INVALID);
1ae34aa Igor Minar chore(validate-commit-msg.js): increase the max line limit for commit me...
IgorMinar authored
45 expect(errors).toEqual(['INVALID COMMIT MSG: is longer than 100 characters !']);
5dbd942 Vojta Jina chore(scripts): add commit-msg hook (validation)
vojtajina authored
46 });
47
48
49 it('should validate "<type>(<scope>): <subject>" format', function() {
50 var msg = 'not correct format';
51
52 expect(m.validateMessage(msg)).toBe(INVALID);
6131521 Miško Hevery fix(git-validator): support fixup and better errors
mhevery authored
53 expect(errors).toEqual(['INVALID COMMIT MSG: does not match "<type>(<scope>): <subject>" ! was: not correct format']);
5dbd942 Vojta Jina chore(scripts): add commit-msg hook (validation)
vojtajina authored
54 });
55
56
57 it('should validate type', function() {
58 expect(m.validateMessage('weird($filter): something')).toBe(INVALID);
59 expect(errors).toEqual(['INVALID COMMIT MSG: "weird" is not allowed type !']);
60 });
61
62
63 it('should allow empty scope', function() {
64 expect(m.validateMessage('fix: blablabla')).toBe(VALID);
65 });
66
67
68 it('should allow dot in scope', function() {
69 expect(m.validateMessage('chore(mocks.$httpBackend): something')).toBe(VALID);
70 });
71
72
73 it('should ignore msg prefixed with "WIP: "', function() {
74 expect(m.validateMessage('WIP: bullshit')).toBe(VALID);
75 });
76 });
77 });
Something went wrong with that request. Please try again.