|
5dbd942
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
mhevery authored
|
||
| 25 | expect(m.validateMessage('fixup! fix($compile): something')).toBe(VALID); | |
|
5dbd942
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
IgorMinar authored
|
||
| 33 | expect(m.validateMessage('chore(foo-bar): something')).toBe(VALID); | |
| 34 | expect(m.validateMessage('chore(*): something')).toBe(VALID); | |
|
7b52a97
IgorMinar authored
|
||
| 35 | expect(m.validateMessage('chore(guide/location): something')).toBe(VALID); | |
|
cfe13b5
IgorMinar authored
|
||
| 36 | expect(m.validateMessage('revert(foo): something')).toBe(VALID); | |
|
5dbd942
vojtajina authored
|
||
| 37 | expect(errors).toEqual([]); | |
| 38 | }); | |
| 39 | ||
| 40 | ||
| 41 | it('should validate 70 characters length', function() { | |
| 42 | var msg = 'fix($compile): something super mega extra giga tera long, maybe even longer... ' + | |
| 43 | 'way over 80 characters'; | |
| 44 | ||
| 45 | expect(m.validateMessage(msg)).toBe(INVALID); | |
| 46 | expect(errors).toEqual(['INVALID COMMIT MSG: is longer than 70 characters !']); | |
| 47 | }); | |
| 48 | ||
| 49 | ||
| 50 | it('should validate "<type>(<scope>): <subject>" format', function() { | |
| 51 | var msg = 'not correct format'; | |
| 52 | ||
| 53 | expect(m.validateMessage(msg)).toBe(INVALID); | |
|
6131521
mhevery authored
|
||
| 54 | expect(errors).toEqual(['INVALID COMMIT MSG: does not match "<type>(<scope>): <subject>" ! was: not correct format']); | |
|
5dbd942
vojtajina authored
|
||
| 55 | }); | |
| 56 | ||
| 57 | ||
| 58 | it('should validate type', function() { | |
| 59 | expect(m.validateMessage('weird($filter): something')).toBe(INVALID); | |
| 60 | expect(errors).toEqual(['INVALID COMMIT MSG: "weird" is not allowed type !']); | |
| 61 | }); | |
| 62 | ||
| 63 | ||
| 64 | it('should allow empty scope', function() { | |
| 65 | expect(m.validateMessage('fix: blablabla')).toBe(VALID); | |
| 66 | }); | |
| 67 | ||
| 68 | ||
| 69 | it('should allow dot in scope', function() { | |
| 70 | expect(m.validateMessage('chore(mocks.$httpBackend): something')).toBe(VALID); | |
| 71 | }); | |
| 72 | ||
| 73 | ||
| 74 | it('should ignore msg prefixed with "WIP: "', function() { | |
| 75 | expect(m.validateMessage('WIP: bullshit')).toBe(VALID); | |
| 76 | }); | |
| 77 | }); | |
| 78 | }); |