Skip to content

Commit 70c3dc8

Browse files
author
Andres Ornelas
committed
expose e2e test results
1 parent b129a10 commit 70c3dc8

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/scenario/Runner.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ angular.scenario.Runner = function(scope, jQuery){
55
var self = scope.$scenario = this;
66
this.scope = scope;
77
this.jQuery = jQuery;
8+
this.scope.$testrun = {done: false, results: []};
89

910
var specs = this.specs = {};
1011
var path = [];
@@ -40,7 +41,7 @@ angular.scenario.Runner = function(scope, jQuery){
4041
self.currentSpec = null;
4142
};
4243
this.logger = function returnNoop(){
43-
return extend(returnNoop, {close:noop, fail:noop});;
44+
return extend(returnNoop, {close:noop, fail:noop});
4445
};
4546
};
4647

@@ -99,6 +100,8 @@ angular.scenario.Runner.prototype = {
99100
var next = specNames.shift();
100101
if(next) {
101102
self.execute(next, callback);
103+
} else {
104+
self.scope.$testrun.done = true;
102105
}
103106
};
104107
callback();
@@ -111,6 +114,7 @@ angular.scenario.Runner.prototype = {
111114
execute: function(name, callback) {
112115
var spec = this.specs[name],
113116
self = this,
117+
stepsDone = [],
114118
result = {
115119
passed: false,
116120
failed: false,
@@ -143,15 +147,23 @@ angular.scenario.Runner.prototype = {
143147
if (step) {
144148
spec.nextStepIndex ++;
145149
result.log = stepLogger('step', step.name);
150+
stepsDone.push(step.name);
146151
try {
147152
step.fn.call(specThis, next);
148153
} catch (e) {
149154
console.error(e);
150155
result.fail(e);
156+
self.scope.$testrun.results.push(
157+
{name: name, passed: false, error: e, steps: stepsDone});
151158
done();
152159
}
153160
} else {
154161
result.passed = !result.failed;
162+
self.scope.$testrun.results.push({
163+
name: name,
164+
passed: !result.failed,
165+
error: result.error,
166+
steps: stepsDone});
155167
done();
156168
}
157169
};

test/scenario/RunnerSpec.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,14 @@ describe('Runner', function(){
148148
it('should handle exceptions in a step', function(){
149149
$scenario.specs['spec'] = {
150150
steps: [
151+
{name: 'first step', fn: function(done) {
152+
done();
153+
}},
151154
{name:'error', fn:function(done) {
152155
throw "MyError";
156+
}},
157+
{name: 'should not execute', fn: function(done) {
158+
done();
153159
}}
154160
]
155161
};
@@ -160,12 +166,17 @@ describe('Runner', function(){
160166
expect(spec.result.failed).toEqual(true);
161167
expect(spec.result.finished).toEqual(true);
162168
expect(spec.result.error).toEqual("MyError");
169+
expect(scenario.$testrun.results).toEqual([{
170+
name: 'spec',
171+
passed: false,
172+
error: 'MyError',
173+
steps: ['first step', 'error']}]);
163174
});
164175
});
165176

166177
describe('run', function(){
167178
var next;
168-
it('should execute all specs', function(){
179+
beforeEach(function() {
169180
Describe('d1', function(){
170181
It('it1', function(){ $scenario.addStep('s1', logger('s1,')); });
171182
It('it2', function(){
@@ -177,13 +188,30 @@ describe('Runner', function(){
177188
It('it3', function(){ $scenario.addStep('s3', logger('s3,')); });
178189
It('it4', function(){ $scenario.addStep('s4', logger('s4,')); });
179190
});
180-
191+
});
192+
it('should execute all specs', function(){
181193
$scenario.run(body);
182194

183195
expect(log).toEqual('s1,s2,');
184196
next();
185197
expect(log).toEqual('s1,s2,s3,s4,');
186-
198+
});
199+
it('should publish done state and results as tests are run', function() {
200+
expect(scenario.$testrun.done).toBeFalsy();
201+
expect(scenario.$testrun.results).toEqual([]);
202+
$scenario.run(body);
203+
expect(scenario.$testrun.done).toBeFalsy();
204+
expect(scenario.$testrun.results).toEqual([
205+
{name: 'd1: it it1', passed: true, steps: ['s1']}
206+
]);
207+
next();
208+
expect(scenario.$testrun.done).toBeTruthy();
209+
expect(scenario.$testrun.results).toEqual([
210+
{name: 'd1: it it1', passed: true, steps: ['s1']},
211+
{name: 'd1: it it2', passed: true, steps: ['s2', 's2.2']},
212+
{name: 'd2: it it3', passed: true, steps: ['s3']},
213+
{name: 'd2: it it4', passed: true, steps: ['s4']}
214+
]);
187215
});
188216
});
189217

0 commit comments

Comments
 (0)