forked from ben-eb/gulp-uncss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
63 lines (45 loc) · 1.38 KB
/
test.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
'use strict';
var test = require('tape'),
gutil = require('gulp-util'),
uncss = require('./'),
Stream = require('stream'),
html = '<html><body><h1>hello</h1></body></html>',
css = 'h2 { color:blue; } h1 { color:red }',
output = 'h1 {\n color: red;\n}\n';
function fixture (contents) {
return new gutil.File({
contents: contents,
cwd: __dirname,
base: __dirname,
path: __dirname + '/fixture.css'
});
}
test('should remove unused css selectors', function (t) {
t.plan(1);
var stream = uncss({html: html});
stream.on('data', function (data) {
t.equal(String(data.contents), output);
});
var file = fixture(new Buffer(css));
stream.write(file);
});
test('should throw an error in stream mode', function (t) {
t.plan(1);
var stream = uncss({html: html});
var file = fixture(new Stream());
var write = function () {
stream.write(file);
file.contents.write(css);
file.contents.end();
};
t.throws(write, 'should not support streaming contents');
});
test('should let null files pass through', function (t) {
t.plan(1);
var stream = uncss({html: html});
stream.on('data', function (data) {
t.equal(data.contents, null, 'should not transform null in any way');
});
var file = fixture(null);
stream.write(file);
});