-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathisEqual.js
More file actions
187 lines (139 loc) · 6.57 KB
/
isEqual.js
File metadata and controls
187 lines (139 loc) · 6.57 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
var fs = require('fs'),
path = require('path'),
fixturesPath = path.join(__dirname, 'fixtures'),
HtmlDiffer = require('../../lib/index').HtmlDiffer;
/**
* @param {String} basename
* @returns {Object}
*/
function readFiles(basename) {
var fileName = basename + '.html';
return {
html1: fs.readFileSync(path.join(fixturesPath, 'first', fileName), 'utf-8'),
html2: fs.readFileSync(path.join(fixturesPath, 'second', fileName), 'utf-8')
};
}
describe('\'isEqual\'', function () {
it('must be equal', function () {
var htmlDiffer = new HtmlDiffer(),
files = readFiles('equal');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must be not equal', function () {
var htmlDiffer = new HtmlDiffer(),
files = readFiles('not-equal');
htmlDiffer.isEqual(files.html1, files.html2).must.be.false();
});
it('must consider uppercase and lowercase declarations in \'doctype\' to be equal', function () {
var htmlDiffer = new HtmlDiffer(),
files = readFiles('doctype');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must sort attributes', function () {
var htmlDiffer = new HtmlDiffer(),
files = readFiles('sort-attributes');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must sort classes\' values', function () {
var htmlDiffer = new HtmlDiffer(),
files = readFiles('sort-classes');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must sort values of attributes as JSON when the content is not a function', function () {
var htmlDiffer = new HtmlDiffer({ compareAttributesAsJSON: ['a', { name: 'b', isFunction: false }] }),
files = readFiles('sort-values-in-json-format');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must handle invalid JSON', function () {
var htmlDiffer = new HtmlDiffer({ compareAttributesAsJSON: ['data-bem'] }),
files = readFiles('invalid-json');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must sort values of attributes as JSON when the content is a function', function () {
var options = {
compareAttributesAsJSON: [
{ name: 'onclick', isFunction: true },
{ name: 'ondblclick', isFunction: true }
]
},
htmlDiffer = new HtmlDiffer(options),
files = readFiles('sort-functions-in-json-format');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must handle invalid function', function () {
var options = { compareAttributesAsJSON: [{ name: 'onclick', isFunction: true }] },
htmlDiffer = new HtmlDiffer(options),
files = readFiles('invalid-function');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must work option \'ignoreAttributes\'', function () {
var htmlDiffer = new HtmlDiffer({ ignoreAttributes: ['id', 'for'] }),
files = readFiles('ignore-attributes');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must work option \'ignoreWhitespaces\'', function () {
var htmlDiffer = new HtmlDiffer({ ignoreWhitespaces: true }),
files = readFiles('ignore-whitespaces');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must work option \'ignoreComments\'', function () {
var htmlDiffer = new HtmlDiffer(),
files = readFiles('ignore-comments');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must does NOT work option \'ignoreComments\'', function () {
var htmlDiffer = new HtmlDiffer({ ignoreComments: false }),
files = readFiles('ignore-comments-false');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must work option \'ignoreEndTags\'', function () {
var htmlDiffer = new HtmlDiffer({ ignoreEndTags: true }),
files = readFiles('ignore-end-tags');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must work option \'ignoreDuplicateAttributes\'', function () {
var htmlDiffer = new HtmlDiffer({ ignoreDuplicateAttributes: true }),
files = readFiles('ignore-duplicate-attributes');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must not ignore duplicate attributes', function () {
var htmlDiffer = new HtmlDiffer({ ignoreDuplicateAttributes: false }),
files = readFiles('ignore-duplicate-attributes');
htmlDiffer.isEqual(files.html1, files.html2).must.be.false();
});
it('must work option \'ignoreEmptyAttributes\'', function () {
var htmlDiffer = new HtmlDiffer({ ignoreEmptyAttributes: true }),
files = readFiles('ignore-empty-attributes');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must not ignore empty attributes', function () {
var htmlDiffer = new HtmlDiffer({ ignoreEmptyAttributes: false }),
files = readFiles('ignore-empty-attributes');
htmlDiffer.isEqual(files.html1, files.html2).must.be.false();
});
it('must work options \'ignoreAttributes\' and \'ignoreEmptyAttributes\'', function () {
var htmlDiffer = new HtmlDiffer({ ignoreAttributes: ['id', 'for'], ignoreEmptyAttributes: true }),
files = readFiles('ignore-attributes-empty');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must not ignore attributes', function () {
var htmlDiffer = new HtmlDiffer({ }),
files = readFiles('ignore-attributes-empty');
htmlDiffer.isEqual(files.html1, files.html2).must.be.false();
});
it('must work \'bem\' preset', function () {
var htmlDiffer = new HtmlDiffer('bem'),
files = readFiles('bem-preset');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must work mask {{RegExp}}', function () {
var htmlDiffer = new HtmlDiffer(),
files = readFiles('mask');
htmlDiffer.isEqual(files.html1, files.html2).must.be.true();
});
it('must not be equal by mask {{RegExp}}', function () {
var htmlDiffer = new HtmlDiffer(),
files = readFiles('mask-false');
htmlDiffer.isEqual(files.html1, files.html2).must.be.false();
});
});