/
stream.test.ts
50 lines (45 loc) · 1.41 KB
/
stream.test.ts
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
import es from 'event-stream';
import internal, { PassThrough } from "stream";
import File from "vinyl";
import gulpPurgecss from "../src/";
describe("gulp-purgecss with stream", () => {
let myGulpPurgecss: internal.Transform;
let fileTest: File.StreamFile;
let fakeStream: internal.PassThrough;
beforeEach(() => {
fakeStream = new PassThrough();
fakeStream.write(Buffer.from(".unused, .used,"));
fakeStream.write(Buffer.from(" a { color:"));
fakeStream.write(Buffer.from(" blue; }"));
fakeStream.end();
fileTest = new File({
contents: fakeStream,
});
myGulpPurgecss = gulpPurgecss({
content: ["./packages/gulp-purgecss/__tests__/test.html"],
});
});
// it("returns a stream", (done) => {
// expect.assertions(1);
// myGulpPurgecss.write(fileTest);
// myGulpPurgecss.once("data", (file) => {
// expect(file.isStream()).toBe(true);
// done();
// });
// });
it("returns a purged css stream", (done) => {
expect.assertions(3);
myGulpPurgecss.write(fileTest);
myGulpPurgecss.on("data", (file: File.StreamFile) => {
file.contents.pipe(
es.wait((_err: any, data: string) => {
expect(data.includes("used")).toBe(true);
expect(data.includes("unused")).toBe(false);
expect(data.includes("a")).toBe(true);
done();
})
);
});
// myGulpPurgecss.on("end", done);
});
});