1 |
|
2 | "use strict";
|
3 |
|
4 | var fs = require("fs"),
|
5 | es = require("event-stream"),
|
6 | should = require("should"),
|
7 | gutil = require("gulp-util"),
|
8 | espower = require("../");
|
9 |
|
10 | describe("gulp-espower", function () {
|
11 |
|
12 | it("should produce expected file via buffer", function (done) {
|
13 | var stream = espower(),
|
14 | srcFile = new gutil.File({
|
15 | path: "test/fixtures/example.js",
|
16 | cwd: "test/",
|
17 | base: "test/fixtures",
|
18 | contents: fs.readFileSync("test/fixtures/example.js")
|
19 | }),
|
20 | expectedFile = new gutil.File({
|
21 | path: "test/expected/example.js",
|
22 | cwd: "test/",
|
23 | base: "test/expected",
|
24 | contents: fs.readFileSync("test/expected/example.js")
|
25 | });
|
26 | stream.on("error", function(err) {
|
27 | should.exist(err);
|
28 | done(err);
|
29 | });
|
30 | stream.on("data", function (newFile) {
|
31 | should.exist(newFile);
|
32 | should.exist(newFile.contents);
|
33 | String(newFile.contents).should.equal(String(expectedFile.contents));
|
34 | done();
|
35 | });
|
36 | stream.write(srcFile);
|
37 | stream.end();
|
38 | });
|
39 |
|
40 |
|
41 | it("custom options", function (done) {
|
42 | var stream = espower({
|
43 | destructive: true,
|
44 | powerAssertVariableName: 'refute',
|
45 | targetMethods: {
|
46 | oneArg: [
|
47 | 'isNull'
|
48 | ],
|
49 | twoArgs: [
|
50 | 'same'
|
51 | ]
|
52 | }
|
53 | }),
|
54 | srcFile = new gutil.File({
|
55 | path: "test/fixtures/customized.js",
|
56 | cwd: "test/",
|
57 | base: "test/fixtures",
|
58 | contents: fs.readFileSync("test/fixtures/customized.js")
|
59 | }),
|
60 | expectedFile = new gutil.File({
|
61 | path: "test/expected/example.js",
|
62 | cwd: "test/",
|
63 | base: "test/expected",
|
64 | contents: fs.readFileSync("test/expected/customized.js")
|
65 | });
|
66 | stream.on("error", function(err) {
|
67 | should.exist(err);
|
68 | done(err);
|
69 | });
|
70 | stream.on("data", function (newFile) {
|
71 | should.exist(newFile);
|
72 | should.exist(newFile.contents);
|
73 | String(newFile.contents).should.equal(String(expectedFile.contents));
|
74 | done();
|
75 | });
|
76 | stream.write(srcFile);
|
77 | stream.end();
|
78 | });
|
79 |
|
80 |
|
81 | it("should error on stream", function (done) {
|
82 | var stream = espower(),
|
83 | srcFile = new gutil.File({
|
84 | path: "test/fixtures/example.js",
|
85 | cwd: "test/",
|
86 | base: "test/fixtures",
|
87 | contents: fs.createReadStream("test/fixtures/example.js")
|
88 | });
|
89 | stream.on("error", function(err) {
|
90 | should.exist(err);
|
91 | done();
|
92 | });
|
93 | stream.on("data", function (newFile) {
|
94 | newFile.contents.pipe(es.wait(function(err, data) {
|
95 | done(err);
|
96 | }));
|
97 | });
|
98 | stream.write(srcFile);
|
99 | stream.end();
|
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 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | });
|