tests.js
1.6 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
var vows = require('vows'),
assert = require('assert'),
path = require('path'),
fs = require('fs'),
exists = fs.existsSync || path.existsSync,
base = path.join(__dirname, './files'),
cssmin = require('../cssmin').cssmin,
files = fs.readdirSync(base),
tests = {
'should be loaded': {
topic: function() {
return require('../cssmin').cssmin;
},
'should be a function': function(topic) {
assert.isFunction(topic);
}
}
};
files.forEach(function(file) {
if (path.extname(file) === '.css') {
var comp = path.join(base, file + '.min');
if (exists(comp)) {
tests['should be loaded'][file] = (function(file) {
var expected = (fs.readFileSync(path.join(base, file + '.min'), 'utf8')).trim(),
str = (fs.readFileSync(path.join(base, file), 'utf8')).trim();
return function(topic) {
var out = topic(str);
assert.equal(expected, out);
};
}(file));
}
}
});
//Line Break Test
(function() {
var file = 'linebreakpos.css';
tests['should be loaded']['and should handle linebreak'] = (function(file) {
var expected = (fs.readFileSync(path.join(base, 'special', file + '.min'), 'utf8')).trim(),
str = (fs.readFileSync(path.join(base, 'special', file), 'utf8')).trim();
return function(topic) {
var out = topic(str, 100);
assert.equal(expected, out);
};
}(file));
}());
vows.describe('cssmin tests').addBatch(tests).export(module);