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

Commit

Permalink
Merge pull request #3334 from adobe/jasonsanjose/fix-live-dev-ci
Browse files Browse the repository at this point in the history
Change SpecRunner to run more than one suite, fix issues in tests
  • Loading branch information
dangoor committed Apr 5, 2013
2 parents 59074d3 + 96f1026 commit b65a3aa
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 86 deletions.
25 changes: 18 additions & 7 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,21 @@ define(function LiveDevelopment(require, exports, module) {
"edit" : require("LiveDevelopment/Agents/EditAgent")
};

var launcherUrl = window.location.href.replace(/\/index.html.*/, "") + "/LiveDevelopment/launch.html";
// construct path to launch.html
// window location is can be one of the following:
// Installed: /path/to/Brackets.app/Contents/www/index.html
// Installed, dev: /path/to/Brackets.app/Contents/dev/src/index.html
// Installed, dev, test: /path/to/Brackets.app/Contents/dev/test/SpecRunner.html
// Arbitrary git repo: /path/to/brackets/src/index.html
// Arbitrary git repo, test: /path/to/brackets/test/SpecRunner.html
var launcherUrl = window.location.pathname;

// special case for test/SpecRunner.html since we can't tell how requirejs
// baseUrl is configured dynamically
launcherUrl = launcherUrl.replace("/test/SpecRunner.html", "/src/index.html");

launcherUrl = launcherUrl.substr(0, launcherUrl.lastIndexOf("/")) + "/LiveDevelopment/launch.html";
launcherUrl = window.location.origin + launcherUrl;

// Some agents are still experimental, so we don't enable them all by default
// However, extensions can enable them by calling enableAgent().
Expand Down Expand Up @@ -556,9 +570,6 @@ define(function LiveDevelopment(require, exports, module) {
// helper function that actually does the launch once we are sure we have
// a doc and the server for that doc is up and running.
function doLaunchAfterServerReady() {
var targetUrl = doc.root.url;
var interstitialUrl = launcherUrl + "?" + encodeURIComponent(targetUrl);

_setStatus(STATUS_CONNECTING);

if (_serverProvider) {
Expand All @@ -579,7 +590,7 @@ define(function LiveDevelopment(require, exports, module) {
});
}

Inspector.connectToURL(interstitialUrl).done(result.resolve).fail(function onConnectFail(err) {
Inspector.connectToURL(launcherUrl).done(result.resolve).fail(function onConnectFail(err) {
if (err === "CANCEL") {
result.reject(err);
return;
Expand Down Expand Up @@ -617,7 +628,7 @@ define(function LiveDevelopment(require, exports, module) {

if (!browserStarted && exports.status !== STATUS_ERROR) {
NativeApp.openLiveBrowser(
interstitialUrl,
launcherUrl,
true // enable remote debugging
)
.done(function () {
Expand Down Expand Up @@ -650,7 +661,7 @@ define(function LiveDevelopment(require, exports, module) {

if (exports.status !== STATUS_ERROR) {
window.setTimeout(function retryConnect() {
Inspector.connectToURL(interstitialUrl).done(result.resolve).fail(onConnectFail);
Inspector.connectToURL(launcherUrl).done(result.resolve).fail(onConnectFail);
}, 500);
}
});
Expand Down
50 changes: 27 additions & 23 deletions src/extensions/default/JavaScriptCodeHints/ScopeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,33 +425,37 @@ define(function (require, exports, module) {
var path = document.file.fullPath,
split = HintUtils.splitPath(path),
dir = split.dir,
file = split.file,
dirEntry = new NativeFileSystem.DirectoryEntry(dir),
reader = dirEntry.createReader();

markFileDirty(dir, file);

reader.readEntries(function (entries) {
entries.slice(0, MAX_FILES_IN_DIR).forEach(function (entry) {
if (entry.isFile) {
var path = entry.fullPath,
split = HintUtils.splitPath(path),
dir = split.dir,
file = split.file;

if (file.indexOf(".") > 1) { // ignore /.dotfiles
var languageID = LanguageManager.getLanguageForPath(entry.fullPath).getId();
if (languageID === HintUtils.LANGUAGE_ID) {
DocumentManager.getDocumentForPath(path).done(function (document) {
refreshOuterScope(dir, file, document.getText());
});
file = split.file;

NativeFileSystem.resolveNativeFileSystemPath(dir, function (dirEntry) {
var reader = dirEntry.createReader();

markFileDirty(dir, file);

reader.readEntries(function (entries) {
entries.slice(0, MAX_FILES_IN_DIR).forEach(function (entry) {
if (entry.isFile) {
var path = entry.fullPath,
split = HintUtils.splitPath(path),
dir = split.dir,
file = split.file;

if (file.indexOf(".") > 1) { // ignore /.dotfiles
var languageID = LanguageManager.getLanguageForPath(entry.fullPath).getId();
if (languageID === HintUtils.LANGUAGE_ID) {
DocumentManager.getDocumentForPath(path).done(function (document) {
refreshOuterScope(dir, file, document.getText());
});
}
}
}
}
});
}, function (err) {
console.log("Unable to refresh directory: " + err);
refreshOuterScope(dir, file, document.getText());
});
}, function (err) {
console.log("Unable to refresh directory: " + err);
refreshOuterScope(dir, file, document.getText());
console.log("Directory \"%s\" does not exist", dir);
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/file/NativeFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,11 @@ define(function (require, exports, module) {
* @param {function(DOMError)=} errorCallback Callback function for error operations
*/
NativeFileSystem.DirectoryReader.prototype.readEntries = function (successCallback, errorCallback) {
if (!this._directory.fullPath) {
errorCallback(new NativeFileError(NativeFileError.PATH_EXISTS_ERR));
return;
}

var rootPath = this._directory.fullPath,
filesystem = this.filesystem,
timeout = NativeFileSystem.ASYNC_TIMEOUT,
Expand Down
3 changes: 2 additions & 1 deletion tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ module.exports = function (grunt) {
opts = { cwd: process.cwd() },
cmd = common.resolve(grunt.option("shell") || grunt.config("shell." + platform)),
spec = grunt.option("spec") || "all",
suite = grunt.option("suite") || "all",
results = grunt.option("results") || process.cwd() + "/results.json",
resultsPath = common.resolve(results),
specRunnerPath = common.resolve("test/SpecRunner.html"),
args = " --startup-path=\"" + specRunnerPath + "?suite=all&spec=" + encodeURIComponent(spec) + "&resultsPath=" + encodeURIComponent(resultsPath) + "\"";
args = " --startup-path=\"" + specRunnerPath + "?suite=" + encodeURIComponent(suite) + "&spec=" + encodeURIComponent(spec) + "&resultsPath=" + encodeURIComponent(resultsPath) + "\"";

if (platform === "win") {
cmd += args;
Expand Down
8 changes: 4 additions & 4 deletions test/SpecRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
<div class="nav-collapse">
<ul class="nav">
<li><a id="all" href="?suite=all">All</a></li>
<li><a id="UnitTestSuite" href="?suite=UnitTestSuite">Unit</a></li>
<li><a id="IntegrationTestSuite" href="?suite=IntegrationTestSuite">Integration</a></li>
<li><a id="PerformanceTestSuite" href="?suite=PerformanceTestSuite">Performance</a></li>
<li><a id="ExtensionTestSuite" href="?suite=ExtensionTestSuite">Extensions</a></li>
<li><a id="unit" href="?suite=unit">Unit</a></li>
<li><a id="integration" href="?suite=integration">Integration</a></li>
<li><a id="performance" href="?suite=performance">Performance</a></li>
<li><a id="extension" href="?suite=extension">Extensions</a></li>
<li><a id="reload" href="#">Reload</a></li>
<li><a id="show-dev-tools" href="#">Show Developer Tools</a></li>
</ul>
Expand Down
73 changes: 24 additions & 49 deletions test/SpecRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ define(function (require, exports, module) {
require("test/UnitTestSuite");
require("test/PerformanceTestSuite");

var selectedSuite,
var selectedSuites,
params = new UrlParams(),
reporter,
_nodeConnectionDeferred = new $.Deferred(),
Expand All @@ -81,7 +81,7 @@ define(function (require, exports, module) {

params.parse();

function _loadExtensionTests(suite) {
function _loadExtensionTests() {
// augment jasmine to identify extension unit tests
var addSuite = jasmine.Runner.prototype.addSuite;
jasmine.Runner.prototype.addSuite = function (suite) {
Expand All @@ -93,7 +93,7 @@ define(function (require, exports, module) {
paths = ["default"];

// load dev and user extensions only when running the extension test suite
if (suite === "ExtensionTestSuite") {
if (selectedSuites.indexOf("extension")) {
paths.push("dev");
paths.push(ExtensionLoader.getUserExtensionPath());
}
Expand Down Expand Up @@ -127,7 +127,9 @@ define(function (require, exports, module) {
window.location.reload(true);
});

$("#" + selectedSuite).closest("li").toggleClass("active", true);
if (selectedSuites.length === 1) {
$("#" + (selectedSuites[0])).closest("li").toggleClass("active", true);
}

AppInit._dispatchReady(AppInit.APP_READY);

Expand Down Expand Up @@ -200,63 +202,36 @@ define(function (require, exports, module) {
);
});

selectedSuite = params.get("suite") || localStorage.getItem("SpecRunner.suite") || "UnitTestSuite";
selectedSuites = (params.get("suite") || localStorage.getItem("SpecRunner.suite") || "unit").split(",");

// Create a top-level filter to show/hide performance and extensions tests
var runAll = (selectedSuite === "all"),
isPerfSuite = (selectedSuite === "PerformanceTestSuite"),
isExtSuite = (selectedSuite === "ExtensionTestSuite"),
isIntegrationSuite = (selectedSuite === "IntegrationTestSuite"),
category;

if (isPerfSuite) {
category = "performance";
} else if (isIntegrationSuite) {
category = "integration";
} else if (isExtSuite) {
category = "extension";
}
var runAll = (selectedSuites.indexOf("all") >= 0);

var topLevelFilter = function (spec) {
// special case "all" suite to run unit, perf, extension, and integration tests
if (runAll) {
return true;
}

var currentSuite = spec.suite;

// unit test suites have no category
if (!isPerfSuite && !isExtSuite && !isIntegrationSuite) {
if (spec.category !== undefined) {
// if an individualy spec has a category, filter it out
return false;
}

var currentSuite = spec.suite,
category = spec.category;

if (!category) {
// find the category from the closest suite
while (currentSuite) {
if (currentSuite.category !== undefined) {
// any suite in the hierarchy may specify a category
return false;
if (currentSuite.category) {
category = currentSuite.category;
break;
}

currentSuite = currentSuite.parentSuite;
}

return true;
}

if (spec.category === category) {
return true;
}

while (currentSuite) {
if (currentSuite.category === category) {
return true;
}

currentSuite = currentSuite.parentSuite;
}

return false;
// if unit tests are selected, make sure there is no category in the heirarchy
// if not a unit test, make sure the category is selected
return (selectedSuites.indexOf("unit") >= 0 && category === undefined) ||
(selectedSuites.indexOf(category) >= 0);
};

/*
Expand All @@ -266,9 +241,9 @@ define(function (require, exports, module) {
*/

// configure spawned test windows to load extensions
SpecRunnerUtils.setLoadExtensionsInTestWindow(isExtSuite);
SpecRunnerUtils.setLoadExtensionsInTestWindow(selectedSuites.indexOf("extension") >= 0);

_loadExtensionTests(selectedSuite).done(function () {
_loadExtensionTests(selectedSuites).done(function () {
var jasmineEnv = jasmine.getEnv();

// Initiailize unit test preferences for each spec
Expand Down Expand Up @@ -302,7 +277,7 @@ define(function (require, exports, module) {
reporterView = new BootstrapReporterView(document, reporter);

// remember the suite for the next unit test window launch
localStorage.setItem("SpecRunner.suite", selectedSuite);
localStorage.setItem("SpecRunner.suite", selectedSuites);

$(window.document).ready(_documentReadyHandler);
});
Expand Down
2 changes: 1 addition & 1 deletion test/spec/LiveDevelopment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ define(function (require, exports, module) {
});

runs(function () {
waitsForDone(Inspector.connectToURL(url), "Inspector.connectToURL", 5000);
waitsForDone(Inspector.connectToURL(url), "Inspector.connectToURL", 10000);
});

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

// Prevent adding doc to working set
docToShim._handleEditorChange = function (event, editor, changeList) {
this.isDirty = true;
this.isDirty = !editor._codeMirror.isClean();

// TODO: This needs to be kept in sync with Document._handleEditorChange(). In the
// future, we should fix things so that we either don't need mock documents or that this
Expand Down

0 comments on commit b65a3aa

Please sign in to comment.