-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
230 lines (192 loc) · 7.71 KB
/
test.js
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
var gulp = require("gulp"),
should = require("should"),
assert = require("stream-assert"),
intoStream = require("into-stream"),
Q = require("q"),
proxyquire = require("proxyquire"),
chutzpah = require("./index.js");
var PATH_TO_CHUTZPAH = "/path/to/chutzpah.runner.exe";
function getChutzpahWithProxy(proxyObj){
return proxyquire("./index.js", proxyObj);
};
function getCommandPromise(optionalConfigs, sourceFiles, execOptions){
sourceFiles = sourceFiles || "index.js";
execOptions = execOptions || {};
var deferred = Q.defer();
var chutzpah = getChutzpahWithProxy({"child_process": {"exec": function(command, opts){
deferred.resolve({ command: command, opts: opts });
}}});
if(typeof optionalConfigs.executable !== "string")
optionalConfigs.executable = PATH_TO_CHUTZPAH
gulp.src(sourceFiles)
.pipe(chutzpah(optionalConfigs, execOptions))
.pipe(assert.end(function(){}))
.end();
return deferred.promise;
};
describe("gulp-chutzpah", function(){
describe("when calling chutzpah()", function(){
const pluginErrorMessage = "gulp-chutzpah: path to chutzpah runner must be specified using the property named 'executable'.";
it("should throw when called without any argument", function(){
(function(){
chutzpah();
}).should.throw(pluginErrorMessage);
});
it("should throw when called without `executable` path", function(){
(function(){
chutzpah({foo: "bar"});
}).should.throw(pluginErrorMessage);
});
it("should not throw when `executable` is specified", function(){
(function(){
chutzpah({executable: PATH_TO_CHUTZPAH})
}).should.not.throw();
});
});
describe("when handling content", function(){
var pluginStream = null;
beforeEach(function(){
var chutzpah = getChutzpahWithProxy({ "child_process": {"exec": function() {} } });
pluginStream = chutzpah({
"executable": PATH_TO_CHUTZPAH
});
});
it("should ignore null files", function(done){
pluginStream
.pipe(assert.length(0))
.pipe(assert.end(done))
.end();
});
it("should not throw on stream contents", function(done){
var stream = gulp.src("*.js", {buffer: false});
(function(){
stream
.pipe(pluginStream)
.pipe(assert.end(done))
.end();
}).should.not.throw();
});
it("should not throw on buffered contents", function(done){
var stream = gulp.src("*.js", {buffer: true});
(function(){
stream
.pipe(pluginStream)
.pipe(assert.end(done))
.end();
}).should.not.throw();
});
it("should not add any content", function(done){
intoStream(["lorem", "ipsum"])
.pipe(pluginStream)
.pipe(assert.length(2))
.pipe(assert.end(done))
.end();
});
it("should not modify any content", function(done){
function shouldBe(expected){
return function(actual){
actual.should.equal(expected);
};
};
intoStream.obj(["lorem", "ipsum", "dolor", 42])
.pipe(pluginStream)
.pipe(assert.first(shouldBe("lorem")))
.pipe(assert.second(shouldBe("ipsum")))
.pipe(assert.nth(2, shouldBe("dolor")))
.pipe(assert.last(shouldBe(42)))
.pipe(assert.end(done))
.end();
});
});
describe("when considering chutzpah configuration", function(){
it("should ignore unknown parameters", function(){
return getCommandPromise({
"who-am-i": "dont-know"
}).then(function (data) {
data.command.should.not.containEql("who-am-i");
});
});
it("should work with boolean parameters", function(){
return getCommandPromise({
"silent": true
}).then(function (data) {
data.command.should.containEql(" /silent");
});
});
it("should work with optional value parameters without any specific value", function(){
return getCommandPromise({
"openInBrowser": true
}).then(function (data) {
data.command.should.containEql(" /openInBrowser");
});
});
it("should work with optional value parameters with specific value", function(){
return getCommandPromise({
"openInBrowser": "Chrome"
}).then(function (data) {
data.command.should.containEql(" /openInBrowser Chrome");
});
});
it("should work with different types of parameters together", function(){
return getCommandPromise({
"parallelism": 4,
"openInBrowser": true,
"coverage": true,
"coveragehtml": "/path/to/coverage.html"
}).then(function (data) {
data.command.should.containEql(" /parallelism 4")
.and.containEql(" /openInBrowser")
.and.containEql(" /coverage")
.and.containEql(" /coveragehtml /path/to/coverage.html");
});
});
});
describe("when using chutzpah with settings file", function() {
it("should generate proper command", function() {
return getCommandPromise({
isSettingsFile: true
}, "package.json")
.then(function (data) {
data.command.should.containEql(PATH_TO_CHUTZPAH)
.and.containEql("package.json");
});
});
it("should ignore all other settings", function() {
return getCommandPromise({
isSettingsFile: true,
"parallelism": 4,
"openInBrowser": true
}, "package.json")
.then(function (data) {
data.command.should.not.containEql("/parallelism")
.and.not.containEql("/openInBrowser");
});
});
});
describe("when using chutzpah with child_process.exec options", function () {
var optionalConfigDummy = {},
execOptionsEmptyStub = {};
it("should call child_process.exec with specified options", function () {
var maxBufferDummy = 10000 * 1024,
execOptionsWithMaxBufferStub = {
maxBuffer: maxBufferDummy
};
return getCommandPromise(optionalConfigDummy, "package.json", execOptionsWithMaxBufferStub)
.then(function (data) {
data.opts.should.containEql(execOptionsWithMaxBufferStub);
});
});
it("should ignore undefined options", function () {
return getCommandPromise(optionalConfigDummy, "package.json")
.then(function (data) {
data.opts.should.containEql(execOptionsEmptyStub);
});
});
it("should ignore null options", function () {
return getCommandPromise(optionalConfigDummy, "package.json", null)
.then(function (data) {
data.opts.should.containEql(execOptionsEmptyStub);
});
});
});
});