-
Notifications
You must be signed in to change notification settings - Fork 164
/
test.js
362 lines (308 loc) · 8.89 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
var automate = require("guide-automation");
var isWindowsCI = require("is-appveyor");
var join = require("path").join;
var rimraf = require("rimraf").sync;
var streamWhen = require("stream-when");
var nodeVersion = +process.version.substr(1).split(".")[0];
// Only run in AppVeyor if version >= 5
if(isWindowsCI && nodeVersion < 5) {
process.exit(0);
}
var guide = automate({ spinner: true, log: true });
var wait = function(){
var ms = isWindowsCI ? 5000 : 2000;
return guide.wait(ms);
};
/**
* @Step 1
*/
guide.step("Remove existing dependencies", function(){
rimraf(join("node_modules", "donejs-cli"));
rimraf(join("node_modules", "generator-donejs"));
});
guide.step("Install donejs", function(){
var branch = process.env.TRAVIS_BRANCH || process.env.APPVEYOR_REPO_BRANCH || 'master';
return guide.executeCommand("npm", ["install", "donejs/donejs#" + branch, "-g"]);
});
// Move to a temp folder for the rest of the guide
guide.moveToTmp();
/**
* @Step 2
*/
guide.step("Run donejs add app", function(){
var init = guide.answerPrompts("donejs", ["add", "app", "donejs-chat", "--skip-install"]);
var answer = init.answer;
answer(/Project name/, "\n");
answer(/Project main folder/, "src\n");
answer(/Description/, "\n");
answer(/Project homepage url/, "\n");
answer(/GitHub username or organization/, "\n");
answer(/Author's Name/, "\n");
answer(/Author's Email/, "\n");
answer(/Author's Homepage/, "\n");
answer(/Application keywords/, "\n");
answer(/NPM version/, "\n");
return init.promise;
});
/**
* @Step 3
*/
guide.step("Move to donejs-chat folder", function(){
process.chdir("donejs-chat");
return guide.injectSpy("src/index.stache");
});
guide.step("Run NPM install", function() {
return guide.executeCommand("npm", ["install"]).then(guide.wait(10000));
});
/**
* @Step 4
*/
guide.step("Start donejs develop", function(){
var child = guide.canServe = guide.executeCommand("donejs", ["develop"]).childProcess;
console.log("done-serve running as", child.pid);
var server = streamWhen(child.stdout, /done-serve starting on/);
var liveReload = streamWhen(child.stderr, /Live-reload server/);
return Promise.all([server, liveReload]).then(wait);
});
guide.test(function(){
return guide.nodeTest(join(__dirname, "steps", "3-donejs-develop", "test.js"));
});
guide.launchBrowser("http://localhost:8080");
/**
* @Step 5
*/
guide.step("Install bootstrap", function(){
return guide.executeCommand("npm", ["install", "bootstrap", "--save"])
.then(wait)
.then(function(){
return guide.replaceFile(join("src", "index.stache"),
join(__dirname, "steps", "4-bootstrap", "index.stache"));
})
.then(function(){
return guide.injectSpy("src/index.stache");
})
.then(wait)
.then(wait);
});
guide.test(function(){
console.log("Running bootstrap tests");
return guide.functionalTest(join(__dirname, "steps", "4-bootstrap", "test.js"))
.then(wait);
});
/**
* @Step 6
*/
guide.step("Generate custom elements", function(){
return guide.executeCommand("donejs", ["add","component","home.component","chat-home"])
.then(function(){
return guide.executeCommand("donejs", ["add","component","messages",
"chat-messages"]);
}).then(wait);
});
/**
* @Step 7
*/
guide.step("Navigate between pages", function(){
return guide.replaceFile(join("src", "home.component"),
join(__dirname, "steps", "7-navigate", "home.component"))
.then(function(){
return guide.replaceFile(join("src", "messages", "messages.stache"),
join(__dirname, "steps", "7-navigate", "messages.stache"));
})
.then(function(){
return guide.replaceFile(join("src", "app.js"),
join(__dirname, "steps", "7-navigate", "app.js"));
})
.then(function(){
return guide.replaceFile(join("src", "index.stache"),
join(__dirname, "steps", "7-navigate", "index.stache"));
})
.then(function(){
return guide.injectSpy("src/index.stache");
})
.then(wait);
});
guide.test(function(){
return guide.functionalTest(join(__dirname, "steps", "7-navigate", "test.js"));
});
guide.test(function(){
return guide.nodeTest(join(__dirname, "steps", "7-navigate", "ssr_test.js"));
});
/**
* @Step 8
*/
guide.step("Install and use bit-tabs", function(){
function installWait(){
return guide.wait(10000);
}
return guide.executeCommand("npm", ["install", "bit-tabs@alpha", "--save"])
.then(installWait)
.then(function(){
return guide.replaceFile(join("src", "home.component"),
join(__dirname, "steps", "8-bit-tabs", "home.component"));
})
.then(wait);
});
guide.test(function(){
console.log("Running bit-tabs tests");
// Check that the tabs have appeared.
return guide.functionalTest(join(__dirname, "steps", "8-bit-tabs", "tabs_test.js"))
.then(wait);
});
/**
* @Step 9
*/
guide.step("Generate the Message model", function(){
var supermodel = guide.answerPrompts("donejs", ["add", "supermodel", "message"]);
var answer = supermodel.answer;
answer(/URL endpoint/, "http://chat.donejs.com/api/messages\n");
answer(/property name/, "\n");
return supermodel.promise;
});
/**
* @Step 10
*/
guide.step("Use the connection", function(){
return guide.replaceFile(join("src", "messages", "messages.stache"),
join(__dirname, "steps", "10-use-connection", "messages.stache"))
.then(wait);
});
guide.test(function(){
return guide.functionalTest(join(__dirname, "steps", "10-use-connection", "test.js"));
});
/**
* @Step 11
*/
guide.step("Create messages", function(){
return guide.replaceFile(join("src", "messages", "messages.stache"),
join(__dirname, "steps", "11-create-messages", "messages.stache"))
.then(function(){
return guide.replaceFile(join("src", "messages", "messages.js"),
join(__dirname, "steps", "11-create-messages", "messages.js"));
}).then(wait);
});
guide.test(function(){
return guide.functionalTest(join(__dirname, "steps", "11-create-messages", "test.js"));
});
/**
* @Step 12
*/
guide.step("Enable a real-time connection", function(){
return guide.executeCommand("npm", ["install", "steal-socket.io@2", "--save"])
.then(wait)
.then(function(){
return guide.replaceFile(join("src", "models", "message.js"),
join(__dirname, "steps", "12-real-time", "message.js"));
});
});
guide.test(function(){
return guide.functionalTest(join(__dirname, "steps", "12-real-time", "test.js"));
});
/**
* @Step 13
*/
guide.closeBrowser();
guide.step("Stop development mode", function(){
return guide.kill(guide.canServe)
.then(function(){
guide.canServe = null;
return guide.wait(2000);
});
});
/**
* @ Step 14
*/
guide.step("Production build", function(){
return guide.executeCommand("donejs", ["build"]);
});
/**
* @ Step 15
*/
guide.step("Open in production", function(){
process.env["NODE_ENV"] = "production";
var child = guide.canServe = guide.executeCommand("donejs", ["start"])
.childProcess;
var server = streamWhen(child.stdout, /done-serve starting on/);
return server.then(wait);
});
guide.test(function(){
return guide.nodeTest(join(__dirname, "steps", "15-production", "test.js"));
});
guide.step("Stop production mode", function(){
return guide.kill(guide.canServe)
.then(function(){
guide.canServe = null;
return guide.wait(2000);
});
});
/**
* @Step 16
*/
guide.stepIf("Deploy to CDN", function() {
return !!guide.options.app;
}, function(){
return guide.executeCommand("donejs", ["add", "firebase"])
.then(function(){
return guide.executeCommand("donejs", ["build"]);
})
.then(function(){
return guide.executeCommand("donejs", ["deploy"]);
});
});
/**
* @Step 17
*/
guide.stepIf("Desktop and mobile apps: Cordova", function() {
return process.platform === 'darwin';
}, function(){
return guide.executeCommand("npm", ["install", "-g", "ios-sim"])
.then(function(){
var proc = guide.answerPrompts("donejs", ["add", "cordova"]);
var answer = proc.answer;
answer(/Name of project/, "donejs chat\n");
answer(/ID of project/, "com.donejs.donejschat\n");
answer(/What platforms/, "\n");
return proc.promise;
})
.then(function(){
return guide.executeCommand("donejs", ["build", "cordova"]);
});
});
/**
* @Step 18
*/
guide.stepIf("Desktop and mobile apps: NW.js", function() {
return process.platform !== 'win32';
}, function(){
var proc = guide.answerPrompts("donejs", ["add", "nw"]);
var answer = proc.answer;
answer(/Main HTML file/, "\n");
answer(/The nw.js version/, "0.12.3\n");
answer(/Width of/, "\n");
answer(/Height of/, "\n");
answer(/What platforms/, "\n");
return proc.promise
.then(function(){
return guide.executeCommand("donejs", ["build", "nw"]);
});
});
/**
* Run the test
*/
guide.run().then(
function(){
console.log("All done!");
return 0;
},
function(err){
console.error("Oh no", err.message, err.stack, err);
return 1;
}
).then(function(exitCode){
if(guide.canServe) {
guide.canServe.kill();
}
return exitCode;
}).then(function(exitCode){
process.exit(exitCode);
});