Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactored all unit test data (including perf data) out into UnitTest…

…Reporter, which now handles all the reporter callbacks.
  • Loading branch information...
commit eb40de8dda5c3c37ea34ff972d37f22734a11f01 1 parent b54ab9f
@njx njx authored
View
7 src/extensions/default/JavaScriptQuickEdit/unittests.js
@@ -37,7 +37,7 @@ define(function (require, exports, module) {
FileUtils = brackets.getModule("file/FileUtils"),
NativeFileSystem = brackets.getModule("file/NativeFileSystem").NativeFileSystem,
SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"),
- PerformanceReporter = brackets.getModule("perf/PerformanceReporter");
+ UnitTestReporter = brackets.getModule("test/UnitTestReporter");
var extensionPath = FileUtils.getNativeModuleDirectoryPath(module),
testPath = extensionPath + "/unittest-files/syntax",
@@ -355,8 +355,9 @@ define(function (require, exports, module) {
};
function logPerf() {
- PerformanceReporter.logTestWindow(perfMeasurements);
- PerformanceReporter.clearTestWindow();
+ var reporter = UnitTestReporter.getActiveReporter();
+ reporter.logTestWindow(perfMeasurements);
+ reporter.clearTestWindow();
}
// repeat 5 times
View
300 test/BootstrapReporter.js
@@ -1,300 +0,0 @@
-/*
- * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
-/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50, forin: true */
-/*global jasmine, $, define, document, require */
-define(function (require, exports, module) {
- 'use strict';
-
- var UrlParams = require("utils/UrlParams").UrlParams,
- SpecRunnerUtils = require("spec/SpecRunnerUtils");
-
- jasmine.BootstrapReporter = function (doc, filter, topLevelResults) {
- this.document = doc || document;
- this._env = jasmine.getEnv();
- this.params = new UrlParams();
- this.params.parse();
-
- // parse querystring
- var self = this,
- i,
- p;
-
- this._runAll = this.params.get("spec") === "All";
-
- // _topLevelFilter is applied first - selects Performance vs. Unit test suites
- this._topLevelFilter = filter;
-
- // Jasmine's runner uses the specFilter to choose which tests to run.
- // If you selected an option other than "All" this will be a subset of all tests loaded.
- this._env.specFilter = this.createSpecFilter(this.params.get("spec"));
- this._runner = this._env.currentRunner();
- this._topLevelResults = topLevelResults;
-
- // build DOM immediately
- var container = $(
- '<div class="container-fluid">' +
- '<div class="row-fluid">' +
- '<div class="span4">' +
- '<ul id="suite-list" class="nav nav-pills nav-stacked">' +
- '</ul>' +
- '</div>' +
- '<div id="results-container" class="span8">' +
- '</div>' +
- '</div>' +
- '</div>'
- );
-
- $(this.document.body).append(container);
-
- this._topLevelSuiteMap = {};
- this.$suiteList = $("#suite-list");
- this.$resultsContainer = $("#results-container");
- };
-
- /**
- * @private
- * Filters specs by full name. Applies _topLevelFilter first before checking
- * for a matching starting substring.
- */
- jasmine.BootstrapReporter.prototype.createSpecFilter = function (filterString) {
- var self = this;
-
- return function (spec) {
- // filterString is undefined when no top-level suite is active (e.g. "All", "HTMLUtils", etc.)
- // When undefined, all specs fail this filter and no tests are ran. This is by design.
- // This setup allows the SpecRunner to load initially without automatically running all tests.
- if (filterString === undefined) {
- return false;
- }
-
- if (!self._topLevelFilter(spec)) {
- return false;
- }
-
- if (filterString === "All") {
- return true;
- }
-
- if (spec.getFullName() === filterString) {
- return true;
- }
-
- // spec.getFullName() concatenates the names of all containing describe()s. We want to filter
- // on just the outermost suite's name (i.e., the item that was selected in the spec list UI)
- // to avoid ambiguity when suite names share the same prefix.
- var topLevelSuite = spec.suite;
- while (topLevelSuite.parentSuite) {
- topLevelSuite = topLevelSuite.parentSuite;
- }
-
- return topLevelSuite.description === filterString;
- };
- };
-
- jasmine.BootstrapReporter.prototype._createSuiteListItem = function (suiteName, specCount) {
- var $badgeAll = $('<span class="badge">' + specCount + "</span>"),
- $badgePassed = $('<span class="badge badge-success" style="display:none"/>'),
- $badgeFailed = $('<span class="badge badge-important" style="display:none"/>'),
- $anchor = $('<a href="?spec=' + encodeURIComponent(suiteName) + '">' + suiteName + '</a>').append($badgeAll).append($badgePassed).append($badgeFailed),
- $listItem = $('<li/>').append($anchor),
- self = this,
- active;
-
- this._topLevelSuiteMap[suiteName] = {
- $badgeAll: $badgeAll,
- $badgePassed: $badgePassed,
- $badgeFailed: $badgeFailed,
- $anchor: $anchor,
- $listItem: $listItem
- };
-
- return $listItem;
- };
-
- jasmine.BootstrapReporter.prototype._createSuiteList = function () {
- var suites = this._topLevelResults.suites,
- sortedNames = this._topLevelResults.sortedNames,
- self = this;
-
- sortedNames.forEach(function (name, index) {
- var count = suites[name].specCount;
- if (count > 0) {
- self.$suiteList.append(self._createSuiteListItem(name, count));
- }
- });
-
- // add an "all" top-level suite
- this.$suiteList.prepend(this._createSuiteListItem("All", suites.All.specCount));
- };
-
- jasmine.BootstrapReporter.prototype._showProgressBar = function (spec) {
- if (!this.$progressBar) {
- this.$progress = $('<div class="bar"/>');
- this.$progressBar = $('<div class="progress progress-striped"/>').append(this.$progress);
- }
-
- this.$resultsContainer.append(this.$progressBar);
- };
-
- jasmine.BootstrapReporter.prototype.reportRunnerStarting = function (runner) {
- var specs = runner.specs(),
- topLevelData,
- self = this;
-
- // create top level suite list navigation
- this._createSuiteList();
-
- // highlight the current suite
- topLevelData = (this.params.get("spec")) ? this._topLevelSuiteMap[this.params.get("spec")] : null;
-
- if (topLevelData) {
- topLevelData.$listItem.toggleClass("active", true);
- }
-
- this._specCount = 0;
- this._specCompleteCount = 0;
-
- specs.forEach(function (spec, index) {
- if (self._env.specFilter(spec)) {
- self._specCount++;
- }
- });
-
- if (this._specCount) {
- this._showProgressBar();
-
- // display current running test
- this.$info = $('<div class="alert alert-info"/>');
- this.$resultsContainer.append(this.$info);
- this.$resultsContainer.append($('<hr/>'));
- }
- };
-
- jasmine.BootstrapReporter.prototype.reportRunnerResults = function (runner) {
- if (this.$info) {
- this.$info.toggleClass("alert-info", false);
-
- if (runner.results().passed()) {
- this.$info.toggleClass("alert-success", true).text("Complete. No failures.");
- } else {
- this.$info.toggleClass("alert-error", true).text("Complete. See failures.");
- }
- }
- };
-
- jasmine.BootstrapReporter.prototype.reportSuiteResults = function (suite) {
- var results = suite.results(),
- passed,
- data = this._topLevelSuiteMap[suite.getFullName()];
-
- if ((suite.getFullName() === this.params.get("spec")) && data) {
- passed = results.passed();
-
- data.$badgeAll.hide();
- }
- };
-
- jasmine.BootstrapReporter.prototype.reportSpecStarting = function (spec) {
- this.$info.text("Running " + spec.getFullName());
- };
-
- jasmine.BootstrapReporter.prototype._updateSuiteStatus = function (suiteName) {
- var suiteResults = this._topLevelResults.suites[suiteName],
- data = this._topLevelSuiteMap[suiteName];
-
- if (!data) {
- return;
- }
-
- // update status badges
- if (suiteResults.passedCount) {
- data.$badgePassed.show().text(suiteResults.passedCount);
- } else {
- data.$badgePassed.hide();
- }
-
- if (suiteResults.failedCount) {
- data.$badgeFailed.show().text(suiteResults.failedCount);
- } else {
- data.$badgeFailed.hide();
- }
-
- var specsRemaining = suiteResults.specCount - suiteResults.passedCount - suiteResults.failedCount;
-
- if (specsRemaining === 0) {
- data.$badgeAll.hide();
- } else {
- data.$badgeAll.text(specsRemaining);
- }
- };
-
- // Jasmine calls this function for all specs, not just filtered specs.
- jasmine.BootstrapReporter.prototype.reportSpecResults = function (spec) {
- var results = spec.results(),
- $specLink,
- $resultDisplay,
- suiteName;
-
- if (!results.skipped) {
- this._topLevelResults.addSpecResults(spec, spec.results());
- this._updateSuiteStatus(this._topLevelResults.getTopLevelSuiteName(spec));
- this._updateSuiteStatus("All");
-
- // update progress
- this._specCompleteCount++;
- this.$progress.css("width", Math.round((this._specCompleteCount / this._specCount) * 100) + "%");
-
- if (!results.passed()) {
- // print suite name if not present
- var $suiteHeader = $("#suite-results-" + spec.suite.id);
-
- if ($suiteHeader.length === 0) {
- this.$resultsContainer.append($('<div id="suite-results-' + spec.suite.id + '" class="alert alert-info"/>').text(spec.suite.getFullName()));
- }
-
- // print spec name
- $specLink = $('<a href="?spec=' + encodeURIComponent(spec.getFullName()) + '"/>').text(spec.description);
- $resultDisplay = $('<div class="alert alert-error"/>').append($specLink);
-
- // print failure details
- var resultItems = results.getItems(),
- $message,
- i;
-
- for (i = 0; i < resultItems.length; i++) {
- var result = resultItems[i];
- $message = $('<pre/>').text(SpecRunnerUtils.getResultMessage(result));
- if ($message) {
- $resultDisplay.append($message);
- }
- }
-
- this.$resultsContainer.append($resultDisplay);
- }
- }
- };
-
- jasmine.BootstrapReporter.prototype.log = function (str) {
- };
-});
View
0  test/BootstrapReporter.css → test/BootstrapReporterView.css
File renamed without changes
View
276 test/BootstrapReporterView.js
@@ -0,0 +1,276 @@
+/*
+ * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50, forin: true */
+/*global jasmine, $, define, document, require */
+define(function (require, exports, module) {
+ 'use strict';
+
+ var UrlParams = require("utils/UrlParams").UrlParams,
+ SpecRunnerUtils = require("spec/SpecRunnerUtils");
+
+ var BootstrapReporterView = function (doc, reporter) {
+ doc = doc || document;
+
+ $(reporter)
+ .on("runnerStart", this._handleRunnerStart.bind(this))
+ .on("runnerEnd", this._handleRunnerEnd.bind(this))
+ .on("suiteEnd", this._handleSuiteEnd.bind(this))
+ .on("specStart", this._handleSpecStart.bind(this))
+ .on("specEnd", this._handleSpecEnd.bind(this));
+
+ // build DOM immediately
+ var container = $(
+ '<div class="container-fluid">' +
+ '<div class="row-fluid">' +
+ '<div class="span4">' +
+ '<ul id="suite-list" class="nav nav-pills nav-stacked">' +
+ '</ul>' +
+ '</div>' +
+ '<div id="results-container" class="span8">' +
+ '</div>' +
+ '</div>' +
+ '</div>'
+ );
+
+ $(doc.body).append(container);
+
+ this._topLevelSuiteMap = {};
+ this.$suiteList = $("#suite-list");
+ this.$resultsContainer = $("#results-container");
+ };
+
+ BootstrapReporterView.prototype._createSuiteListItem = function (suiteName, specCount) {
+ var $badgeAll = $('<span class="badge">' + specCount + "</span>"),
+ $badgePassed = $('<span class="badge badge-success" style="display:none"/>'),
+ $badgeFailed = $('<span class="badge badge-important" style="display:none"/>'),
+ $anchor = $('<a href="?spec=' + encodeURIComponent(suiteName) + '">' + suiteName + '</a>').append($badgeAll).append($badgePassed).append($badgeFailed),
+ $listItem = $('<li/>').append($anchor),
+ self = this,
+ active;
+
+ this._topLevelSuiteMap[suiteName] = {
+ $badgeAll: $badgeAll,
+ $badgePassed: $badgePassed,
+ $badgeFailed: $badgeFailed,
+ $anchor: $anchor,
+ $listItem: $listItem
+ };
+
+ return $listItem;
+ };
+
+ BootstrapReporterView.prototype._createSuiteList = function (suites, sortedNames, totalSpecCount) {
+ var self = this;
+
+ sortedNames.forEach(function (name, index) {
+ var count = suites[name].specCount;
+ if (count > 0) {
+ self.$suiteList.append(self._createSuiteListItem(name, count));
+ }
+ });
+
+ // add an "all" top-level suite
+ this.$suiteList.prepend(this._createSuiteListItem("All", totalSpecCount));
+ };
+
+ BootstrapReporterView.prototype._showProgressBar = function (spec) {
+ if (!this.$progressBar) {
+ this.$progress = $('<div class="bar"/>');
+ this.$progressBar = $('<div class="progress progress-striped"/>').append(this.$progress);
+ }
+
+ this.$resultsContainer.append(this.$progressBar);
+ };
+
+ BootstrapReporterView.prototype._handleRunnerStart = function (event, reporter) {
+ var topLevelData,
+ self = this;
+
+ // create top level suite list navigation
+ this._createSuiteList(reporter.suites, reporter.sortedNames, reporter.totalSpecCount);
+
+ // highlight the current suite
+ topLevelData = reporter.activeSuite ? this._topLevelSuiteMap[reporter.activeSuite] : null;
+
+ if (topLevelData) {
+ topLevelData.$listItem.toggleClass("active", true);
+ }
+
+ if (reporter.activeSpecCount) {
+ this._showProgressBar();
+
+ // display current running test
+ this.$info = $('<div class="alert alert-info"/>');
+ this.$resultsContainer.append(this.$info);
+ this.$resultsContainer.append($('<hr/>'));
+ }
+ };
+
+ BootstrapReporterView.prototype._handleRunnerEnd = function (event, reporter) {
+ if (this.$info) {
+ this.$info.toggleClass("alert-info", false);
+
+ if (reporter.passed) {
+ this.$info.toggleClass("alert-success", true).text("Complete. No failures.");
+ } else {
+ this.$info.toggleClass("alert-error", true).text("Complete. See failures.");
+ }
+ }
+ };
+
+ BootstrapReporterView.prototype._handleSuiteEnd = function (event, reporter, suiteData) {
+ var data = this._topLevelSuiteMap[suiteData.name];
+ if ((suiteData.name === reporter.activeSuite) && data) {
+ data.$badgeAll.hide();
+ }
+ };
+
+ BootstrapReporterView.prototype._handleSpecStart = function (event, reporter, specName) {
+ this.$info.text("Running " + specName);
+ };
+
+ BootstrapReporterView.prototype._updateSuiteStatus = function (name, specCount, passedCount, failedCount) {
+ var data = this._topLevelSuiteMap[name];
+
+ if (!data) {
+ return;
+ }
+
+ // update status badges
+ if (passedCount) {
+ data.$badgePassed.show().text(passedCount);
+ } else {
+ data.$badgePassed.hide();
+ }
+
+ if (failedCount) {
+ data.$badgeFailed.show().text(failedCount);
+ } else {
+ data.$badgeFailed.hide();
+ }
+
+ var specsRemaining = specCount - passedCount - failedCount;
+
+ if (specsRemaining === 0) {
+ data.$badgeAll.hide();
+ } else {
+ data.$badgeAll.text(specsRemaining);
+ }
+ };
+
+ BootstrapReporterView.prototype._createRows = function (record, level) {
+ var rows = [],
+ $row,
+ indent = "",
+ i,
+ self = this;
+
+ level = (level || 0);
+
+ for (i = 0; i < level; i++) {
+ indent = indent.concat("&nbsp;&nbsp;&nbsp;");
+ }
+
+ if (level > 0) {
+ indent = indent.concat("•&nbsp;");
+ } else if (record.children) {
+ indent = "»&nbsp;".concat(indent);
+ }
+
+ $row = $("<tr/>");
+ $row.append($("<td>" + indent + record.name + "</td><td>" + record.value + "</td>"));
+
+ rows.push($row);
+
+ if (record.children) {
+ level++;
+ record.children.forEach(function (child) {
+ Array.prototype.push.apply(rows, self._createRows(child, level));
+ });
+ }
+
+ return rows;
+ };
+
+ BootstrapReporterView.prototype._handleSpecEnd = function (event, reporter, specData, suiteData) {
+ var $specLink,
+ $resultDisplay,
+ suiteName,
+ self = this;
+
+ this._updateSuiteStatus(suiteData.name, suiteData.specCount, suiteData.passedCount, suiteData.failedCount);
+ this._updateSuiteStatus("All", reporter.totalSpecCount, reporter.totalPassedCount, reporter.totalFailedCount);
+
+ this.$progress.css("width", Math.round((reporter.activeSpecCompleteCount / reporter.activeSpecCount) * 100) + "%");
+
+ if (!specData.passed) {
+ // print suite name if not present
+ var $suiteHeader = $("#suite-results-" + suiteData.id);
+
+ if ($suiteHeader.length === 0) {
+ this.$resultsContainer.append($('<div id="suite-results-' + suiteData.id + '" class="alert alert-info"/>').text(suiteData.name));
+ }
+
+ // print spec name
+ $specLink = $('<a href="?spec=' + encodeURIComponent(specData.name) + '"/>').text(specData.description);
+ $resultDisplay = $('<div class="alert alert-error"/>').append($specLink);
+
+ // print failure details
+ if (specData.messages) {
+ specData.messages.forEach(function (message) {
+ $resultDisplay.append($('<pre/>').text(message));
+ });
+ }
+
+ this.$resultsContainer.append($resultDisplay);
+ }
+
+ if (specData.passed && specData.perf) {
+ // add spec name
+ $specLink = $('<a href="?spec=' + encodeURIComponent(specData.name) + '"/>').text(specData.name);
+ this.$resultsContainer.append($('<div class="alert alert-info"/>').append($specLink));
+
+ // add table
+ var $table = $('<table class="table table-striped table-bordered table-condensed"><thead><tr><th>Measurement</th><th>Value</th></tr></thead></table>'),
+ $tbody = $table.append($('<tbody/>')),
+ rows,
+ specRecords = specData.perf;
+
+ this.$resultsContainer.append($table);
+
+ specRecords.forEach(function (record) {
+ rows = self._createRows(record);
+
+ rows.forEach(function (row) {
+ $tbody.append(row);
+ });
+ });
+ }
+ };
+
+ BootstrapReporterView.prototype.log = function (str) {
+ };
+
+ exports.BootstrapReporterView = BootstrapReporterView;
+});
View
2  test/SpecRunner.html
@@ -29,7 +29,7 @@
<link href="thirdparty/bootstrap2/css/bootstrap.min.css" rel="stylesheet">
<link href="thirdparty/bootstrap2/css/bootstrap-responsive.min.css" rel="stylesheet">
- <link href="BootstrapReporter.css" rel="stylesheet">
+ <link href="BootstrapReporterView.css" rel="stylesheet">
<script src="thirdparty/jasmine-core/jasmine.js"></script>
View
35 test/SpecRunner.js
@@ -40,19 +40,16 @@ define(function (require, exports, module) {
'use strict';
// Utility dependency
- var Global = require("utils/Global"),
- SpecRunnerUtils = require("spec/SpecRunnerUtils"),
- PerformanceReporter = require("perf/PerformanceReporter").PerformanceReporter,
- ExtensionLoader = require("utils/ExtensionLoader"),
- Async = require("utils/Async"),
- FileUtils = require("file/FileUtils"),
- Menus = require("command/Menus"),
- UrlParams = require("utils/UrlParams").UrlParams,
- TopLevelResults = require("test/TopLevelResults").TopLevelResults;
+ var Global = require("utils/Global"),
+ SpecRunnerUtils = require("spec/SpecRunnerUtils"),
+ ExtensionLoader = require("utils/ExtensionLoader"),
+ Async = require("utils/Async"),
+ FileUtils = require("file/FileUtils"),
+ Menus = require("command/Menus"),
+ UrlParams = require("utils/UrlParams").UrlParams,
+ UnitTestReporter = require("test/UnitTestReporter").UnitTestReporter,
+ BootstrapReporterView = require("test/BootstrapReporterView").BootstrapReporterView;
- // Jasmine reporter UI
- require("test/BootstrapReporter");
-
// Load modules that self-register and just need to get included in the main project
require("document/ChangedDocumentTracker");
@@ -62,7 +59,8 @@ define(function (require, exports, module) {
var suite,
params = new UrlParams(),
- topLevelResults;
+ reporter,
+ reporterView;
params.parse();
@@ -169,8 +167,6 @@ define(function (require, exports, module) {
_loadExtensionTests(suite).done(function () {
var jasmineEnv = jasmine.getEnv();
- topLevelResults = new TopLevelResults(jasmineEnv.currentRunner(), topLevelFilter);
-
// Initiailize unit test preferences for each spec
beforeEach(function () {
// Unique key for unit testing
@@ -184,12 +180,9 @@ define(function (require, exports, module) {
jasmineEnv.updateInterval = 1000;
- jasmineEnv.addReporter(new jasmine.BootstrapReporter(document, topLevelFilter, topLevelResults));
-
- // add performance reporting
- if (isPerfSuite) {
- jasmineEnv.addReporter(new PerformanceReporter(topLevelResults));
- }
+ reporter = new UnitTestReporter(jasmineEnv, topLevelFilter);
+ jasmineEnv.addReporter(reporter);
+ reporterView = new BootstrapReporterView(document, reporter);
// remember the suite for the next unit test window launch
localStorage.setItem("SpecRunner.suite", suite);
View
187 test/TopLevelResults.js
@@ -1,187 +0,0 @@
-/*
- * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
-/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50, forin: true */
-/*global $, define */
-
-/**
- * A massaged version of the standard Jasmine results that:
- * - summarizes the results for each top-level suite (instead of flattening out all suites)
- * - counts the number of passed/failed specs instead of counting each expect()
- */
-
-define(function (require, exports, module) {
- "use strict";
-
- var SpecRunnerUtils = require("spec/SpecRunnerUtils");
-
- /**
- * @constructor
- * Creates a TopLevelResults object. This has two public properties:
- *
- * suites - an object with entries for each top-level suite; each value is an object containing:
- * specCount - number of specs in the suite and its descendants
- * passedCount - number of passed specs in the suite and its descendants
- * failedCount - number of failed specs in the suite and its descendants
- * messages - if defined, an array of message objects for failed specs, each of which contains:
- * spec - the name of the failing spec
- * message - the error message for that spec's failure
- * perf - if defined, an array of perf objects for any specs that have perf data, each of which contains:
- * spec - the name of the spec with perf results
- * record - the performance record for that spec
- * The suites object also contains an All property that summarizes total counts (but not messages or perf)
- * across all suites.
- *
- * sortedNames - a sorted list of suite names (including all the keys in the suites object except All).
- *
- * @param {!jasmine.Runner} runner The Jasmine spec runner for which we're reporting results.
- * @param {Function} filter The filter being used to determine whether a given spec is run or not.
- */
- function TopLevelResults(runner, filter) {
- var self = this,
- totalSpecCount = 0;
-
- this.suites = {};
-
- function makeData(count) {
- return {
- specCount: count,
- passedCount: 0,
- failedCount: 0
- };
- }
-
- runner.topLevelSuites().forEach(function (suite) {
- var specCount = self._countSpecs(suite, filter);
- self.suites[suite.getFullName()] = makeData(specCount);
- totalSpecCount += specCount;
- });
-
- this.sortedNames = Object.keys(this.suites).sort(function (a, b) {
- a = a.toLowerCase();
- b = b.toLowerCase();
- if (a < b) {
- return -1;
- } else if (a > b) {
- return 1;
- }
- return 0;
- });
-
- this.suites.All = makeData(totalSpecCount);
- }
-
- /**
- * @private
- *
- * @param {!jasmine.Suite} suite
- * @param {Function} filter
- * @return {Number} count The number of specs in the given suite (and its descendants) that match the filter.
- */
- TopLevelResults.prototype._countSpecs = function (suite, filter) {
- var count = 0,
- self = this;
-
- // count specs attached directly to this suite
- suite.specs().forEach(function (spec) {
- if (!filter || filter(spec)) {
- count++;
- }
- });
-
- // recursively count child suites
- suite.suites().forEach(function (child) {
- count += self._countSpecs(child, filter);
- });
-
- return count;
- };
-
- /**
- * Returns the name of the top-level suite containing the given spec.
- * @param {!jasmine.Spec} spec
- * @return {string} the top level suite name
- */
- TopLevelResults.prototype.getTopLevelSuiteName = function (spec) {
- var topLevelSuite = spec.suite;
-
- while (topLevelSuite.parentSuite) {
- topLevelSuite = topLevelSuite.parentSuite;
- }
-
- return topLevelSuite.getFullName();
- };
-
- /**
- * Adds the passed/failed counts and failure messages for the given spec to the data for its top level suite,
- * and updates the total counts on the All record.
- * @param {!jasmine.Spec} spec The spec to record
- * @param {Object} results Jasmine result object for that spec
- */
- TopLevelResults.prototype.addSpecResults = function (spec, results) {
- var suiteData = this.suites[this.getTopLevelSuiteName(spec)],
- allData = this.suites.All;
- if (results.passed()) {
- suiteData.passedCount++;
- allData.passedCount++;
- } else {
- suiteData.failedCount++;
- allData.failedCount++;
- }
-
- results.getItems().forEach(function (item) {
- var message = SpecRunnerUtils.getResultMessage(item);
- if (message) {
- suiteData.messages = suiteData.messages || [];
- suiteData.messages.push({
- spec: spec.getFullName(),
- message: message
- });
- }
- });
- };
-
- /**
- * Adds the given perf data for the given spec to the data for its top level suite.
- * @param {!jasmine.Spec} spec The spec to record
- * @param {Object} results The performance record for that spec
- */
- TopLevelResults.prototype.addSpecPerf = function (spec, results) {
- var suiteData = this.suites[this.getTopLevelSuiteName(spec)];
- suiteData.perf = suiteData.perf || [];
- suiteData.perf.push({
- spec: spec.getFullName(),
- record: results
- });
- };
-
- /**
- * Returns a JSON string for the list of suites (including the "All" record).
- * @return {string} the JSON string
- */
- TopLevelResults.prototype.toJSON = function () {
- return JSON.stringify(this.suites, null, " ");
- };
-
- exports.TopLevelResults = TopLevelResults;
-});
View
432 test/UnitTestReporter.js
@@ -0,0 +1,432 @@
+/*
+ * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50, forin: true */
+/*global $, define, brackets */
+
+/**
+ * A Jasmine reporter that summarizes test results data:
+ * - summarizes the results for each top-level suite (instead of flattening out all suites)
+ * - counts the number of passed/failed specs instead of counting each expect()
+ * - tracks performance data for tests that want to log it
+ * and rebroadcasts the summarized results to the reporter view, as well as serializing the data
+ * to JSON.
+ */
+
+define(function (require, exports, module) {
+ "use strict";
+
+ var UrlParams = require("utils/UrlParams").UrlParams,
+ SpecRunnerUtils = require("spec/SpecRunnerUtils"),
+ Global = require("utils/Global"),
+ BuildInfoUtils = require("utils/BuildInfoUtils");
+
+ var activeReporter;
+
+ /**
+ * @constructor
+ * Creates a UnitTestReporter object. This has a number public properties:
+ *
+ * suites - an object with entries for each top-level suite; each value is an object containing:
+ * name - the full name of the suite
+ * specCount - number of specs in the suite and its descendants
+ * passedCount - number of passed specs in the suite and its descendants
+ * failedCount - number of failed specs in the suite and its descendants
+ * specs - an array of results for each spec; each result is an object containing:
+ * name - the full name of the spec
+ * passed - true if the spec passed, false otherwise
+ * messages - if defined, an array of message objects for the failed spec
+ * perf - if defined, the performance record for the spec
+ *
+ * activeSuite - the suite that was run, or All for all suites
+ * passed - true if all specs passed, false otherwise
+ * sortedNames - a sorted list of suite names (including all the keys in the suites object except All).
+ * activeSuite - the suite currently selected in the URL params, or null if all are being run
+ * activeSpecCount - the number of specs that will actually be run given the current filter
+ * activeSpecCompleteCount - the number of specs that have been run so far
+ * totalSpecCount - the total number of specs (ignoring filter)
+ * totalPassedCount - the total number of specs passed across all suites
+ * totalFailedCount - the total number of specs failed across all suites
+ *
+ * runInfo - an object containing info about the current run:
+ * app - name of the app
+ * version - version number
+ * branch - branch the current build is running on
+ * sha - sha of the current build
+ * platform - platform of the current run
+ * startTime - time the run was started
+ * endTime - time the run finished
+ *
+ * @param {!Object} env The Jasmine environment we're running in.
+ * @param {Function} filter The filter being used to determine whether a given spec is run or not.
+ */
+ function UnitTestReporter(env, filter) {
+ var self = this,
+ params = new UrlParams();
+
+ params.parse();
+ this.activeSuite = params.get("spec");
+
+ this.runInfo = {
+ app: brackets.metadata.name,
+ version: brackets.metadata.version,
+ platform: brackets.platform
+ };
+ BuildInfoUtils.getBracketsSHA().done(function (branch, sha) {
+ self.runInfo.branch = branch;
+ self.runInfo.sha = sha;
+ });
+
+ // _topLevelFilter is applied first - selects Performance vs. Unit test suites
+ this._topLevelFilter = filter;
+
+ // Jasmine's runner uses the specFilter to choose which tests to run.
+ // If you selected an option other than "All" this will be a subset of all tests loaded.
+ env.specFilter = this._createSpecFilter(this.activeSuite);
+
+ this.suites = {};
+ this.passed = false;
+
+ this.totalSpecCount = 0;
+ this.totalPassedCount = 0;
+ this.totalFailedCount = 0;
+ env.currentRunner().topLevelSuites().forEach(function (suite) {
+ var specCount = self._countSpecs(suite, filter);
+ self.suites[suite.getFullName()] = {
+ id: suite.id,
+ name: suite.getFullName(),
+ specCount: specCount,
+ passedCount: 0,
+ failedCount: 0,
+ specs: []
+ };
+ self.totalSpecCount += specCount;
+ });
+
+ this.sortedNames = Object.keys(this.suites).sort(function (a, b) {
+ a = a.toLowerCase();
+ b = b.toLowerCase();
+ if (a < b) {
+ return -1;
+ } else if (a > b) {
+ return 1;
+ }
+ return 0;
+ });
+
+ this.activeSpecCount = 0;
+ this.activeSpecCompleteCount = 0;
+
+ env.currentRunner().specs().forEach(function (spec, index) {
+ if (env.specFilter(spec)) {
+ self.activeSpecCount++;
+ }
+ });
+ }
+
+ /**
+ * @private
+ * Filters specs by full name. Applies _topLevelFilter first before checking
+ * for a matching starting substring.
+ */
+ UnitTestReporter.prototype._createSpecFilter = function (filterString) {
+ var self = this;
+
+ return function (spec) {
+ // filterString is undefined when no top-level suite is active (e.g. "All", "HTMLUtils", etc.)
+ // When undefined, all specs fail this filter and no tests are ran. This is by design.
+ // This setup allows the SpecRunner to load initially without automatically running all tests.
+ if (filterString === undefined) {
+ return false;
+ }
+
+ if (!self._topLevelFilter(spec)) {
+ return false;
+ }
+
+ if (filterString === "All") {
+ return true;
+ }
+
+ if (spec.getFullName() === filterString) {
+ return true;
+ }
+
+ // spec.getFullName() concatenates the names of all containing describe()s. We want to filter
+ // on just the outermost suite's name (i.e., the item that was selected in the spec list UI)
+ // to avoid ambiguity when suite names share the same prefix.
+ var topLevelSuite = spec.suite;
+ while (topLevelSuite.parentSuite) {
+ topLevelSuite = topLevelSuite.parentSuite;
+ }
+
+ return topLevelSuite.description === filterString;
+ };
+ };
+
+ /**
+ * @private
+ *
+ * @param {!jasmine.Suite} suite
+ * @param {Function} filter
+ * @return {Number} count The number of specs in the given suite (and its descendants) that match the filter.
+ */
+ UnitTestReporter.prototype._countSpecs = function (suite, filter) {
+ var count = 0,
+ self = this;
+
+ // count specs attached directly to this suite
+ suite.specs().forEach(function (spec) {
+ if (!filter || filter(spec)) {
+ count++;
+ }
+ });
+
+ // recursively count child suites
+ suite.suites().forEach(function (child) {
+ count += self._countSpecs(child, filter);
+ });
+
+ return count;
+ };
+
+ /**
+ * Returns the name of the top-level suite containing the given spec.
+ * @param {!jasmine.Spec} spec
+ * @return {string} the top level suite name
+ */
+ UnitTestReporter.prototype.getTopLevelSuiteName = function (spec) {
+ var topLevelSuite = spec.suite;
+
+ while (topLevelSuite.parentSuite) {
+ topLevelSuite = topLevelSuite.parentSuite;
+ }
+
+ return topLevelSuite.getFullName();
+ };
+
+ /**
+ * @private
+ * Adds the passed/failed counts and failure messages for the given spec to the data for its top level suite,
+ * and updates the total counts on the All record.
+ * @param {!jasmine.Spec} spec The spec to record
+ * @param {Object} results Jasmine result object for that spec
+ * @return {Object} the spec data for the given spec, listing whether it passed and any
+ * messages/perf data
+ */
+ UnitTestReporter.prototype._addSpecResults = function (spec, results, perfRecord) {
+ var suiteData = this.suites[this.getTopLevelSuiteName(spec)],
+ specData = {
+ name: spec.getFullName(),
+ description: spec.description,
+ passed: results.passed()
+ };
+
+ this.activeSpecCompleteCount++;
+
+ if (specData.passed) {
+ suiteData.passedCount++;
+ this.totalPassedCount++;
+ } else {
+ suiteData.failedCount++;
+ this.totalFailedCount++;
+ }
+
+ results.getItems().forEach(function (item) {
+ var message = SpecRunnerUtils.getResultMessage(item);
+ if (message) {
+ specData.messages = specData.messages || [];
+ specData.messages.push(message);
+ }
+ });
+
+ if (perfRecord && perfRecord.length) {
+ specData.perf = perfRecord;
+ }
+
+ suiteData.specs.push(specData);
+ return specData;
+ };
+
+ /**
+ * Returns a JSON string containing all our public data. See the constructor
+ * docs for a list.
+ * @return {string} the JSON string
+ */
+ UnitTestReporter.prototype.toJSON = function () {
+ var data = {}, prop;
+ for (prop in this) {
+ if (this.hasOwnProperty(prop) && prop.charAt(0) !== "_") {
+ data[prop] = this[prop];
+ }
+ }
+ return JSON.stringify(data, null, " ");
+ };
+
+ // Handlers for Jasmine callback functions
+
+ UnitTestReporter.prototype.reportRunnerStarting = function (runner) {
+ activeReporter = this;
+ this.runInfo.startTime = new Date().toString();
+ $(this).triggerHandler("runnerStart", [this]);
+ };
+
+ UnitTestReporter.prototype.reportRunnerResults = function (runner) {
+ this.passed = runner.results().passed();
+ this.runInfo.endTime = new Date().toString();
+ $(this).triggerHandler("runnerEnd", [this]);
+ activeReporter = null;
+ };
+
+ UnitTestReporter.prototype.reportSuiteResults = function (suite) {
+ if (suite.parentSuite === null) {
+ $(this).triggerHandler("suiteEnd", [this, this.suites[suite.getFullName()]]);
+ }
+ };
+
+ /**
+ * @private
+ * @param {!Object} spec the Jasmine spec to find the category for
+ * @return {string} the category for the given spec
+ */
+ UnitTestReporter.prototype._getCategory = function (spec) {
+ if (spec.category) {
+ return spec.category;
+ } else {
+ var suite = spec.suite;
+ while (suite) {
+ if (suite.category) {
+ return suite.category;
+ }
+ suite = suite.parentSuite;
+ }
+ }
+ };
+
+ UnitTestReporter.prototype.reportSpecStarting = function (spec) {
+ if (this._getCategory(spec) === "performance") {
+ this._currentPerfRecord = [];
+ }
+ $(this).triggerHandler("specStart", [this, spec.getFullName()]);
+ };
+
+ UnitTestReporter.prototype.reportSpecResults = function (spec) {
+ if (!spec.results().skipped) {
+ var specData = this._addSpecResults(spec, spec.results(), this._currentPerfRecord);
+ $(this).triggerHandler("specEnd", [this, specData, this.suites[this.getTopLevelSuiteName(spec)]]);
+ }
+ this._currentPerfRecord = null;
+ };
+
+ // Performance tracking
+
+ UnitTestReporter.prototype._getTestWindowPerf = function () {
+ return SpecRunnerUtils.getTestWindow().brackets.test.PerfUtils;
+ };
+
+ UnitTestReporter.prototype._logTestWindowMeasurement = function (measureInfo) {
+ var value,
+ printName = measureInfo.measure.name || measureInfo.name,
+ record = {},
+ self = this;
+
+ if (measureInfo.measure instanceof RegExp) {
+ value = this._currentPerfUtils.searchData(measureInfo.measure);
+ } else {
+ value = this._currentPerfUtils.getData(measureInfo.measure.id);
+ }
+
+ if (value === undefined) {
+ value = "(None)";
+ }
+
+ if (measureInfo.measure.name && measureInfo.name) {
+ printName = measureInfo.measure.name + " - " + measureInfo.name;
+ }
+
+ if (measureInfo.operation === "sum") {
+ if (Array.isArray(value)) {
+ value = value.reduce(function (a, b) { return a + b; });
+ }
+
+ printName = "Sum of all " + printName;
+ }
+
+ record.name = printName;
+ record.value = value;
+
+ if (measureInfo.children) {
+ record.children = [];
+ measureInfo.children.forEach(function (child) {
+ record.children.push(self._logTestWindowMeasurement(child));
+ });
+ }
+
+ return record;
+ };
+
+ /**
+ * Records a performance measurement from the test window for the current running spec.
+ * @param {!(PerfMeasurement|string)} measure A PerfMeasurement or string key to query PerfUtils for metrics.
+ * @param {string} name An optional name or description to print with the measurement name
+ * @param {string} operation An optional operation to perform on the measurement data. Currently supports sum.
+ */
+ UnitTestReporter.prototype.logTestWindow = function (measures, name, operation) {
+ var self = this;
+
+ if (!this._currentPerfRecord) {
+ return;
+ }
+
+ this._currentPerfUtils = this._getTestWindowPerf();
+
+ if (!Array.isArray(measures)) {
+ measures = [{measure: measures, name: name, operation: operation}];
+ }
+
+ measures.forEach(function (measure) {
+ self._currentPerfRecord.push(self._logTestWindowMeasurement(measure));
+ });
+
+ this._currentPerfUtils = null;
+ };
+
+ /**
+ * Clears the current set of performance measurements.
+ */
+ UnitTestReporter.prototype.clearTestWindow = function () {
+ this._getTestWindowPerf().clear();
+ };
+
+ /**
+ * @return The active unit test reporter, or null if no unit test is running.
+ */
+ function getActiveReporter() {
+ return activeReporter;
+ }
+
+ // Exports
+
+ exports.UnitTestReporter = UnitTestReporter;
+ exports.getActiveReporter = getActiveReporter;
+});
View
7 test/perf/Performance-test.js
@@ -37,7 +37,7 @@ define(function (require, exports, module) {
JSLintUtils, // loaded from brackets.test
DocumentManager, // loaded from brackets.test
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
- PerformanceReporter = require("perf/PerformanceReporter");
+ UnitTestReporter = require("test/UnitTestReporter");
var jsLintPrevSetting;
@@ -61,8 +61,9 @@ define(function (require, exports, module) {
});
runs(function () {
- PerformanceReporter.logTestWindow(/Open File:\t,*/, path);
- PerformanceReporter.clearTestWindow();
+ var reporter = UnitTestReporter.getActiveReporter();
+ reporter.logTestWindow(/Open File:\t,*/, path);
+ reporter.clearTestWindow();
});
}
View
186 test/perf/PerformanceReporter.js
@@ -1,186 +0,0 @@
-/*
- * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- */
-
-/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
-/*global define, $ */
-
-define(function (require, exports, module) {
- 'use strict';
-
- var SpecRunnerUtils = require("spec/SpecRunnerUtils");
-
- var records = {},
- currentSpec = null,
- currentPerfUtils;
-
- function _getTestWindowPerf() {
- return SpecRunnerUtils.getTestWindow().brackets.test.PerfUtils;
- }
-
- function _logTestWindowMeasurement(measureInfo) {
- 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.measure.name && measureInfo.name) {
- printName = measureInfo.measure.name + " - " + measureInfo.name;
- }
-
- if (measureInfo.operation === "sum") {
- if (Array.isArray(value)) {
- value = value.reduce(function (a, b) { return a + b; });
- }
-
- printName = "Sum of all " + printName;
- }
-
- record.name = printName;
- record.value = value;
-
- if (measureInfo.children) {
- record.children = [];
- measureInfo.children.forEach(function (child) {
- record.children.push(_logTestWindowMeasurement(child));
- });
- }
-
- return record;
- }
-
- /**
- * Records a performance measurement from the test window for the current running spec.
- * @param {!(PerfMeasurement|string)} measure A PerfMeasurement or string key to query PerfUtils for metrics.
- * @param {string} name An optional name or description to print with the measurement name
- * @param {string} operation An optional operation to perform on the measurement data. Currently supports sum.
- */
- function logTestWindow(measures, name, operation) {
- if (!currentSpec) {
- return;
- }
-
- currentPerfUtils = _getTestWindowPerf();
-
- if (!Array.isArray(measures)) {
- measures = [{measure: measures, name: name, operation: operation}];
- }
-
- measures.forEach(function (measure) {
- records[currentSpec].push(_logTestWindowMeasurement(measure));
- });
-
- currentPerfUtils = null;
- }
-
- function clearTestWindow() {
- _getTestWindowPerf().clear();
- }
-
- // a minimal reporter implementation to listen for completion
- function PerformanceReporter(topLevelResults) {
- this._topLevelResults = topLevelResults;
- }
-
- PerformanceReporter.prototype.reportSpecStarting = function (spec) {
- currentSpec = spec;
- records[spec] = [];
- };
-
- function _createRows(record, level) {
- var rows = [],
- $row,
- indent = "",
- i;
-
- level = (level || 0);
-
- for (i = 0; i < level; i++) {
- indent = indent.concat("&nbsp;&nbsp;&nbsp;");
- }
-
- if (level > 0) {
- indent = indent.concat("•&nbsp;");
- } else if (record.children) {
- indent = "»&nbsp;".concat(indent);
- }
-
- $row = $("<tr/>");
- $row.append($("<td>" + indent + record.name + "</td><td>" + record.value + "</td>"));
-
- rows.push($row);
-
- if (record.children) {
- level++;
- record.children.forEach(function (child) {
- Array.prototype.push.apply(rows, _createRows(child, level));
- });
- }
-
- return rows;
- }
-
- PerformanceReporter.prototype.reportSpecResults = function (spec) {
- if (spec.results().skipped || (records[spec] && records[spec].length === 0)) {
- return;
- }
-
- var $container = $("#results-container");
-
- // add spec name
- var $specLink = $('<a href="?spec=' + encodeURIComponent(spec.getFullName()) + '"/>').text(spec.getFullName());
- $container.append($('<div class="alert alert-info"/>').append($specLink));
-
- // add table
- var $table = $('<table class="table table-striped table-bordered table-condensed"><thead><tr><th>Measurement</th><th>Value</th></tr></thead></table>'),
- $tbody = $table.append($('<tbody/>')),
- rows,
- specRecords = records[spec];
-
- $container.append($table);
-
- specRecords.forEach(function (record) {
- rows = _createRows(record);
-
- rows.forEach(function (row) {
- $tbody.append(row);
- });
- });
-
- this._topLevelResults.addSpecPerf(spec, records[spec]);
-
- delete records[spec];
- };
-
- exports.PerformanceReporter = PerformanceReporter;
- exports.logTestWindow = logTestWindow;
- exports.clearTestWindow = clearTestWindow;
-});
Please sign in to comment.
Something went wrong with that request. Please try again.