test.js
4.46 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
var expect = require('chai').expect,
through = require('through2'),
gutil = require('gulp-util'),
fs = require('fs'),
path = require('path'),
concatCss = require('../');
function expected(file) {
var base = path.join(process.cwd(), 'test/expected');
var filepath = path.resolve(base, file);
return new gutil.File({
path: filepath,
cwd: process.cwd(),
base: base,
contents: fs.readFileSync(filepath)
});
}
function fixture(file) {
var base = path.join(process.cwd(), 'test/fixtures');
var filepath = path.join(base, file);
return new gutil.File({
path: filepath,
cwd: process.cwd(),
base: base,
contents: fs.readFileSync(filepath)
});
}
describe('gulp-concat-css', function() {
it('should only bubble up imports', function(done) {
var now = Date.now();
var stream = concatCss('build/bundle-bubbleonly.css', {inlineImports: false, rebaseUrls: false});
var expectedFile = expected('build/bundle-bubbleonly.css');
stream
.pipe(through.obj(function(file, enc, cb) {
//fs.writeFileSync("bundle.css", file.contents);
expect(String(file.contents)).to.be.equal(String(expectedFile.contents));
expect(path.basename(file.path)).to.be.equal(path.basename(expectedFile.path));
expect(file.cwd, "cwd").to.be.equal(expectedFile.cwd);
expect(file.relative, "relative").to.be.equal(expectedFile.relative);
console.log('Execution time: ' + (Date.now() - now) + 'ms');
done();
}));
stream.write(fixture('main.css'));
stream.write(fixture('vendor/vendor.css'));
stream.end();
});
it('should only rebase urls', function(done) {
var now = Date.now();
var stream = concatCss('build/bundle-rebase.css', {inlineImports: false});
var expectedFile = expected('build/bundle-rebase.css');
stream
.pipe(through.obj(function(file, enc, cb) {
//fs.writeFileSync("bundle.css", file.contents);
expect(String(file.contents)).to.be.equal(String(expectedFile.contents));
expect(path.basename(file.path)).to.be.equal(path.basename(expectedFile.path));
expect(file.cwd, "cwd").to.be.equal(expectedFile.cwd);
expect(file.relative, "relative").to.be.equal(expectedFile.relative);
console.log('Execution time: ' + (Date.now() - now) + 'ms');
done();
}));
stream.write(fixture('main.css'));
stream.write(fixture('vendor/vendor.css'));
stream.end();
});
it('should only inline imports', function(done) {
var now = Date.now();
var stream = concatCss('build/bundle-import.css', {inlineImports: true, rebaseUrls: false});
var expectedFile = expected('build/bundle-import.css');
stream
.pipe(through.obj(function(file, enc, cb) {
//fs.writeFileSync("bundle.css", file.contents);
expect(String(file.contents)).to.be.equal(String(expectedFile.contents));
expect(path.basename(file.path)).to.be.equal(path.basename(expectedFile.path));
expect(file.cwd, "cwd").to.be.equal(expectedFile.cwd);
expect(file.relative, "relative").to.be.equal(expectedFile.relative);
console.log('Execution time: ' + (Date.now() - now) + 'ms');
done();
}));
stream.write(fixture('main.css'));
stream.write(fixture('vendor/vendor.css'));
stream.end();
});
it('should concat, rebase urls, inline imports and bubble up external imports', function(done) {
var now = Date.now();
var stream = concatCss('build/bundle-all.css');
var expectedFile = expected('build/bundle-all.css');
stream
.pipe(through.obj(function(file, enc, cb) {
//fs.writeFileSync("bundle.css", file.contents);
expect(String(file.contents)).to.be.equal(String(expectedFile.contents));
expect(path.basename(file.path)).to.be.equal(path.basename(expectedFile.path));
expect(file.cwd, "cwd").to.be.equal(expectedFile.cwd);
expect(file.relative, "relative").to.be.equal(expectedFile.relative);
console.log('Execution time: ' + (Date.now() - now) + 'ms');
done();
}));
stream.write(fixture('main.css'));
stream.write(fixture('vendor/vendor.css'));
stream.end();
});
it('should not crash if no file is provided', function(done) {
var stream = concatCss('build/bundle-all.css');
stream
.on('error', function() {
done(false);
})
.pipe(through.obj(function(file, enc, cb) {
done(false);
}, function() {
done();
}));
stream.end();
});
});