Skip to content

Commit d1cac58

Browse files
committed
WebDriver reporter updates
- Fix call to non-existent _send method - Add unit tests
1 parent 03e78c0 commit d1cac58

2 files changed

Lines changed: 125 additions & 17 deletions

File tree

lib/reporters/WebDriver.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
define([
2-
'dojo/aspect',
3-
'dojo/topic',
4-
'dojo/request',
5-
'dojo/Promise',
62
'../util',
7-
'../sendData',
3+
// Conditional load sendData for testability
4+
'dojo/has!host-browser?../sendData',
85
'require'
9-
], function (aspect, topic, request, Promise, util, sendData, require) {
10-
function scroll() {
11-
window.scrollTo(0, document.documentElement.scrollHeight || document.body.scrollHeight);
12-
}
13-
6+
], function (
7+
util,
8+
sendData,
9+
require
10+
) {
1411
function WebDriver(config) {
1512
config = config || {};
1613

@@ -33,7 +30,7 @@ define([
3330
$others: function (name) {
3431
// never send coverage events; coverage is handled explicitly by Proxy
3532
if (name !== 'coverage' && name !== 'run') {
36-
return this._send(Array.prototype.slice.call(arguments, 0));
33+
return this._sendEvent(name, Array.prototype.slice.call(arguments, 1));
3734
}
3835
},
3936

@@ -72,7 +69,7 @@ define([
7269
oldSuiteNode.appendChild(outerSuiteNode);
7370
}
7471

75-
scroll();
72+
this._scroll();
7673
}
7774

7875
return this._sendEvent('suiteStart', arguments);
@@ -86,7 +83,7 @@ define([
8683
var errorNode = document.createElement('pre');
8784
errorNode.appendChild(document.createTextNode(util.getErrorMessage(error)));
8885
this.suiteNode.appendChild(errorNode);
89-
scroll();
86+
this._scroll();
9087
}
9188

9289
return this._sendEvent('suiteError', arguments);
@@ -97,7 +94,7 @@ define([
9794
this.testNode = document.createElement('li');
9895
this.testNode.appendChild(document.createTextNode(test.name));
9996
this.suiteNode.appendChild(this.testNode);
100-
scroll();
97+
this._scroll();
10198
}
10299

103100
return this._sendEvent('testStart', arguments);
@@ -107,7 +104,7 @@ define([
107104
if (this.writeHtml) {
108105
this.testNode.appendChild(document.createTextNode(' passed (' + test.timeElapsed + 'ms)'));
109106
this.testNode.style.color = 'green';
110-
scroll();
107+
this._scroll();
111108
}
112109

113110
return this._sendEvent('testPass', arguments);
@@ -120,7 +117,7 @@ define([
120117
(test.skipped ? ' (' + test.skipped + ')' : '')));
121118
testNode.style.color = 'gray';
122119
this.suiteNode.appendChild(testNode);
123-
scroll();
120+
this._scroll();
124121
}
125122

126123
return this._sendEvent('testSkip', arguments);
@@ -134,7 +131,7 @@ define([
134131
var errorNode = document.createElement('pre');
135132
errorNode.appendChild(document.createTextNode(util.getErrorMessage(test.error)));
136133
this.testNode.appendChild(errorNode);
137-
scroll();
134+
this._scroll();
138135
}
139136

140137
return this._sendEvent('testFail', arguments);
@@ -148,6 +145,10 @@ define([
148145
if (shouldWait) {
149146
return promise;
150147
}
148+
},
149+
150+
_scroll: function () {
151+
window.scrollTo(0, document.documentElement.scrollHeight || document.body.scrollHeight);
151152
}
152153
};
153154

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
define([
2+
'intern!object',
3+
'intern/chai!assert',
4+
'../../../../lib/Suite',
5+
'../../../../lib/Test',
6+
'../../../../lib/reporters/WebDriver'
7+
], function (
8+
registerSuite,
9+
assert,
10+
Suite,
11+
Test,
12+
WebDriver
13+
) {
14+
var reporter;
15+
var messages;
16+
var documentAdded = false;
17+
18+
function messageTest(name, object) {
19+
if (reporter[name]) {
20+
reporter[name](object);
21+
}
22+
else {
23+
reporter.$others(name, object);
24+
}
25+
assert.lengthOf(messages, 1, 'expected a message to be sent');
26+
assert.strictEqual(messages[0].name, name, 'unexpected message name ' + messages[0].name);
27+
if (object) {
28+
assert.strictEqual(messages[0].args[0], object, 'unexpected message args');
29+
}
30+
}
31+
32+
function createSuiteMessageTest(name) {
33+
return function () {
34+
var suite = new Suite({ name: 'suite', parent: {} });
35+
return messageTest(name, suite);
36+
};
37+
}
38+
39+
function createTestMessageTest(name) {
40+
return function () {
41+
var test = new Test({ name: 'test', parent: {} });
42+
return messageTest(name, test);
43+
};
44+
}
45+
46+
function createMessageTest(name) {
47+
return function () {
48+
return messageTest(name);
49+
};
50+
}
51+
52+
registerSuite({
53+
name: 'intern/lib/reporters/WebDriver',
54+
55+
setup: function () {
56+
if (typeof document === 'undefined') {
57+
/* globals global */
58+
global.document = {};
59+
documentAdded = true;
60+
}
61+
},
62+
63+
beforeEach: function () {
64+
reporter = new WebDriver({
65+
writeHtml: false,
66+
internConfig: {
67+
sessionId: 'foo'
68+
}
69+
});
70+
messages = [];
71+
72+
reporter._sendEvent = function (name, args) {
73+
messages.push({
74+
name: name,
75+
args: args
76+
});
77+
};
78+
79+
reporter._scroll = function () {};
80+
},
81+
82+
afterEach: function () {
83+
messages = null;
84+
reporter = null;
85+
},
86+
87+
teardown: function () {
88+
if (documentAdded) {
89+
delete global.document;
90+
}
91+
},
92+
93+
suiteStart: createSuiteMessageTest('suiteStart'),
94+
suiteEnd: createSuiteMessageTest('suiteEnd'),
95+
suiteError: createSuiteMessageTest('suiteError'),
96+
97+
runStart: createMessageTest('runStart'),
98+
runEnd: createMessageTest('runEnd'),
99+
100+
testStart: createTestMessageTest('testStart'),
101+
testPass: createTestMessageTest('testPass'),
102+
testSkip: createTestMessageTest('testSkip'),
103+
testEnd: createTestMessageTest('testEnd'),
104+
testFail: createTestMessageTest('testFail')
105+
});
106+
});
107+

0 commit comments

Comments
 (0)