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

Improve Live Dev test reliability #3134

Merged
merged 6 commits into from
Mar 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,9 @@ define(function LiveDevelopment(require, exports, module) {
// Register user defined server provider
var userServerProvider = new UserServerProvider();
LiveDevServerManager.registerProvider(userServerProvider, 99);

// Initialize exports.status
_setStatus(STATUS_INACTIVE);
}

function _setServerProvider(serverProvider) {
Expand Down
59 changes: 31 additions & 28 deletions test/spec/LiveDevelopment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ define(function (require, exports, module) {
LiveDevelopment,
LiveDevServerManager,
DOMAgent,
Inspector,
DocumentManager,
ProjectManager;

Expand Down Expand Up @@ -69,21 +68,22 @@ define(function (require, exports, module) {
var localText,
browserText;

//verify we aren't currently connected
expect(Inspector.connected()).toBeFalsy();
//verify live dev isn't currently active
expect(LiveDevelopment.status).toBe(LiveDevelopment.STATUS_INACTIVE);

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

//start the connection
//start live dev
runs(function () {
LiveDevelopment.open();
});
waitsFor(function () { return Inspector.connected(); }, "Waiting for browser", 10000);

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

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

var doc = DocumentManager.getOpenDocumentForPath(testPath + "/" + htmlFile);
//expect(isOpenInBrowser(doc, LiveDevelopment.agents)).toBeTruthy();
expect(isOpenInBrowser(doc, LiveDevelopment.agents)).toBeTruthy();
});
}

Expand All @@ -133,7 +133,6 @@ define(function (require, exports, module) {
LiveDevelopment = testWindow.brackets.test.LiveDevelopment;
LiveDevServerManager = testWindow.brackets.test.LiveDevServerManager;
DOMAgent = testWindow.brackets.test.DOMAgent;
Inspector = testWindow.brackets.test.Inspector;
DocumentManager = testWindow.brackets.test.DocumentManager;
CommandManager = testWindow.brackets.test.CommandManager;
Commands = testWindow.brackets.test.Commands;
Expand All @@ -150,56 +149,60 @@ define(function (require, exports, module) {
LiveDevelopment.close();
});

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

SpecRunnerUtils.closeTestWindow();
});

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

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

//start the connection
//start live dev
runs(function () {
LiveDevelopment.open();
});
waitsFor(function () { return Inspector.connected(); }, "Waiting for browser", 10000);
waitsFor(function () {
return (LiveDevelopment.status === LiveDevelopment.STATUS_ACTIVE);
}, "Waiting for browser to become active", 10000);

runs(function () {
expect(Inspector.connected()).toBeTruthy();
expect(LiveDevelopment.status).toBe(LiveDevelopment.STATUS_ACTIVE);

var doc = DocumentManager.getOpenDocumentForPath(testPath + "/simple1.html");
//expect(isOpenInBrowser(doc, LiveDevelopment.agents)).toBeTruthy();
expect(isOpenInBrowser(doc, LiveDevelopment.agents)).toBeTruthy();
});

// Let things settle down before trying to close the connection.
// Let things settle down before trying to stop live dev.
waits(1000);
});

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

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

//start the connection
//start live dev
runs(function () {
LiveDevelopment.open();
});

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

runs(function () {
expect(Inspector.connected()).toBeFalsy();
expect(LiveDevelopment.status).toBe(LiveDevelopment.STATUS_INACTIVE);

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

//verify we aren't currently connected
expect(Inspector.connected()).toBeFalsy();
//verify live dev isn't currently active
expect(LiveDevelopment.status).toBe(LiveDevelopment.STATUS_INACTIVE);

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

//start the connection
//start live dev
var liveDoc;
runs(function () {
LiveDevelopment.open();
Expand Down Expand Up @@ -275,8 +278,8 @@ define(function (require, exports, module) {
browserHtmlText,
htmlDoc;

// verify we aren't currently connected
expect(Inspector.connected()).toBeFalsy();
//verify live dev isn't currently active
expect(LiveDevelopment.status).toBe(LiveDevelopment.STATUS_INACTIVE);

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

// Modify some text in test file before starting live connection
// Modify some text in test file before starting live dev
runs(function () {
htmlDoc = DocumentManager.getCurrentDocument();
origHtmlText = htmlDoc.getText();
updatedHtmlText = origHtmlText.replace("Brackets is", "Live Preview in Brackets is");
htmlDoc.setText(updatedHtmlText);
});

// start the connection
// start live dev
var liveDoc, liveHtmlDoc;
runs(function () {
waitsForDone(LiveDevelopment.open(), "LiveDevelopment.open()", 2000);
Expand Down