aboutsummaryrefslogtreecommitdiffstats
path: root/src/scenario/HtmlUI.js
diff options
context:
space:
mode:
authorElliott Sprehn2010-10-24 14:14:45 -0700
committerIgor Minar2010-10-26 15:17:57 -0700
commit40d7e66f408eaaa66efd8d7934ab2eb3324236a1 (patch)
treedaf88d70df9037416598307784eb83df93df4fed /src/scenario/HtmlUI.js
parent1d52349440d40de527b5d7f3849070f525c1b79b (diff)
downloadangular.js-40d7e66f408eaaa66efd8d7934ab2eb3324236a1.tar.bz2
Lots of bug fixes in the scenario runner and a bunch of new features.
- By default the runner now creates multiple output formats as it runs. Nodes are created in the DOM with ids: json, xml, and html. ex. $('#json').html() => json output of the runner ex. $('#xml').html() => json output of the runner $result is also an object tree result. The permitted formats are html,json,xml,object. If you don't want certain formats you can select specific ones with the new ng:scenario-output attribute on the script tag. <script src="angular-scenario.js" ng:scenario-output="xml,json"> - Added element(...).count() that returns the number of matching elements for the selector. - repeater(...).count() now returns 0 if no elements matched which can be used to check if a repeater is empty. - Added toBe() matcher that does strict equality with === - Implement iit and ddescribe. If iit() is used instead of it() then only that test will run. If ddescribe() is used instead of describe() them only it() statements inside of it will run. Several iit/ddescribe() blocks can be used to run isolated tests. - Implement new event based model for SpecRunner. You can now listen for events in the runner. This is useful for writing your own UI or connecting a remote process (ex. WebDriver). Event callbacks execute on the Runner instance. Events, if fired, will always be in the below order. All events always happen except for Failure and Error events which only happen in error conditions. Events: RunnerBegin SpecBegin(spec) StepBegin(spec, step) StepError(spec, step, error) StepFailure(spec, step, error) StepEnd(spec, step) SpecError(spec, step, error) SpecEnd(spec) RunnerEnd - Only allow the browser to repaint every 10 steps. Cuts 700ms off Firefox in benchmark, 200ms off Chrome. - Bug Fix: Manually navigate anchors on click since trigger wont work in Firefox.
Diffstat (limited to 'src/scenario/HtmlUI.js')
-rw-r--r--src/scenario/HtmlUI.js244
1 files changed, 0 insertions, 244 deletions
diff --git a/src/scenario/HtmlUI.js b/src/scenario/HtmlUI.js
deleted file mode 100644
index 78fe8c33..00000000
--- a/src/scenario/HtmlUI.js
+++ /dev/null
@@ -1,244 +0,0 @@
-/**
- * User Interface for the Scenario Runner.
- *
- * @param {Object} The jQuery UI object for the UI.
- */
-angular.scenario.ui.Html = function(context) {
- this.context = context;
- context.append(
- '<div id="header">' +
- ' <h1><span class="angular">&lt;angular/&gt;</span>: Scenario Test Runner</h1>' +
- ' <ul id="status-legend" class="status-display">' +
- ' <li class="status-error">0 Errors</li>' +
- ' <li class="status-failure">0 Failures</li>' +
- ' <li class="status-success">0 Passed</li>' +
- ' </ul>' +
- '</div>' +
- '<div id="specs">' +
- ' <div class="test-children"></div>' +
- '</div>'
- );
-};
-
-/**
- * The severity order of an error.
- */
-angular.scenario.ui.Html.SEVERITY = ['pending', 'success', 'failure', 'error'];
-
-/**
- * Adds a new spec to the UI.
- *
- * @param {Object} The spec object created by the Describe object.
- */
-angular.scenario.ui.Html.prototype.addSpec = function(spec) {
- var self = this;
- var specContext = this.findContext(spec.definition);
- specContext.find('> .tests').append(
- '<li class="status-pending test-it"></li>'
- );
- specContext = specContext.find('> .tests li:last');
- return new angular.scenario.ui.Html.Spec(specContext, spec.name,
- function(status) {
- status = self.context.find('#status-legend .status-' + status);
- var parts = status.text().split(' ');
- var value = (parts[0] * 1) + 1;
- status.text(value + ' ' + parts[1]);
- }
- );
-};
-
-/**
- * Finds the context of a spec block defined by the passed definition.
- *
- * @param {Object} The definition created by the Describe object.
- */
-angular.scenario.ui.Html.prototype.findContext = function(definition) {
- var self = this;
- var path = [];
- var currentContext = this.context.find('#specs');
- var currentDefinition = definition;
- while (currentDefinition && currentDefinition.name) {
- path.unshift(currentDefinition);
- currentDefinition = currentDefinition.parent;
- }
- angular.foreach(path, function(defn) {
- var id = 'describe-' + defn.id;
- if (!self.context.find('#' + id).length) {
- currentContext.find('> .test-children').append(
- '<div class="test-describe" id="' + id + '">' +
- ' <h2></h2>' +
- ' <div class="test-children"></div>' +
- ' <ul class="tests"></ul>' +
- '</div>'
- );
- self.context.find('#' + id).find('> h2').text('describe: ' + defn.name);
- }
- currentContext = self.context.find('#' + id);
- });
- return this.context.find('#describe-' + definition.id);
-};
-
-/**
- * A spec block in the UI.
- *
- * @param {Object} The jQuery object for the context of the spec.
- * @param {String} The name of the spec.
- * @param {Function} Callback function(status) to call when complete.
- */
-angular.scenario.ui.Html.Spec = function(context, name, doneFn) {
- this.status = 'pending';
- this.context = context;
- this.startTime = new Date().getTime();
- this.doneFn = doneFn;
- context.append(
- '<div class="test-info">' +
- ' <p class="test-title">' +
- ' <span class="timer-result"></span>' +
- ' <span class="test-name"></span>' +
- ' </p>' +
- '</div>' +
- '<div class="scrollpane">' +
- ' <ol class="test-actions">' +
- ' </ol>' +
- '</div>'
- );
- context.find('> .test-info').click(function() {
- var scrollpane = context.find('> .scrollpane');
- var actions = scrollpane.find('> .test-actions');
- var name = context.find('> .test-info .test-name');
- if (actions.find(':visible').length) {
- actions.hide();
- name.removeClass('open').addClass('closed');
- } else {
- actions.show();
- scrollpane.attr('scrollTop', scrollpane.attr('scrollHeight'));
- name.removeClass('closed').addClass('open');
- }
- });
- context.find('> .test-info .test-name').text('it ' + name);
-};
-
-/**
- * Adds a new Step to this spec and returns it.
- *
- * @param {String} The name of the step.
- * @param {Function} function() that returns a string with the file/line number
- * where the step was added from.
- */
-angular.scenario.ui.Html.Spec.prototype.addStep = function(name, location) {
- this.context.find('> .scrollpane .test-actions').append('<li class="status-pending"></li>');
- var stepContext = this.context.find('> .scrollpane .test-actions li:last');
- var self = this;
- return new angular.scenario.ui.Html.Step(stepContext, name, location, function(status) {
- if (indexOf(angular.scenario.ui.Html.SEVERITY, status) >
- indexOf(angular.scenario.ui.Html.SEVERITY, self.status)) {
- self.status = status;
- }
- var scrollpane = self.context.find('> .scrollpane');
- scrollpane.attr('scrollTop', scrollpane.attr('scrollHeight'));
- });
-};
-
-/**
- * Completes the spec and sets the timer value.
- */
-angular.scenario.ui.Html.Spec.prototype.complete = function() {
- this.context.removeClass('status-pending');
- var endTime = new Date().getTime();
- this.context.find("> .test-info .timer-result").
- text((endTime - this.startTime) + "ms");
- if (this.status === 'success') {
- this.context.find('> .test-info .test-name').addClass('closed');
- this.context.find('> .scrollpane .test-actions').hide();
- }
-};
-
-/**
- * Finishes the spec, possibly with an error.
- *
- * @param {Object} An optional error
- */
-angular.scenario.ui.Html.Spec.prototype.finish = function() {
- this.complete();
- this.context.addClass('status-' + this.status);
- this.doneFn(this.status);
-};
-
-/**
- * Finishes the spec, but with a Fatal Error.
- *
- * @param {Object} Required error
- */
-angular.scenario.ui.Html.Spec.prototype.error = function(error) {
- this.status = 'error';
- this.context.append('<pre></pre>');
- this.context.find('> pre').text(formatException(error));
- this.finish();
-};
-
-/**
- * A single step inside an it block (or a before/after function).
- *
- * @param {Object} The jQuery object for the context of the step.
- * @param {String} The name of the step.
- * @param {Function} function() that returns file/line number of step.
- * @param {Function} Callback function(status) to call when complete.
- */
-angular.scenario.ui.Html.Step = function(context, name, location, doneFn) {
- this.context = context;
- this.name = name;
- this.location = location;
- this.startTime = new Date().getTime();
- this.doneFn = doneFn;
- context.append(
- '<div class="timer-result"></div>' +
- '<div class="test-title"></div>'
- );
- context.find('> .test-title').text(name);
- var scrollpane = context.parents('.scrollpane');
- scrollpane.attr('scrollTop', scrollpane.attr('scrollHeight'));
-};
-
-/**
- * Completes the step and sets the timer value.
- */
-angular.scenario.ui.Html.Step.prototype.complete = function(error) {
- this.context.removeClass('status-pending');
- var endTime = new Date().getTime();
- this.context.find(".timer-result").
- text((endTime - this.startTime) + "ms");
- if (error) {
- if (!this.context.find('.test-title pre').length) {
- this.context.find('.test-title').append('<pre></pre>');
- }
- var message = _jQuery.trim(this.location() + '\n\n' + formatException(error));
- this.context.find('.test-title pre').text(message);
- }
-};
-
-/**
- * Finishes the step, possibly with an error.
- *
- * @param {Object} An optional error
- */
-angular.scenario.ui.Html.Step.prototype.finish = function(error) {
- this.complete(error);
- if (error) {
- this.context.addClass('status-failure');
- this.doneFn('failure');
- } else {
- this.context.addClass('status-success');
- this.doneFn('success');
- }
-};
-
-/**
- * Finishes the step, but with a Fatal Error.
- *
- * @param {Object} Required error
- */
-angular.scenario.ui.Html.Step.prototype.error = function(error) {
- this.complete(error);
- this.context.addClass('status-error');
- this.doneFn('error');
-};