This repository has been archived by the owner on Dec 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest.js
77 lines (54 loc) · 1.64 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'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 { color:red }';
function fixture (contents) {
return new gutil.File({
contents: contents,
cwd: __dirname,
base: __dirname,
path: __dirname + '/fixture.css'
});
}
test('should not throw on an empty file', function (t) {
t.plan(1);
var stream = uncss({html: html});
stream.on('data', function (data) {
t.equal(String(data.contents), '');
});
var file = fixture(new Buffer(''));
stream.write(file);
});
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);
});