-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
73 lines (54 loc) · 1.98 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
/* Modules */
var assert = require('assert');
var gutil = require('gulp-util');
var sourcemaps = require('gulp-sourcemaps');
var pixrem = require('./');
/* Helpers */
var regex = /sourceMappingURL=data:application\/json;base64/;
function fixture(content) {
var file = new gutil.File({
contents: new Buffer(content),
cwd: __dirname,
base: __dirname,
path: __dirname + '/fixture.css'
});
return file;
}
/* Tests */
describe('gulp-pixrem', function() {
it('should postprocess CSS using Pixrem with the default pixel root value', function(done) {
var stream = pixrem();
stream.on('data', function(data) {
assert.equal(data.contents.toString(), 'code { font-size: 14px; font-size: 0.875rem; }');
done();
});
stream.write(fixture('code { font-size: 0.875rem; }'));
});
it('should postprocess CSS using Pixrem with a custom pixel root value', function(done) {
var stream = pixrem({ rootValue: '10px' });
stream.on('data', function(data) {
assert.equal(data.contents.toString(), 'code { font-size: 10px; font-size: 1rem; }');
done();
});
stream.write(fixture('code { font-size: 1rem; }'));
});
it('should postprocess CSS using Pixrem with a custom pixel root value set in the html tag', function(done) {
var stream = pixrem({ rootValue: '100%', replace: true });
stream.on('data', function(data) {
assert.equal(data.contents.toString(), 'html { font-size: 12px; } code { font-size: 12px; }');
done();
});
stream.write(fixture('html { font-size: 12px; } code { font-size: 1rem; }'));
});
it('should postprocess CSS using Pixrem with sourcemaps', function(done) {
var stream = sourcemaps.init();
var write = sourcemaps.write();
stream.pipe(pixrem()).pipe(write);
write.on('data', function(data) {
var results = data.contents.toString();
assert.ok(regex.test(results));
done();
});
stream.write(fixture('code { font-size: 1rem; }'));
});
});