-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
117 lines (87 loc) · 4.63 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var assert = require('assert');
var cssSemver = require('./index')
describe('cssSemver', function() {
// major
it('Should return major when changed is null', function() {
assert.equal('major', cssSemver('.test{color: #000;}',null));
});
it('Should return major when changed has less selectors than old', function() {
assert.equal('major', cssSemver('.test{color: #000;} .deleted{display:none}','.test{color: #000;}'));
});
it('Should return major when changed has less selectors than old and another rule change occured', function() {
assert.equal('major', cssSemver('.test{color: #000;} .deleted{display:none}','.test{color: #fff;}'));
});
it('Should return major when changed has less selectors than old and another selector was added', function() {
assert.equal('major', cssSemver('.test{color: #000;} .deleted{display:none}','.test{color: #fff;} .added{visibility: hidden}'));
});
it('Should return major on nested selector change', function() {
assert.equal('major', cssSemver('.parent .child{color: #000;}','.parent .other-child {color: #000;}'));
});
// minor
it('Should return minor whit only changed content and old is null', function() {
assert.equal('minor', cssSemver(null,'.test{color: #000;}'));
});
it('Should return minor when changed has more selectors than old', function() {
assert.equal('minor', cssSemver('.test{color: #000;}', '.test{color: #000;} .added{display:none}'));
});
it('Should return minor when changed has more selectors than old and another rule change occured', function() {
assert.equal('minor', cssSemver('.test{color: #000;}', '.test{color: #fff;} .added{display:none}'));
});
it('Should return minor when changed has more selectors on the same rule', function() {
assert.equal('minor', cssSemver('.test{color: #000;}', '.test, .added{color: #fff;} '));
});
// patch
it('Should return patch when selectors are equal but content of rules is different', function() {
assert.equal('patch', cssSemver('.test{color: #000;} .unchanged{display:none}','.test{color: #fff;} .unchanged{display:none}'));
});
it('Should return patch when selectors are equal but selectors are grouped differently', function() {
assert.equal('patch', cssSemver('.a, .b{color: #000;}','.a{color: #000;} .b{color: #000;}'));
});
it('Should return patch when selectors are equal but selectors are ordered differently', function() {
assert.equal('patch', cssSemver('.b{color: #000;} .a{color: #fff;}','.a{color: #fff;} .b{color: #000;}'));
});
it('Should return patch when selectors are not equal and selectors are ordered differently, complex', function() {
assert.equal('patch', cssSemver('.b{color: #ddd; width: 33px} .a{color: #fff; width: 33px}','.a{color: #fff; width: 33px} .b{color: #000; width: 33px}'));
});
// null
it('Should return null when no values are defined', function() {
assert.equal(null, cssSemver());
});
it('Should return null when both values are null', function() {
assert.equal(null, cssSemver(null, null));
});
it('Should return null when old and changed are equal', function() {
assert.equal(null, cssSemver('.a{display:none} .b{color: #000;} ',' .a {display:none} .b {color: #000;}'));
});
it('Should return null when selectors and content are equal but has different withespace', function() {
assert.equal(null, cssSemver('.a{display:none;} .b{color: #000;} ',' .a {display:none} .b {color: #000;}', {verbose:true}));
});
// verbose mode
var originalLog;
var logStack = [];
function enableMockLog (){
originalLog = console.log;
console.log = function (message) {
logStack.push(message);
};
}
function disableMockLog() {
console.log = originalLog;
logStack = [];
}
try{
it('Should work with verbose mode when changed has less selectors than old and another selector was added', function() {
enableMockLog();
assert.equal('major', cssSemver('.test{color: #000;} .deleted{display:none}','.test{color: #fff;} .added{visibility: hidden}', {verbose: true}));
assert.equal(logStack.length, 4);
disableMockLog();
});
// comments in css
it('Should not return null and fail when a comment exists in the css', function() {
assert.equal('patch', cssSemver('.test{color: #000;} .unchanged{display:none} /* this is a comment */','.test{color: #fff;} .unchanged{display:none}'));
});
} catch(e){
disableMockLog()
console.log(e)
}
});