Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Prevent extensions from loading in test windows. Separate extension u…

…nit tests as a suite. Fix broken perf tests.
  • Loading branch information...
commit 8e3039ce734e2ed8137373c56894926b317b7038 1 parent bb5de62
@jasonsanjose jasonsanjose authored
View
17 src/brackets.js
@@ -81,9 +81,16 @@ define(function (require, exports, module) {
Async = require("utils/Async");
// Local variables
- var bracketsReady = false,
- bracketsReadyHandlers = [];
-
+ var bracketsReady = false,
+ bracketsReadyHandlers = [],
+ paramMap = [],
+ params = window.document.location.search.substring(1).split('&');
+
+ params.forEach(function (param) {
+ var p = param.split('=');
+ paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
+ });
+
//Load modules that self-register and just need to get included in the main project
require("document/ChangedDocumentTracker");
require("editor/EditorCommandHandlers");
@@ -175,7 +182,9 @@ define(function (require, exports, module) {
// TODO: (issue 1029) Add timeout to main extension loading promise, so that we always call this function
// Making this fix will fix a warning (search for issue 1029) related to the brackets 'ready' event.
function _initExtensions() {
- return Async.doInParallel(["default", "user"], function (item) {
+ var paths = paramMap.extensions || "default,user";
+
+ return Async.doInParallel(paths.split(","), function (item) {
return ExtensionLoader.loadAllExtensionsInNativeDirectory(
FileUtils.getNativeBracketsDirectoryPath() + "/extensions/" + item,
"extensions/" + item
View
2  src/extensions/default/JavaScriptQuickEdit/unittests.js
@@ -279,7 +279,7 @@ define(function (require, exports, module) {
describe("Performance suite", function () {
- this.performance = true;
+ this.category = "performance";
var testPath = SpecRunnerUtils.getTestPath("/../../../brackets-scenario/jquery-ui/");
View
15 src/utils/PerfUtils.js
@@ -316,6 +316,20 @@ define(function (require, exports, module) {
return perfData[toMeasurementId(name)];
}
+ function searchData(regExp) {
+ var keys = Object.keys(perfData).filter(function (key) {
+ return regExp.test(key);
+ });
+
+ var datas = [];
+
+ keys.forEach(function (key) {
+ datas.push(perfData[key]);
+ });
+
+ return datas;
+ }
+
/**
* Clear all logs including metric data and active tests.
*/
@@ -336,6 +350,7 @@ define(function (require, exports, module) {
exports.isActive = isActive;
exports.markStart = markStart;
exports.getData = getData;
+ exports.searchData = searchData;
exports.updateMeasurement = updateMeasurement;
exports.getDelimitedPerfData = getDelimitedPerfData;
exports.createPerfMeasurement = createPerfMeasurement;
View
2  test/PerformanceTestSuite.js
@@ -26,6 +26,6 @@
define(function (require, exports, module) {
'use strict';
- // Each suite or spec must have this.performance = true to be filtered properly
+ // Each suite or spec must have this.category === "performance" to be filtered properly
require("perf/Performance-test");
});
View
3  test/SpecRunner.html
@@ -32,8 +32,6 @@
<link href="BootstrapReporter.css" rel="stylesheet">
<script src="thirdparty/jasmine-core/jasmine.js"></script>
- <script src="thirdparty/jasmine-core/jasmine-html.js"></script>
- <script src="thirdparty/jasmine-jquery-1.3.1.js"></script>
<!-- Pre-load third party scripts that cannot be async loaded. -->
<script src="../src/thirdparty/jquery-1.7.min.js"></script>
@@ -61,6 +59,7 @@
<ul class="nav">
<li><a id="UnitTestSuite" href="?suite=UnitTestSuite">Unit</a></li>
<li><a id="PerformanceTestSuite" href="?suite=PerformanceTestSuite">Performance</a></li>
+ <li><a id="ExtensionSuite" href="?suite=ExtensionTestSuite">Extensions</a></li>
<li><a id="reload" href="#">Reload</a></li>
<li><a id="show-dev-tools" href="#">Show Developer Tools</a></li>
</ul>
View
85 test/SpecRunner.js
@@ -70,13 +70,26 @@ define(function (require, exports, module) {
return paramMap;
}
- function _loadExtensionTests() {
- var bracketsPath = FileUtils.getNativeBracketsDirectoryPath();
+ function _loadExtensionTests(suite) {
+ // augment jasmine to identify extension unit tests
+ var addSuite = jasmine.Runner.prototype.addSuite;
+ jasmine.Runner.prototype.addSuite = function (suite) {
+ suite.category = "extension";
+ addSuite.call(this, suite);
+ };
+
+ var bracketsPath = FileUtils.getNativeBracketsDirectoryPath(),
+ paths = ["default"];
+
+ // load user extensions only when running the extension test suite
+ if (suite === "ExtensionTestSuite") {
+ paths.push("user");
+ }
// This returns path to test folder, so convert to src
bracketsPath = bracketsPath.replace("brackets/test", "brackets/src");
- return Async.doInParallel(["default", "user"], function (dir) {
+ return Async.doInParallel(paths, function (dir) {
return ExtensionLoader.testAllExtensionsInNativeDirectory(
bracketsPath + "/extensions/" + dir,
"extensions/" + dir
@@ -123,8 +136,47 @@ define(function (require, exports, module) {
// Note: we change the name to "getModule" because this won't do exactly the same thing as 'require' in AMD-wrapped
// modules. The extension will only be able to load modules that have already been loaded once.
brackets.getModule = require;
+
+ suite = getParamMap().suite || localStorage.getItem("SpecRunner.suite") || "UnitTestSuite";
+
+ // Create a top-level filter to show/hide performance and extensions tests
+ var isPerfSuite = (suite === "PerformanceTestSuite"),
+ isExtSuite = (suite === "ExtensionTestSuite");
+
+ var topLevelFilter = function (spec) {
+ if (!isPerfSuite && !isExtSuite) {
+ return !spec.category;
+ }
+
+ var category = (isPerfSuite) ? "performance" : "extension";
+
+ if (spec.category === category) {
+ return true;
+ }
+
+ var suite = spec.suite;
+
+ while (suite) {
+ if (suite.category === category) {
+ return true;
+ }
+
+ suite = suite.parentSuite;
+ }
+
+ return false;
+ };
- _loadExtensionTests().done(function () {
+ /*
+ * TODO (jason-sanjose): extension unit tests should only load the
+ * extension and the extensions dependencies. We should not load
+ * unrelated extensions. Currently, this solution is all or nothing.
+ */
+
+ // configure spawned test windows to load extensions
+ SpecRunnerUtils.setLoadExtensionsInTestWindow(isExtSuite);
+
+ _loadExtensionTests(suite).done(function () {
var jasmineEnv = jasmine.getEnv();
// Initiailize unit test preferences for each spec
@@ -140,35 +192,14 @@ define(function (require, exports, module) {
jasmineEnv.updateInterval = 1000;
- suite = getParamMap().suite || localStorage.getItem("SpecRunner.suite") || "UnitTestSuite";
-
- // Create a top-level filter to show/hide performance tests
- var isPerfSuite = (suite === "PerformanceTestSuite"),
- performanceFilter = function (spec) {
- if (spec.performance === true) {
- return isPerfSuite;
- }
-
- var suite = spec.suite;
-
- while (suite) {
- if (suite.performance === true) {
- return isPerfSuite;
- }
-
- suite = suite.parentSuite;
- }
-
- return !isPerfSuite;
- };
-
- jasmineEnv.addReporter(new jasmine.BootstrapReporter(document, performanceFilter));
+ jasmineEnv.addReporter(new jasmine.BootstrapReporter(document, topLevelFilter));
// add performance reporting
if (isPerfSuite) {
jasmineEnv.addReporter(new PerformanceReporter());
}
+ // remember the suite for the next unit test window launch
localStorage.setItem("SpecRunner.suite", suite);
$(window.document).ready(_documentReadyHandler);
View
17 test/perf/Performance-test.js
@@ -22,7 +22,7 @@
*/
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
-/*global define, describe, beforeEach, afterEach, it, runs, waitsFor, expect, brackets */
+/*global define, describe, beforeEach, afterEach, it, runs, waitsFor, waitsForDone, expect, brackets */
// TODO: Eventually we should have a brackets performance test suite that is separate from the unit tests
@@ -43,7 +43,7 @@ define(function (require, exports, module) {
describe("Performance Tests", function () {
- this.performance = true;
+ this.category = "performance";
// Note: this tests assumes that the "brackets-scenario" repo is in the same folder
// as the "brackets-app"
@@ -54,19 +54,14 @@ define(function (require, exports, module) {
testWindow;
function openFile(path) {
- var didOpen = false, gotError = false;
-
+ var fullPath = testPath + path;
runs(function () {
- CommandManager.execute(Commands.FILE_OPEN, {fullPath: testPath + path})
- .done(function () {
- didOpen = true;
- })
- .fail(function () { gotError = true; });
+ var promise = CommandManager.execute(Commands.FILE_OPEN, {fullPath: fullPath});
+ waitsForDone(promise);
});
- waitsFor(function () { return didOpen && !gotError; }, 1000);
runs(function () {
- PerformanceReporter.logTestWindow(PerfUtils.OPEN_FILE, path);
+ PerformanceReporter.logTestWindow(/Open File:\t,*/, path);
PerformanceReporter.clearTestWindow();
});
}
View
14 test/perf/PerformanceReporter.js
@@ -38,16 +38,22 @@ define(function (require, exports, module) {
}
function _logTestWindowMeasurement(measureInfo) {
- var value = currentPerfUtils.getData(measureInfo.measure.id),
- printName = measureInfo.measure.name,
+ var value,
+ printName = measureInfo.measure.name || measureInfo.name,
record = {};
+ if (measureInfo.measure instanceof RegExp) {
+ value = currentPerfUtils.searchData(measureInfo.measure);
+ } else {
+ value = currentPerfUtils.getData(measureInfo.measure.id);
+ }
+
if (value === undefined) {
value = "(None)";
}
- if (measureInfo.name) {
- printName = printName + " - " + measureInfo.name;
+ if (measureInfo.measure.name && measureInfo.name) {
+ printName = measureInfo.measure.name + " - " + measureInfo.name;
}
if (measureInfo.operation === "sum") {
View
93 test/spec/SpecRunnerUtils.js
@@ -37,7 +37,8 @@ define(function (require, exports, module) {
OPEN_TAG = "{{",
CLOSE_TAG = "}}",
RE_MARKER = /[^\\]?\{\{(\d+)[^\\]?\}\}/g,
- testWindow;
+ _testWindow,
+ _doLoadExtensions;
function getTestRoot() {
// /path/to/brackets/test/SpecRunner.html
@@ -59,6 +60,23 @@ define(function (require, exports, module) {
return path.join("/");
}
+ function Params() {
+ this.params = [];
+ }
+
+ Params.prototype.push = function (name, value) {
+ this.params.push({name: name, value: value});
+ };
+
+ Params.prototype.toString = function () {
+ var strs = [];
+
+ this.params.forEach(function (param) {
+ strs.push(encodeURIComponent(param.name) + "=" + encodeURIComponent(param.value));
+ });
+
+ return strs.join("&");
+ };
/**
* Utility for tests that wait on a Promise to complete. Placed in the global namespace so it can be used
@@ -128,24 +146,30 @@ define(function (require, exports, module) {
testWindowY = window.screen.availHeight - testWindowHt,
optionsStr = "left=" + testWindowX + ",top=" + testWindowY +
",width=" + testWindowWid + ",height=" + testWindowHt;
- testWindow = window.open(getBracketsSourceRoot() + "/index.html", "_blank", optionsStr);
- testWindow.executeCommand = function executeCommand(cmd, args) {
- return testWindow.brackets.test.CommandManager.execute(cmd, args);
+ var params = new Params();
+
+ // setup extension loading in the test window
+ params.push("extensions", _doLoadExtensions ? "default,user" : "default");
+
+ _testWindow = window.open(getBracketsSourceRoot() + "/index.html?" + params.toString(), "_blank", optionsStr);
+
+ _testWindow.executeCommand = function executeCommand(cmd, args) {
+ return _testWindow.brackets.test.CommandManager.execute(cmd, args);
};
});
// FIXME (issue #249): Need an event or something a little more reliable...
waitsFor(
function isBracketsDoneLoading() {
- return testWindow.brackets && testWindow.brackets.test && testWindow.brackets.test.doneLoading;
+ return _testWindow.brackets && _testWindow.brackets.test && _testWindow.brackets.test.doneLoading;
},
10000
);
runs(function () {
// callback allows specs to query the testWindow before they run
- callback.call(spec, testWindow);
+ callback.call(spec, _testWindow);
});
}
@@ -156,7 +180,7 @@ define(function (require, exports, module) {
runs(function () {
//we need to mark the documents as not dirty before we close
//or the window will stay open prompting to save
- var openDocs = testWindow.brackets.test.DocumentManager.getAllOpenDocuments();
+ var openDocs = _testWindow.brackets.test.DocumentManager.getAllOpenDocuments();
openDocs.forEach(function resetDoc(doc) {
if (doc.isDirty) {
//just refresh it back to it's current text. This will mark it
@@ -164,7 +188,7 @@ define(function (require, exports, module) {
doc.refreshText(doc.getText(), doc.diskTimestamp);
}
});
- testWindow.close();
+ _testWindow.close();
});
}
@@ -178,7 +202,7 @@ define(function (require, exports, module) {
*/
function clickDialogButton(buttonId) {
// Make sure there's one and only one dialog open
- var $dlg = testWindow.$(".modal.instance"),
+ var $dlg = _testWindow.$(".modal.instance"),
promise = $dlg.data("promise");
expect($dlg.length).toBe(1);
@@ -200,7 +224,7 @@ define(function (require, exports, module) {
runs(function () {
// begin loading project path
- var result = testWindow.brackets.test.ProjectManager.openProject(path);
+ var result = _testWindow.brackets.test.ProjectManager.openProject(path);
result.done(function () {
isReady = true;
});
@@ -268,7 +292,7 @@ define(function (require, exports, module) {
* @return {!Array.<string>|string} Absolute file path(s)
*/
function makeAbsolute(paths) {
- var fullPath = testWindow.brackets.test.ProjectManager.getProjectRoot().fullPath;
+ var fullPath = _testWindow.brackets.test.ProjectManager.getProjectRoot().fullPath;
function prefixProjectPath(path) {
if (path.indexOf(fullPath) === 0) {
@@ -292,7 +316,7 @@ define(function (require, exports, module) {
* @return {!Array.<string>|string} Relative file path(s)
*/
function makeRelative(paths) {
- var fullPath = testWindow.brackets.test.ProjectManager.getProjectRoot().fullPath,
+ var fullPath = _testWindow.brackets.test.ProjectManager.getProjectRoot().fullPath,
fullPathLength = fullPath.length;
function removeProjectPath(path) {
@@ -351,7 +375,7 @@ define(function (require, exports, module) {
fullpaths = makeArray(makeAbsolute(paths)),
keys = makeArray(makeRelative(paths)),
docs = {},
- FileViewController = testWindow.brackets.test.FileViewController;
+ FileViewController = _testWindow.brackets.test.FileViewController;
Async.doSequentially(fullpaths, function (path, i) {
var one = new $.Deferred();
@@ -456,7 +480,7 @@ define(function (require, exports, module) {
function toggleQuickEditAtOffset(editor, offset) {
editor.setCursorPos(offset.line, offset.ch);
- return testWindow.executeCommand(Commands.TOGGLE_QUICK_EDIT);
+ return _testWindow.executeCommand(Commands.TOGGLE_QUICK_EDIT);
}
/**
@@ -523,26 +547,31 @@ define(function (require, exports, module) {
}
function getTestWindow() {
- return testWindow;
+ return _testWindow;
+ }
+
+ function setLoadExtensionsInTestWindow(doLoadExtensions) {
+ _doLoadExtensions = doLoadExtensions;
}
exports.TEST_PREFERENCES_KEY = TEST_PREFERENCES_KEY;
- exports.getTestRoot = getTestRoot;
- exports.getTestPath = getTestPath;
- exports.getBracketsSourceRoot = getBracketsSourceRoot;
- exports.makeAbsolute = makeAbsolute;
- exports.createMockDocument = createMockDocument;
- exports.createTestWindowAndRun = createTestWindowAndRun;
- exports.closeTestWindow = closeTestWindow;
- exports.clickDialogButton = clickDialogButton;
- exports.loadProjectInTestWindow = loadProjectInTestWindow;
- exports.openProjectFiles = openProjectFiles;
- exports.toggleQuickEditAtOffset = toggleQuickEditAtOffset;
- exports.saveFilesWithOffsets = saveFilesWithOffsets;
- exports.saveFilesWithoutOffsets = saveFilesWithoutOffsets;
- exports.saveFileWithoutOffsets = saveFileWithoutOffsets;
- exports.deleteFile = deleteFile;
- exports.getTestWindow = getTestWindow;
- exports.simulateKeyEvent = simulateKeyEvent;
+ exports.getTestRoot = getTestRoot;
+ exports.getTestPath = getTestPath;
+ exports.getBracketsSourceRoot = getBracketsSourceRoot;
+ exports.makeAbsolute = makeAbsolute;
+ exports.createMockDocument = createMockDocument;
+ exports.createTestWindowAndRun = createTestWindowAndRun;
+ exports.closeTestWindow = closeTestWindow;
+ exports.clickDialogButton = clickDialogButton;
+ exports.loadProjectInTestWindow = loadProjectInTestWindow;
+ exports.openProjectFiles = openProjectFiles;
+ exports.toggleQuickEditAtOffset = toggleQuickEditAtOffset;
+ exports.saveFilesWithOffsets = saveFilesWithOffsets;
+ exports.saveFilesWithoutOffsets = saveFilesWithoutOffsets;
+ exports.saveFileWithoutOffsets = saveFileWithoutOffsets;
+ exports.deleteFile = deleteFile;
+ exports.getTestWindow = getTestWindow;
+ exports.simulateKeyEvent = simulateKeyEvent;
+ exports.setLoadExtensionsInTestWindow = setLoadExtensionsInTestWindow;
});
Please sign in to comment.
Something went wrong with that request. Please try again.