Skip to content

Commit

Permalink
Merge pull request adobe#1341 from adobe/jason-sanjose/livedev-tests
Browse files Browse the repository at this point in the history
fix async bugs in livedevelopment unit tests. fixes failures in brackets-shell
  • Loading branch information
redmunds committed Aug 3, 2012
2 parents f15ce77 + df2e259 commit 1bcd16c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/utils/NativeApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ define(function (require, exports, module) {
function closeAllLiveBrowsers() {
//make a copy incase the array is edited as we iterate
var closeIDs = liveBrowserOpenedPIDs.concat();
return Async.doInParallel(closeIDs, closeLiveBrowser, false);
return Async.doSequentially(closeIDs, closeLiveBrowser, false);
}

/** _setLiveBrowserUserDataDir
Expand Down
2 changes: 1 addition & 1 deletion test/spec/CodeHint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function (require, exports, module) {

// Load dependent modules
var HTMLUtils = require("language/HTMLUtils"),
SpecRunnerUtils = require("./SpecRunnerUtils.js"),
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
Editor = require("editor/Editor").Editor,
EditorManager, // loaded from brackets.test
CodeHintManager;
Expand Down
83 changes: 29 additions & 54 deletions test/spec/LiveDevelopment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define: false, describe: false, it: false, xit: false, expect: false, beforeEach: false, afterEach: false, waitsFor: false, waits: false, runs: false, $: false*/
/*global define, describe, it, xit, expect, beforeEach, afterEach, waitsFor, waitsForDone, waits, runs, $*/

define(function (require, exports, module) {
'use strict';
Expand All @@ -45,7 +45,6 @@ define(function (require, exports, module) {
function isOpenInBrowser(doc, agents) {
return (doc && doc.url && agents && agents.network && agents.network.wasURLRequested(doc.url));
}


describe("Live Development", function () {

Expand All @@ -66,23 +65,27 @@ define(function (require, exports, module) {


afterEach(function () {
var browserDone = false;
runs(function () {
LiveDevelopment.close();
});
waitsFor(function () { return !Inspector.connected(); }, "Waiting for to close inspector", 10000);
waits(20);
NativeApp._setLiveBrowserUserDataDir("");

runs(function () {
NativeApp.closeAllLiveBrowsers().always(function () {
browserDone = true;
if (window.appshell) {
runs(function () {
waitsForDone(NativeApp.closeAllLiveBrowsers(), "NativeApp.closeAllLiveBrowsers", 10000);
});
SpecRunnerUtils.closeTestWindow();
} else {
// Remove this 'else' after migrating to brackets-shell.
// brackets-app never resolves the promise for brackets.app.closeLiveBrowser.
runs(function () {
NativeApp.closeAllLiveBrowsers();
});
waits(100);
}

});
waits(100);
//waitsFor(function () { return browserDone; }, "closeLiveBrowser timeout", 10000);
SpecRunnerUtils.closeTestWindow();
});

describe("CSS Editing", function () {
Expand All @@ -92,15 +95,9 @@ define(function (require, exports, module) {
expect(Inspector.connected()).toBeFalsy();

//open a file
var htmlOpened = false;
runs(function () {
SpecRunnerUtils.openProjectFiles(["simple1.html"]).fail(function () {
expect("Failed To Open").toBe("simple1.html");
}).always(function () {
htmlOpened = true;
});
waitsForDone(SpecRunnerUtils.openProjectFiles(["simple1.html"]), "SpecRunnerUtils.openProjectFiles");
});
waitsFor(function () { return htmlOpened; }, "htmlOpened FILE_OPEN timeout", 1000);

//start the connection
runs(function () {
Expand All @@ -124,15 +121,9 @@ define(function (require, exports, module) {
expect(Inspector.connected()).toBeFalsy();

//open a file
var opened = false;
runs(function () {
SpecRunnerUtils.openProjectFiles(["simple1.css"]).fail(function () {
expect("Failed To Open").toBe("simple1.css");
}).always(function () {
opened = true;
});
waitsForDone(SpecRunnerUtils.openProjectFiles(["simple1.css"]), "SpecRunnerUtils.openProjectFiles");
});
waitsFor(function () { return opened; }, "FILE_OPEN timeout", 1000);

//start the connection
runs(function () {
Expand All @@ -157,15 +148,9 @@ define(function (require, exports, module) {
//verify we aren't currently connected
expect(Inspector.connected()).toBeFalsy();

var htmlOpened = false;
runs(function () {
SpecRunnerUtils.openProjectFiles(["simple1.html"]).fail(function () {
expect("Failed To Open").toBe("simple1.html");
}).always(function () {
htmlOpened = true;
});
waitsForDone(SpecRunnerUtils.openProjectFiles(["simple1.html"]), "SpecRunnerUtils.openProjectFiles");
});
waitsFor(function () { return htmlOpened; }, "htmlOpened FILE_OPEN timeout", 1000);

//start the connection
runs(function () {
Expand All @@ -176,29 +161,25 @@ define(function (require, exports, module) {
// Wait for the file and its stylesheets to fully load (and be communicated back).
waits(1000);

var cssOpened = false;
runs(function () {
SpecRunnerUtils.openProjectFiles(["simple1.css"]).fail(function () {
expect("Failed To Open").toBe("simple1.css");
}).always(function () {
cssOpened = true;
});
waitsForDone(SpecRunnerUtils.openProjectFiles(["simple1.css"]), "SpecRunnerUtils.openProjectFiles");
});
waitsFor(function () { return cssOpened; }, "cssOpened FILE_OPEN timeout", 1000);

runs(function () {
var curDoc = DocumentManager.getCurrentDocument();
localText = curDoc.getText();
localText += "\n .testClass { color:#090; }\n";
curDoc.setText(localText);
});

//add a wait for the change to get pushed, then wait to get the result
waits(1000);

var liveDoc;
waitsFor(function () {
liveDoc = LiveDevelopment.getLiveDocForPath(testPath + "/simple1.css");
return !!liveDoc;
}, "Waiting for LiveDevelopment document", 10000);

var doneSyncing = false;
runs(function () {
var liveDoc = LiveDevelopment.getLiveDocForPath(testPath + "/simple1.css");
liveDoc.getSourceFromBrowser().done(function (text) {
browserText = text;
}).always(function () {
Expand Down Expand Up @@ -239,28 +220,22 @@ define(function (require, exports, module) {
curDoc.setText(localText);
});

var htmlOpened = false;
runs(function () {
SpecRunnerUtils.openProjectFiles(["simple1.css", "simple1.html"]).fail(function () {
expect("Failed To Open").toBe("simple1.html");
}).always(function () {
htmlOpened = true;
});
waitsForDone(SpecRunnerUtils.openProjectFiles(["simple1.css", "simple1.html"]), "SpecRunnerUtils.openProjectFiles");
});
waitsFor(function () { return htmlOpened; }, "htmlOpened FILE_OPEN timeout", 1000);

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

//wait again for the final changes to load
waits(350);
waitsFor(function () {
liveDoc = LiveDevelopment.getLiveDocForPath(testPath + "/simple1.css");
return !!liveDoc;
}, "Waiting for LiveDevelopment document", 10000);

var doneSyncing = false;
runs(function () {
var liveDoc = LiveDevelopment.getLiveDocForPath(testPath + "/simple1.css");
liveDoc.getSourceFromBrowser().done(function (text) {
browserText = text;
}).always(function () {
Expand Down
7 changes: 4 additions & 3 deletions test/spec/SpecRunnerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ define(function (require, exports, module) {
* @param {$.Promise} promise
* @param {string} operationName Name used for timeout error message
*/
window.waitsForDone = function (promise, operationName) {
window.waitsForDone = function (promise, operationName, timeout) {
timeout = timeout || 1000;
expect(promise).toBeTruthy();
waitsFor(function () {
return promise.state() === "resolved";
}, "Timeout waiting for success " + operationName, 1000);
}, "success " + operationName, timeout);
};

/**
Expand All @@ -86,7 +87,7 @@ define(function (require, exports, module) {
expect(promise).toBeTruthy();
waitsFor(function () {
return promise.state() === "rejected";
}, "Timeout waiting for failure " + operationName, 1000);
}, "failure " + operationName, 1000);
};


Expand Down

0 comments on commit 1bcd16c

Please sign in to comment.