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.7 kb
e741107 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() {
25 expect(m.validateMessage('fix($compile): something')).toBe(VALID);
26 expect(m.validateMessage('feat($location): something')).toBe(VALID);
27 expect(m.validateMessage('docs($filter): something')).toBe(VALID);
28 expect(m.validateMessage('style($http): something')).toBe(VALID);
29 expect(m.validateMessage('refactor($httpBackend): something')).toBe(VALID);
30 expect(m.validateMessage('test($resource): something')).toBe(VALID);
31 expect(m.validateMessage('chore($controller): something')).toBe(VALID);
ace81c0 Igor Minar chore(validate-commit-msg): allow * and - in scope string
IgorMinar authored
32 expect(m.validateMessage('chore(foo-bar): something')).toBe(VALID);
33 expect(m.validateMessage('chore(*): something')).toBe(VALID);
537e200 Igor Minar chore(validate-commit-msg): allow '/' in scope
IgorMinar authored
34 expect(m.validateMessage('chore(guide/location): something')).toBe(VALID);
f5b567d Igor Minar chore(validate-commit-msg): recognize 'revert' as valid commit type
IgorMinar authored
35 expect(m.validateMessage('revert(foo): something')).toBe(VALID);
e741107 Vojta Jina chore(scripts): add commit-msg hook (validation)
vojtajina authored
36 expect(errors).toEqual([]);
37 });
38
39
40 it('should validate 70 characters length', function() {
41 var msg = 'fix($compile): something super mega extra giga tera long, maybe even longer... ' +
42 'way over 80 characters';
43
44 expect(m.validateMessage(msg)).toBe(INVALID);
45 expect(errors).toEqual(['INVALID COMMIT MSG: is longer than 70 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>" !']);
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.