-
Notifications
You must be signed in to change notification settings - Fork 754
/
recipes.js
131 lines (119 loc) · 4.04 KB
/
recipes.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
require("source-map-support").install();
var path = require("path");
var pkg = require(path.resolve("package.json"));
var sinon = require("sinon");
var logger = require("../../../dist/logger").logger;
var assert = require("chai").assert;
var cli = require(path.resolve(pkg.bin)).default;
var fs = require("fs");
var rim = require("rimraf").sync;
describe("E2E CLI `recipes` command", function() {
it("works with no output flag", function(done) {
rim("./server");
cli({
cli: {
input: ["recipe", "server"],
flags: {}
},
cb: function() {
assert.isTrue(fs.existsSync("./server"));
rim("./server");
done();
}
});
});
it("lists all available when no second arg given", function(done) {
var stub1 = sinon.stub(logger, "info");
var stub2 = sinon.stub(console, "log");
cli({
cli: {
input: ["recipe"],
flags: {}
},
cb: function() {
sinon.assert.calledWith(stub1, "No recipe name provided!");
sinon.assert.calledWith(
stub1,
"Install one of the following with {cyan:browser-sync recipe <name>\n"
);
logger.info.restore();
console.log.restore();
var calls = stub2.getCalls().map(function(call) {
return call.args[0].trim();
});
assert.include(calls, "gulp.pug");
assert.include(calls, "server");
assert.include(calls, "html.injection");
done();
}
});
});
it("Does not overwrite existing dir", function(done) {
cli({
cli: {
input: ["recipe", "server"],
flags: {
output: "test/fixtures"
}
},
cb: function(err) {
assert.equal(
err.message,
"Target folder exists remove it first and then try again"
);
done();
}
});
});
it("accepts --output flag", function(done) {
var stub1 = sinon.stub(logger, "info");
cli({
cli: {
input: ["recipe", "server"],
flags: {
output: "test/recipes/server1"
}
},
cb: function() {
var dir = path.resolve("./test/recipes/server1");
assert.isTrue(fs.existsSync("test/recipes/server1"));
rim("test/recipes/server1");
var call1 = stub1.getCall(0).args;
assert.equal(call1[0], "Recipe copied into {cyan:%s}");
assert.equal(call1[1], dir);
sinon.assert.calledWith(
stub1,
"Next, inside that folder, run {cyan:npm i && npm start}"
);
logger.info.restore();
done();
}
});
});
it("Loges recipes when not found", function(done) {
var stub1 = sinon.stub(logger, "info");
var stub2 = sinon.stub(console, "log");
cli({
cli: {
input: ["recipe", "beepboop"],
flags: {}
},
cb: function(err) {
var call1 = stub1.getCall(0).args;
assert.equal(
call1[0],
"Recipe {cyan:%s} not found. The following are available though"
);
var calls = stub2.getCalls().map(function(call) {
return call.args[0].trim();
});
assert.include(calls, "gulp.pug");
assert.include(calls, "server");
assert.include(calls, "html.injection");
logger.info.restore();
console.log.restore();
done();
}
});
});
});