forked from rameel/gulp-bytediff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
64 lines (53 loc) · 1.64 KB
/
test.js
File metadata and controls
64 lines (53 loc) · 1.64 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
/* global describe, it */
"use strict";
const bytediff = require("./index");
const expect = require("chai").expect;
const gulp = require("gulp");
const map = require("map-stream");
const vinyl = require("vinyl");
function fixture(contents) {
return new vinyl({
contents: contents,
cwd: __dirname,
base: __dirname,
path: __dirname + "/fixture.css"
});
}
describe("gulp-bytediff", () => {
it("should be able to report the new size of a file", cb => {
let output = "";
process.stdout.write = (write => {
return function(text) {
output = text;
write.apply(process.stdout, arguments);
};
})(process.stdout.write);
gulp.src("./index.js")
.pipe(bytediff.start())
.pipe(map((file, done) => {
file.contents = new Buffer("minification happened");
done(null, file);
}))
.pipe(bytediff.stop())
.pipe(map(() => {
expect(output).to.have.string("21 B");
cb();
}));
});
it("should store the original size on the file object", cb => {
const stream = bytediff.start();
stream.on("data", data => {
expect(data.bytediff.startSize).to.eql(5);
cb();
});
stream.write(fixture(new Buffer("hello")));
});
it("should pass null contents through", cb => {
const stream = bytediff.start();
stream.on("data", data => {
expect(data.contents).to.eql(null);
cb();
});
stream.write(fixture(null));
});
});