|
36831ec
mzgol authored
|
||
| 1 | /* global describe: false, beforeEach: false, it: false, expect: false, spyOn: false */ | |
| 2 | 'use strict'; | |
| 3 | ||
|
5dbd942
vojtajina authored
|
||
| 4 | describe('validate-commit-msg.js', function() { | |
| 5 | var m = require('./validate-commit-msg'); | |
| 6 | var errors = []; | |
| 7 | var logs = []; | |
| 8 | ||
| 9 | var VALID = true; | |
| 10 | var INVALID = false; | |
| 11 | ||
| 12 | beforeEach(function() { | |
| 13 | errors.length = 0; | |
| 14 | logs.length = 0; | |
| 15 | ||
| 16 | spyOn(console, 'error').andCallFake(function(msg) { | |
| 17 | errors.push(msg.replace(/\x1B\[\d+m/g, '')); // uncolor | |
| 18 | }); | |
| 19 | ||
| 20 | spyOn(console, 'log').andCallFake(function(msg) { | |
| 21 | logs.push(msg.replace(/\x1B\[\d+m/g, '')); // uncolor | |
| 22 | }); | |
| 23 | }); | |
| 24 | ||
| 25 | describe('validateMessage', function() { | |
| 26 | ||
| 27 | it('should be valid', function() { | |
|
6131521
mhevery authored
|
||
| 28 | expect(m.validateMessage('fixup! fix($compile): something')).toBe(VALID); | |
|
5dbd942
vojtajina authored
|
||
| 29 | expect(m.validateMessage('fix($compile): something')).toBe(VALID); | |
| 30 | expect(m.validateMessage('feat($location): something')).toBe(VALID); | |
| 31 | expect(m.validateMessage('docs($filter): something')).toBe(VALID); | |
| 32 | expect(m.validateMessage('style($http): something')).toBe(VALID); | |
| 33 | expect(m.validateMessage('refactor($httpBackend): something')).toBe(VALID); | |
| 34 | expect(m.validateMessage('test($resource): something')).toBe(VALID); | |
| 35 | expect(m.validateMessage('chore($controller): something')).toBe(VALID); | |
|
175e727
IgorMinar authored
|
||
| 36 | expect(m.validateMessage('chore(foo-bar): something')).toBe(VALID); | |
| 37 | expect(m.validateMessage('chore(*): something')).toBe(VALID); | |
|
7b52a97
IgorMinar authored
|
||
| 38 | expect(m.validateMessage('chore(guide/location): something')).toBe(VALID); | |
|
cfe13b5
IgorMinar authored
|
||
| 39 | expect(m.validateMessage('revert(foo): something')).toBe(VALID); | |
|
5dbd942
vojtajina authored
|
||
| 40 | expect(errors).toEqual([]); | |
| 41 | }); | |
| 42 | ||
| 43 | ||
|
1ae34aa
IgorMinar authored
|
||
| 44 | it('should validate 100 characters length', function() { | |
| 45 | var msg = "fix($compile): something super mega extra giga tera long, maybe even longer and longer and longer... "; | |
|
5dbd942
vojtajina authored
|
||
| 46 | ||
| 47 | expect(m.validateMessage(msg)).toBe(INVALID); | |
|
1ae34aa
IgorMinar authored
|
||
| 48 | expect(errors).toEqual(['INVALID COMMIT MSG: is longer than 100 characters !']); | |
|
5dbd942
vojtajina authored
|
||
| 49 | }); | |
| 50 | ||
| 51 | ||
| 52 | it('should validate "<type>(<scope>): <subject>" format', function() { | |
| 53 | var msg = 'not correct format'; | |
| 54 | ||
| 55 | expect(m.validateMessage(msg)).toBe(INVALID); | |
|
6131521
mhevery authored
|
||
| 56 | expect(errors).toEqual(['INVALID COMMIT MSG: does not match "<type>(<scope>): <subject>" ! was: not correct format']); | |
|
5dbd942
vojtajina authored
|
||
| 57 | }); | |
| 58 | ||
| 59 | ||
| 60 | it('should validate type', function() { | |
| 61 | expect(m.validateMessage('weird($filter): something')).toBe(INVALID); | |
| 62 | expect(errors).toEqual(['INVALID COMMIT MSG: "weird" is not allowed type !']); | |
| 63 | }); | |
| 64 | ||
| 65 | ||
| 66 | it('should allow empty scope', function() { | |
| 67 | expect(m.validateMessage('fix: blablabla')).toBe(VALID); | |
| 68 | }); | |
| 69 | ||
| 70 | ||
| 71 | it('should allow dot in scope', function() { | |
| 72 | expect(m.validateMessage('chore(mocks.$httpBackend): something')).toBe(VALID); | |
| 73 | }); | |
| 74 | ||
| 75 | ||
| 76 | it('should ignore msg prefixed with "WIP: "', function() { | |
| 77 | expect(m.validateMessage('WIP: bullshit')).toBe(VALID); | |
| 78 | }); | |
| 79 | }); | |
| 80 | }); |