forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhot-code-push.js
More file actions
260 lines (212 loc) · 8.14 KB
/
hot-code-push.js
File metadata and controls
260 lines (212 loc) · 8.14 KB
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
var selftest = require('../tool-testing/selftest.js');
var Sandbox = selftest.Sandbox;
var utils = require('../utils/utils.js');
selftest.define("css hot code push", function (options) {
var s = new Sandbox({
clients: options.clients
});
s.createApp("myapp", "css-injection-test");
s.cd("myapp");
s.testWithAllClients(function (run) {
run.match("myapp");
run.match("proxy");
run.match("MongoDB");
run.match("running at");
run.match("localhost");
run.connectClient();
run.waitSecs(20);
run.match("client connected");
// 'numCssChanges' variable is set to 0 on a client refresh.
// Since CSS changes should not trigger a client refresh, numCssChanges
// should never reset.
// The css file is initially empty.
run.match("numCssChanges: 0");
// Some browsers represent no background as 'transparent', others use
// rgba(0, 0, 0, 0).
run.match(/background-color: (transparent|rgba\(0, 0, 0, 0\))/);
// The server does NOT restart if a new css file is added.
s.write("test.css", "body { background-color: red; }");
run.waitSecs(30);
run.match("Client modified -- refreshing");
run.match("numCssChanges: 1");
run.match(/background-color: (red|rgb\(255, 0, 0\))/);
s.write("test.css", "body { background-color: blue; }");
run.match("Client modified -- refreshing");
run.match("numCssChanges: 2");
run.match(/background-color: (blue|rgb\(0, 0, 255\))/);
// The server does NOT restart if a css file is removed.
s.unlink("test.css");
run.match("Client modified -- refreshing");
run.match("numCssChanges: 3");
run.match(/background-color: (transparent|rgba\(0, 0, 0, 0\))/);
s.write(".meteor/packages", `meteor-base
jquery
my-package`);
run.match(/my-package.*added,/);
run.match("client connected");
run.match("numCssChanges: 0");
s.write("packages/my-package/foo.css", "body { background-color: blue; }");
run.match("numCssChanges: 1");
run.match(/background-color: (blue|rgb\(0, 0, 255\))/);
// Add appcache and ensure that the browser still reloads.
s.write(".meteor/packages", `meteor-base
jquery
my-package
appcache`);
run.match(/appcache.*added,/);
run.match("server restarted");
run.match("numCssChanges: 0");
run.match(/background-color: (blue|rgb\(0, 0, 255\))/);
s.write("packages/my-package/foo.css", "body { background-color: red; }");
run.match("Client modified -- refreshing");
run.match("numCssChanges: 1");
run.match(/background-color: (red|rgb\(255, 0, 0\))/);
// XXX: Remove me. This shouldn't be needed, but sometimes
// if we run too quickly on fast (or Linux?) machines, it looks
// like there's a race and we see a weird state
utils.sleepMs(10000);
s.write(".meteor/packages", `meteor-base
jquery`);
run.match(/my-package.*removed from your project/);
run.match("numCssChanges: 0");
run.match(/background-color: (transparent|rgba\(0, 0, 0, 0\))/);
run.stop();
});
});
selftest.define("versioning hot code push", function (options) {
var s = new Sandbox();
s.set("AUTOUPDATE_VERSION", "1.0");
s.createApp("myapp", "hot-code-push-test");
s.cd("myapp");
s.testWithAllClients(function (run) {
run.baseTimeout = 20;
run.match("myapp");
run.match("proxy");
run.match("MongoDB");
run.match("running at");
run.match("localhost");
run.connectClient();
run.waitSecs(20);
run.match("client connected: 0");
run.forbidAll("Error listening");
run.stop();
});
});
selftest.define("javascript hot code push", function (options) {
var s = new Sandbox({
clients: options.clients
});
s.createApp("myapp", "hot-code-push-test");
s.cd("myapp");
s.testWithAllClients(function (run) {
run.match("myapp");
run.match("proxy");
run.match("MongoDB");
run.match("running at");
run.match("localhost");
run.connectClient();
run.waitSecs(40);
// There is initially no JavaScript file.
run.match("client connected: 0");
run.match("jsVar: undefined");
run.match("sessionVar: null");
// The server and client both restart if a shared js file is added
// or removed.
s.write("test.js", "jsVar = 'foo'");
run.match("server restarted");
run.match("client connected: 0");
run.match("jsVar: foo");
run.match("sessionVar: true");
s.unlink("test.js");
run.match("server restarted");
run.match("client connected: 0");
run.match("jsVar: undefined");
// Only the client should refresh if a client js file is added. Thus,
// "client connected" variable will be incremented.
s.mkdir("client");
s.write("client/test.js", "jsVar = 'bar'");
run.match("client connected: 1");
run.match("jsVar: bar");
s.unlink("client/test.js");
run.match("client connected: 2");
run.match("jsVar: undefined");
// When we change a server file the client should not refresh. We observe
// this by changing a server file and then a client file and verifying
// that the client has only connected once.
s.mkdir("server");
s.write("server/test.js", "jsVar = 'bar'");
run.match("server restarted");
s.write("client/empty.js", "");
run.match("client connected: 0");
// We should not be able to access a server variable from the client.
run.match("jsVar: undefined");
s.unlink("client/empty.js");
run.waitSecs(5);
run.match("client connected: 1");
run.match("jsVar: undefined");
// Break the HTML file. This should kill the server, and print errors.
// (It would be reasonable behavior for this to NOT kill the server, since
// it only affects the client. But this is a regression test for a bug where
// fixing the HTML file wouldn't actually restart the server; that's the
// important part of this test.)
s.write("hot-code-push-test.html", ">");
run.match("Errors prevented startup");
run.match("Expected one of: <body>, <head>, <template>");
// Fix it. It should notice, and restart. The client will restart too.
s.write("hot-code-push-test.html", "");
run.match("server restarted");
run.match("client connected: 0");
// Write something else to it. The client should restart.
s.write("hot-code-push-test.html", "<head><title>foo</title></head>");
run.match("Client modified -- refreshing");
run.match("client connected: 1");
run.match("jsVar: undefined");
s.write(".meteor/packages", `meteor-base
session
my-package`);
run.match(/my-package.*added,/);
run.match("server restarted");
run.match("client connected: 0");
run.match("jsVar: undefined");
run.match("packageVar: foo");
s.write("packages/my-package/foo.js", "packageVar = 'bar'");
run.match("client connected: 1");
run.match("jsVar: undefined");
run.match("packageVar: bar");
// Add appcache and ensure that the browser still reloads.
s.write(".meteor/packages", `meteor-base
session
appcache`);
run.match(/appcache.*added,/);
run.match("server restarted");
run.match("client connected: 0");
run.match("jsVar: undefined");
// XXX: Remove me. This shouldn't be needed, but sometimes
// if we run too quickly on fast (or Linux?) machines, it looks
// like there's a race and we see a weird state
utils.sleepMs(10000);
s.write("client/test.js", "jsVar = 'bar'");
run.match("client connected: 1");
run.match("jsVar: bar");
// Remove appcache and ensure that the browser still reloads.
s.write(".meteor/packages", `meteor-base
session`);
run.match(/appcache.*removed from your project/);
run.match("server restarted");
run.match("client connected: 0");
s.write("client/test.js", "jsVar = 'baz'");
run.match("client connected: 1");
run.match("jsVar: baz");
s.unlink("client/test.js");
// Setting the autoupdateVersion to a different string should also
// force the client to restart.
s.write("server/test.js",
"Package.autoupdate.Autoupdate.autoupdateVersion = 'random'");
run.match("server restarted");
run.match("client connected: 0");
run.match("jsVar: undefined");
s.unlink("server/test.js");
run.match("server restarted");
run.stop();
});
});