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

Commit 03d2b45

Browse files
committed
Merge pull request #1284 from adobe/jason-sanjose/issue-1275
Prevent extensions from loading in test windows
2 parents de3dbfc + 8c501a8 commit 03d2b45

File tree

11 files changed

+262
-115
lines changed

11 files changed

+262
-115
lines changed

src/brackets.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,17 @@ define(function (require, exports, module) {
7878
Dialogs = require("widgets/Dialogs"),
7979
ExtensionLoader = require("utils/ExtensionLoader"),
8080
SidebarView = require("project/SidebarView"),
81-
Async = require("utils/Async");
81+
Async = require("utils/Async"),
82+
UrlParams = require("utils/UrlParams").UrlParams;
8283

8384
// Local variables
84-
var bracketsReady = false,
85-
bracketsReadyHandlers = [];
86-
85+
var bracketsReady = false,
86+
bracketsReadyHandlers = [],
87+
params = new UrlParams();
88+
89+
// read URL params
90+
params.parse();
91+
8792
//Load modules that self-register and just need to get included in the main project
8893
require("document/ChangedDocumentTracker");
8994
require("editor/EditorCommandHandlers");
@@ -175,7 +180,10 @@ define(function (require, exports, module) {
175180
// TODO: (issue 1029) Add timeout to main extension loading promise, so that we always call this function
176181
// Making this fix will fix a warning (search for issue 1029) related to the brackets 'ready' event.
177182
function _initExtensions() {
178-
return Async.doInParallel(["default", "user"], function (item) {
183+
// allow unit tests to override which plugin folder(s) to load
184+
var paths = params.get("extensions") || "default,user";
185+
186+
return Async.doInParallel(paths.split(","), function (item) {
179187
return ExtensionLoader.loadAllExtensionsInNativeDirectory(
180188
FileUtils.getNativeBracketsDirectoryPath() + "/extensions/" + item,
181189
"extensions/" + item

src/extensions/default/JavaScriptQuickEdit/unittests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ define(function (require, exports, module) {
279279

280280
describe("Performance suite", function () {
281281

282-
this.performance = true;
282+
this.category = "performance";
283283

284284
var testPath = SpecRunnerUtils.getTestPath("/../../../brackets-scenario/jquery-ui/");
285285

src/utils/PerfUtils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,20 @@ define(function (require, exports, module) {
316316
return perfData[toMeasurementId(name)];
317317
}
318318

319+
function searchData(regExp) {
320+
var keys = Object.keys(perfData).filter(function (key) {
321+
return regExp.test(key);
322+
});
323+
324+
var datas = [];
325+
326+
keys.forEach(function (key) {
327+
datas.push(perfData[key]);
328+
});
329+
330+
return datas;
331+
}
332+
319333
/**
320334
* Clear all logs including metric data and active tests.
321335
*/
@@ -336,6 +350,7 @@ define(function (require, exports, module) {
336350
exports.isActive = isActive;
337351
exports.markStart = markStart;
338352
exports.getData = getData;
353+
exports.searchData = searchData;
339354
exports.updateMeasurement = updateMeasurement;
340355
exports.getDelimitedPerfData = getDelimitedPerfData;
341356
exports.createPerfMeasurement = createPerfMeasurement;

src/utils/UrlParams.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
25+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
26+
/*global define, window */
27+
28+
define(function (require, exports, module) {
29+
"use strict";
30+
31+
/**
32+
* Convert between URL querystring and name/value pairs. Decodes and encodes URL parameters.
33+
*/
34+
function UrlParams() {
35+
this._store = {};
36+
}
37+
38+
/**
39+
* Parse the window location by default. Optionally specify a URL to parse.
40+
* @param {string} url
41+
*/
42+
UrlParams.prototype.parse = function (url) {
43+
if (url) {
44+
url = url.substring(indexOf("?") + 1);
45+
} else {
46+
url = window.document.location.search.substring(1);
47+
}
48+
49+
var urlParams = url.split("&"),
50+
p,
51+
self = this;
52+
53+
urlParams.forEach(function (param) {
54+
p = param.split("=");
55+
self._store[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
56+
});
57+
};
58+
59+
/**
60+
* Store a name/value string pair
61+
* @param {!string} name
62+
* @param {!string} value
63+
*/
64+
UrlParams.prototype.put = function (name, value) {
65+
this._store[name] = value;
66+
};
67+
68+
/**
69+
* Retreive a value by name
70+
* @param {!string} name
71+
*/
72+
UrlParams.prototype.get = function (name) {
73+
return this._store[name];
74+
};
75+
76+
/**
77+
* Encode name/value pairs as URI components.
78+
*/
79+
UrlParams.prototype.toString = function () {
80+
var strs = [],
81+
self = this;
82+
83+
Object.keys(self._store).forEach(function (key) {
84+
strs.push(encodeURIComponent(key) + "=" + encodeURIComponent(self._store[key]));
85+
});
86+
87+
return strs.join("&");
88+
};
89+
90+
// Define public API
91+
exports.UrlParams = UrlParams;
92+
});

test/BootstrapReporter.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50, forin: true */
2-
/*global jasmine, document */
3-
(function ($) {
2+
/*global jasmine, $, define, document, require */
3+
define(function (require, exports, module) {
44
'use strict';
5+
6+
var UrlParams = require("utils/UrlParams").UrlParams;
57

68
jasmine.BootstrapReporter = function (doc, filter) {
7-
this._paramMap = {};
89
this.document = doc || document;
910
this._env = jasmine.getEnv();
11+
this.params = new UrlParams();
12+
this.params.parse();
1013

1114
// parse querystring
1215
var self = this,
13-
params = this.document.location.search.substring(1).split('&'),
1416
i,
1517
p;
1618

17-
for (i = 0; i < params.length; i++) {
18-
p = params[i].split('=');
19-
this._paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
20-
}
21-
22-
this._runAll = this._paramMap.spec === "All";
19+
this._runAll = this.params.get("spec") === "All";
2320

2421
// _topLevelFilter is applied first - selects Performance vs. Unit test suites
2522
this._topLevelFilter = filter;
2623

2724
// Jasmine's runner uses the specFilter to choose which tests to run.
2825
// If you selected an option other than "All" this will be a subset of all tests loaded.
29-
this._env.specFilter = this.createSpecFilter(this._paramMap.spec);
26+
this._env.specFilter = this.createSpecFilter(this.params.get("spec"));
3027
this._runner = this._env.currentRunner();
3128

3229
// build DOM immediately
@@ -187,7 +184,7 @@
187184
this._createSuiteList();
188185

189186
// highlight the current suite
190-
topLevelData = (this._paramMap.spec) ? this._topLevelSuiteMap[this._paramMap.spec] : null;
187+
topLevelData = (this.params.get("spec")) ? this._topLevelSuiteMap[this.params.get("spec")] : null;
191188

192189
if (topLevelData) {
193190
topLevelData.$listItem.toggleClass("active", true);
@@ -229,7 +226,7 @@
229226
passed,
230227
data = this._topLevelSuiteMap[suite.getFullName()];
231228

232-
if ((suite.getFullName() === this._paramMap.spec) && data) {
229+
if ((suite.getFullName() === this.params.get("spec")) && data) {
233230
passed = results.passed();
234231

235232
data.$badgeAll.hide();
@@ -354,4 +351,4 @@
354351

355352
jasmine.BootstrapReporter.prototype.log = function (str) {
356353
};
357-
}(window.jQuery));
354+
});

test/PerformanceTestSuite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
define(function (require, exports, module) {
2727
'use strict';
2828

29-
// Each suite or spec must have this.performance = true to be filtered properly
29+
// Each suite or spec must have this.category === "performance" to be filtered properly
3030
require("perf/Performance-test");
3131
});

test/SpecRunner.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,11 @@
3232
<link href="BootstrapReporter.css" rel="stylesheet">
3333

3434
<script src="thirdparty/jasmine-core/jasmine.js"></script>
35-
<script src="thirdparty/jasmine-core/jasmine-html.js"></script>
36-
<script src="thirdparty/jasmine-jquery-1.3.1.js"></script>
3735

3836
<!-- Pre-load third party scripts that cannot be async loaded. -->
3937
<script src="../src/thirdparty/jquery-1.7.min.js"></script>
4038
<script src="../src/thirdparty/CodeMirror2/lib/codemirror.js"></script>
4139
<script src="thirdparty/bootstrap2/js/bootstrap.min.js"></script>
42-
<script src="BootstrapReporter.js"></script>
4340

4441
<!-- All other scripts are loaded through require. -->
4542
<script src="../src/thirdparty/require.js" data-main="SpecRunner"></script>
@@ -61,6 +58,7 @@
6158
<ul class="nav">
6259
<li><a id="UnitTestSuite" href="?suite=UnitTestSuite">Unit</a></li>
6360
<li><a id="PerformanceTestSuite" href="?suite=PerformanceTestSuite">Performance</a></li>
61+
<li><a id="ExtensionSuite" href="?suite=ExtensionTestSuite">Extensions</a></li>
6462
<li><a id="reload" href="#">Reload</a></li>
6563
<li><a id="show-dev-tools" href="#">Show Developer Tools</a></li>
6664
</ul>

0 commit comments

Comments
 (0)