| OLD | NEW |
| (Empty) | |
| 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() { |
| 25 expect(m.validateMessage('fixup! fix($compile): something')).toBe(VALID); |
| 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); |
| 33 expect(m.validateMessage('chore(foo-bar): something')).toBe(VALID); |
| 34 expect(m.validateMessage('chore(*): something')).toBe(VALID); |
| 35 expect(m.validateMessage('chore(guide/location): something')).toBe(VALID); |
| 36 expect(m.validateMessage('revert(foo): something')).toBe(VALID); |
| 37 expect(errors).toEqual([]); |
| 38 }); |
| 39 |
| 40 |
| 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... "; |
| 43 |
| 44 expect(m.validateMessage(msg)).toBe(INVALID); |
| 45 expect(errors).toEqual(['INVALID COMMIT MSG: is longer than 100 characters
!']); |
| 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); |
| 53 expect(errors).toEqual(['INVALID COMMIT MSG: does not match "<type>(<scope
>): <subject>" ! was: not correct format']); |
| 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(VAL
ID); |
| 70 }); |
| 71 |
| 72 |
| 73 it('should ignore msg prefixed with "WIP: "', function() { |
| 74 expect(m.validateMessage('WIP: bullshit')).toBe(VALID); |
| 75 }); |
| 76 }); |
| 77 }); |
| OLD | NEW |