Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 604b27f

Browse files
committed
Merge pull request #3134 from adobe/randy/live-dev-ut
Improve Live Dev test reliability
2 parents c4d907b + 58baddd commit 604b27f

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

src/LiveDevelopment/LiveDevelopment.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,9 @@ define(function LiveDevelopment(require, exports, module) {
776776
// Register user defined server provider
777777
var userServerProvider = new UserServerProvider();
778778
LiveDevServerManager.registerProvider(userServerProvider, 99);
779+
780+
// Initialize exports.status
781+
_setStatus(STATUS_INACTIVE);
779782
}
780783

781784
function _setServerProvider(serverProvider) {

test/spec/LiveDevelopment-test.js

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ define(function (require, exports, module) {
3939
LiveDevelopment,
4040
LiveDevServerManager,
4141
DOMAgent,
42-
Inspector,
4342
DocumentManager,
4443
ProjectManager;
4544

@@ -69,21 +68,22 @@ define(function (require, exports, module) {
6968
var localText,
7069
browserText;
7170

72-
//verify we aren't currently connected
73-
expect(Inspector.connected()).toBeFalsy();
71+
//verify live dev isn't currently active
72+
expect(LiveDevelopment.status).toBe(LiveDevelopment.STATUS_INACTIVE);
7473

7574
runs(function () {
7675
waitsForDone(SpecRunnerUtils.openProjectFiles([htmlFile]), "SpecRunnerUtils.openProjectFiles");
7776
});
7877

79-
//start the connection
78+
//start live dev
8079
runs(function () {
8180
LiveDevelopment.open();
8281
});
83-
waitsFor(function () { return Inspector.connected(); }, "Waiting for browser", 10000);
8482

8583
// Wait for the file and its stylesheets to fully load (and be communicated back).
86-
waits(1000);
84+
waitsFor(function () {
85+
return (LiveDevelopment.status === LiveDevelopment.STATUS_ACTIVE);
86+
}, "Waiting for browser to become active", 10000);
8787

8888
runs(function () {
8989
waitsForDone(SpecRunnerUtils.openProjectFiles([cssFile]), "SpecRunnerUtils.openProjectFiles");
@@ -116,7 +116,7 @@ define(function (require, exports, module) {
116116
expect(fixSpaces(browserText)).toBe(fixSpaces(localText));
117117

118118
var doc = DocumentManager.getOpenDocumentForPath(testPath + "/" + htmlFile);
119-
//expect(isOpenInBrowser(doc, LiveDevelopment.agents)).toBeTruthy();
119+
expect(isOpenInBrowser(doc, LiveDevelopment.agents)).toBeTruthy();
120120
});
121121
}
122122

@@ -133,7 +133,6 @@ define(function (require, exports, module) {
133133
LiveDevelopment = testWindow.brackets.test.LiveDevelopment;
134134
LiveDevServerManager = testWindow.brackets.test.LiveDevServerManager;
135135
DOMAgent = testWindow.brackets.test.DOMAgent;
136-
Inspector = testWindow.brackets.test.Inspector;
137136
DocumentManager = testWindow.brackets.test.DocumentManager;
138137
CommandManager = testWindow.brackets.test.CommandManager;
139138
Commands = testWindow.brackets.test.Commands;
@@ -150,56 +149,60 @@ define(function (require, exports, module) {
150149
LiveDevelopment.close();
151150
});
152151

153-
waitsFor(function () { return !Inspector.connected(); }, "Waiting to close inspector", 10000);
152+
waitsFor(function () {
153+
return (LiveDevelopment.status === LiveDevelopment.STATUS_INACTIVE);
154+
}, "Waiting for browser to become inactive", 10000);
154155

155156
SpecRunnerUtils.closeTestWindow();
156157
});
157158

158159
it("should establish a browser connection for an opened html file", function () {
159-
//verify we aren't currently connected
160-
expect(Inspector.connected()).toBeFalsy();
160+
//verify live dev isn't currently active
161+
expect(LiveDevelopment.status).toBe(LiveDevelopment.STATUS_INACTIVE);
161162

162163
//open a file
163164
runs(function () {
164165
waitsForDone(SpecRunnerUtils.openProjectFiles(["simple1.html"]), "SpecRunnerUtils.openProjectFiles");
165166
});
166167

167-
//start the connection
168+
//start live dev
168169
runs(function () {
169170
LiveDevelopment.open();
170171
});
171-
waitsFor(function () { return Inspector.connected(); }, "Waiting for browser", 10000);
172+
waitsFor(function () {
173+
return (LiveDevelopment.status === LiveDevelopment.STATUS_ACTIVE);
174+
}, "Waiting for browser to become active", 10000);
172175

173176
runs(function () {
174-
expect(Inspector.connected()).toBeTruthy();
177+
expect(LiveDevelopment.status).toBe(LiveDevelopment.STATUS_ACTIVE);
175178

176179
var doc = DocumentManager.getOpenDocumentForPath(testPath + "/simple1.html");
177-
//expect(isOpenInBrowser(doc, LiveDevelopment.agents)).toBeTruthy();
180+
expect(isOpenInBrowser(doc, LiveDevelopment.agents)).toBeTruthy();
178181
});
179182

180-
// Let things settle down before trying to close the connection.
183+
// Let things settle down before trying to stop live dev.
181184
waits(1000);
182185
});
183186

184187
it("should should not start a browser connection for an opened css file", function () {
185-
//verify we aren't currently connected
186-
expect(Inspector.connected()).toBeFalsy();
188+
//verify live dev isn't currently active
189+
expect(LiveDevelopment.status).toBe(LiveDevelopment.STATUS_INACTIVE);
187190

188191
//open a file
189192
runs(function () {
190193
waitsForDone(SpecRunnerUtils.openProjectFiles(["simple1.css"]), "SpecRunnerUtils.openProjectFiles");
191194
});
192195

193-
//start the connection
196+
//start live dev
194197
runs(function () {
195198
LiveDevelopment.open();
196199
});
197200

198-
//we just need to wait an arbitrary time since we can't check for the connection to be true
201+
//need to wait an arbitrary time since we can't check for live dev to be active
199202
waits(1000);
200203

201204
runs(function () {
202-
expect(Inspector.connected()).toBeFalsy();
205+
expect(LiveDevelopment.status).toBe(LiveDevelopment.STATUS_INACTIVE);
203206

204207
var doc = DocumentManager.getOpenDocumentForPath(testPath + "/simple1.css");
205208
expect(isOpenInBrowser(doc, LiveDevelopment.agents)).toBeFalsy();
@@ -218,8 +221,8 @@ define(function (require, exports, module) {
218221
var localText,
219222
browserText;
220223

221-
//verify we aren't currently connected
222-
expect(Inspector.connected()).toBeFalsy();
224+
//verify live dev isn't currently active
225+
expect(LiveDevelopment.status).toBe(LiveDevelopment.STATUS_INACTIVE);
223226

224227
var cssOpened = false;
225228
runs(function () {
@@ -242,7 +245,7 @@ define(function (require, exports, module) {
242245
waitsForDone(SpecRunnerUtils.openProjectFiles(["simple1.css", "simple1.html"]), "SpecRunnerUtils.openProjectFiles");
243246
});
244247

245-
//start the connection
248+
//start live dev
246249
var liveDoc;
247250
runs(function () {
248251
LiveDevelopment.open();
@@ -275,8 +278,8 @@ define(function (require, exports, module) {
275278
browserHtmlText,
276279
htmlDoc;
277280

278-
// verify we aren't currently connected
279-
expect(Inspector.connected()).toBeFalsy();
281+
//verify live dev isn't currently active
282+
expect(LiveDevelopment.status).toBe(LiveDevelopment.STATUS_INACTIVE);
280283

281284
var cssOpened = false;
282285
runs(function () {
@@ -299,15 +302,15 @@ define(function (require, exports, module) {
299302
waitsForDone(SpecRunnerUtils.openProjectFiles(["simple1.html"]), "SpecRunnerUtils.openProjectFiles");
300303
});
301304

302-
// Modify some text in test file before starting live connection
305+
// Modify some text in test file before starting live dev
303306
runs(function () {
304307
htmlDoc = DocumentManager.getCurrentDocument();
305308
origHtmlText = htmlDoc.getText();
306309
updatedHtmlText = origHtmlText.replace("Brackets is", "Live Preview in Brackets is");
307310
htmlDoc.setText(updatedHtmlText);
308311
});
309312

310-
// start the connection
313+
// start live dev
311314
var liveDoc, liveHtmlDoc;
312315
runs(function () {
313316
waitsForDone(LiveDevelopment.open(), "LiveDevelopment.open()", 2000);

0 commit comments

Comments
 (0)