aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndres Ornelas2010-06-22 17:15:14 -0700
committerAndres Ornelas2010-06-22 17:15:14 -0700
commit70c3dc81665191cd065a5303e5e26639a0023a73 (patch)
tree72ba1be4006bc5191bd852284db026bcf2e702d9
parentb129a1094e6b42ed82c3ccecc2f40daaa0a6cb6a (diff)
downloadangular.js-70c3dc81665191cd065a5303e5e26639a0023a73.tar.bz2
expose e2e test results
-rw-r--r--src/scenario/Runner.js14
-rw-r--r--test/scenario/RunnerSpec.js34
2 files changed, 44 insertions, 4 deletions
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index 8e0cc909..13ba5af0 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -5,6 +5,7 @@ angular.scenario.Runner = function(scope, jQuery){
var self = scope.$scenario = this;
this.scope = scope;
this.jQuery = jQuery;
+ this.scope.$testrun = {done: false, results: []};
var specs = this.specs = {};
var path = [];
@@ -40,7 +41,7 @@ angular.scenario.Runner = function(scope, jQuery){
self.currentSpec = null;
};
this.logger = function returnNoop(){
- return extend(returnNoop, {close:noop, fail:noop});;
+ return extend(returnNoop, {close:noop, fail:noop});
};
};
@@ -99,6 +100,8 @@ angular.scenario.Runner.prototype = {
var next = specNames.shift();
if(next) {
self.execute(next, callback);
+ } else {
+ self.scope.$testrun.done = true;
}
};
callback();
@@ -111,6 +114,7 @@ angular.scenario.Runner.prototype = {
execute: function(name, callback) {
var spec = this.specs[name],
self = this,
+ stepsDone = [],
result = {
passed: false,
failed: false,
@@ -143,15 +147,23 @@ angular.scenario.Runner.prototype = {
if (step) {
spec.nextStepIndex ++;
result.log = stepLogger('step', step.name);
+ stepsDone.push(step.name);
try {
step.fn.call(specThis, next);
} catch (e) {
console.error(e);
result.fail(e);
+ self.scope.$testrun.results.push(
+ {name: name, passed: false, error: e, steps: stepsDone});
done();
}
} else {
result.passed = !result.failed;
+ self.scope.$testrun.results.push({
+ name: name,
+ passed: !result.failed,
+ error: result.error,
+ steps: stepsDone});
done();
}
};
diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js
index ca6e8eb2..5e05cd00 100644
--- a/test/scenario/RunnerSpec.js
+++ b/test/scenario/RunnerSpec.js
@@ -148,8 +148,14 @@ describe('Runner', function(){
it('should handle exceptions in a step', function(){
$scenario.specs['spec'] = {
steps: [
+ {name: 'first step', fn: function(done) {
+ done();
+ }},
{name:'error', fn:function(done) {
throw "MyError";
+ }},
+ {name: 'should not execute', fn: function(done) {
+ done();
}}
]
};
@@ -160,12 +166,17 @@ describe('Runner', function(){
expect(spec.result.failed).toEqual(true);
expect(spec.result.finished).toEqual(true);
expect(spec.result.error).toEqual("MyError");
+ expect(scenario.$testrun.results).toEqual([{
+ name: 'spec',
+ passed: false,
+ error: 'MyError',
+ steps: ['first step', 'error']}]);
});
});
describe('run', function(){
var next;
- it('should execute all specs', function(){
+ beforeEach(function() {
Describe('d1', function(){
It('it1', function(){ $scenario.addStep('s1', logger('s1,')); });
It('it2', function(){
@@ -177,13 +188,30 @@ describe('Runner', function(){
It('it3', function(){ $scenario.addStep('s3', logger('s3,')); });
It('it4', function(){ $scenario.addStep('s4', logger('s4,')); });
});
-
+ });
+ it('should execute all specs', function(){
$scenario.run(body);
expect(log).toEqual('s1,s2,');
next();
expect(log).toEqual('s1,s2,s3,s4,');
-
+ });
+ it('should publish done state and results as tests are run', function() {
+ expect(scenario.$testrun.done).toBeFalsy();
+ expect(scenario.$testrun.results).toEqual([]);
+ $scenario.run(body);
+ expect(scenario.$testrun.done).toBeFalsy();
+ expect(scenario.$testrun.results).toEqual([
+ {name: 'd1: it it1', passed: true, steps: ['s1']}
+ ]);
+ next();
+ expect(scenario.$testrun.done).toBeTruthy();
+ expect(scenario.$testrun.results).toEqual([
+ {name: 'd1: it it1', passed: true, steps: ['s1']},
+ {name: 'd1: it it2', passed: true, steps: ['s2', 's2.2']},
+ {name: 'd2: it it3', passed: true, steps: ['s3']},
+ {name: 'd2: it it4', passed: true, steps: ['s4']}
+ ]);
});
});