forked from drublic/gulp-css-background-remove
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
68 lines (55 loc) · 2.03 KB
/
test.js
File metadata and controls
68 lines (55 loc) · 2.03 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
/* eslint-env mocha */
'use strict';
var path = require('path');
var assert = require('assert');
var gutil = require('gulp-util');
var cssBackgroundRemove = require('./');
var generateFile = function (content) {
return new gutil.File({
cwd: __dirname,
base: path.join(__dirname, 'fixture'),
path: path.join(__dirname, 'fixture', 'fixture.css'),
contents: new Buffer(content)
});
};
it('should move background to separate CSS', function (cb) {
var stream = cssBackgroundRemove({
dest: 'dist/',
filename: 'image.css'
});
stream.on('data', function (file) {
assert(file.contents.toString(), 'a {\n\tcolor: #ddd;\n}\na {\n\tcolor: #fff;\n}');
assert.equal(file.relative, 'fixture.css');
});
stream.on('end', cb);
stream.write(generateFile('a {\n\tbackground: url("test.png"); background-image: url("test.png"); color: #ddd;\n}\na {\n\tcolor: #fff;\n}'));
stream.end();
});
it('should not move un-url-like property to separate CSS', function (cb) {
var stream = cssBackgroundRemove({
dest: 'dist/',
filename: 'image.css'
});
stream.on('data', function (file) {
assert(file.contents.toString(), 'a {\n\tbackground: #ddd; color: #ddd;\n}\na {\n\tcolor: #fff;\n}');
});
stream.on('end', cb);
stream.write(generateFile('a {\n\tbackground: #ddd; color: #ddd;\n}\na {\n\tcolor: #fff;\n}'));
stream.end();
});
it('should be possible to get a stream from the image properties', function (cb) {
var stream = cssBackgroundRemove({
writeImagesFile: false
});
stream.images(function (imagesStream) {
imagesStream.on('data', function (file) {
assert(file.contents.toString(), 'div {\n\tbackground-image: url(image.png);\n}');
})
});
stream.on('data', function (file) {
assert(file.contents.toString(), 'a {\n\tbackground: #ddd; color: #ddd;\n}\na {\n\tcolor: #fff;\n}');
});
stream.on('end', cb);
stream.write(generateFile('a {\n\tbackground: #ddd; color: #ddd;\n}\na {\n\tcolor: #fff;\n}\ndiv {\n\tbackground-image: url(image.jpg);\n}'));
stream.end();
});