forked from browserstack/browserstack-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.js
More file actions
228 lines (218 loc) · 7.63 KB
/
Copy pathrunner.js
File metadata and controls
228 lines (218 loc) · 7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
'use strict';
global.logLevel = 'silent';
var assert = require('assert'),
sinon = require('sinon'),
path = require('path'),
http = require('http'),
browserstackRunner = require('../../bin/cli.js'),
Tunnel = require('../../lib/local.js').Tunnel;
var getBaseConfig = function() {
return {
username: 'BROWSERSTACK_USER',
key: 'BROWSERSTACK_KEY',
test_framework: 'qunit',
test_path: path.resolve(__dirname, 'resources', 'qunit_sample.html'),
build: 'BrowserStack Runner Behaviour Tests',
browsers: [ {
browser: 'firefox',
browser_version: '47.0',
os: 'Windows',
os_version: '7'
}, {
browser: 'chrome',
browser_version: '52.0',
os: 'Windows',
os_version: '7'
}, {
browser: 'iphone',
browser_version: '',
device: 'iPhone SE',
os: 'ios',
os_version: '11.2',
real_mobile: true
} ]
}
};
describe('Config Assertions', function() {
this.timeout(0);
it('should run normally with valid config', function(done) {
browserstackRunner.run(getBaseConfig(), function(err) {
assert.equal(err, null);
done();
});
});
it('should have an error if test path is not valid', function(done) {
var config = getBaseConfig();
config.test_path = 'Some invalid path';
browserstackRunner.run(config, function(err) {
assert.equal(err.message, 'Test path: ' + config.test_path + ' is invalid.');
done();
});
});
it('should have an error if config does not have a browsers key', function(done) {
var config = getBaseConfig();
delete(config.browsers);
browserstackRunner.run(config, function(err) {
assert.equal(err.message, 'Configuration parameter browsers is required.');
done();
});
});
it('should have an error if config does not have a test_path key', function(done) {
var config = getBaseConfig();
delete(config.test_path);
browserstackRunner.run(config, function(err) {
assert.equal(err.message, 'Configuration parameter test_path is required.');
done();
});
});
describe('Check Behaviour with invalid username or key', function() {
var sandbox;
beforeEach(function() {
sandbox = sinon.sandbox.create();
sandbox.stub(process, 'env', {});
});
it('should have an error if config does not have a username', function(done) {
var config = getBaseConfig();
delete(config.username);
browserstackRunner.run(config, function(err) {
assert.equal(err.message, 'Configuration parameter username is required.');
done();
});
});
it('should have an error if config does not have a key', function(done) {
var config = getBaseConfig();
delete(config.key);
browserstackRunner.run(config, function(err) {
assert.equal(err.message, 'Configuration parameter key is required.');
done();
});
});
afterEach(function() {
sandbox.restore();
});
});
});
describe('Pass/Fail reporting', function() {
this.timeout(0);
it('report keys should have browser names', function(done) {
var config = getBaseConfig();
browserstackRunner.run(config, function(err, reports) {
var shouldBePresentBrowsers = [ 'Windows 7, Chrome 52.0', 'Windows 7, Firefox 47.0', 'ios 11.2, Iphone '];
assert.equal(err, null);
reports.forEach(function(report) {
var numMatched = 0;
shouldBePresentBrowsers.forEach(function(browser) {
if(browser === report.browser) {
numMatched++;
}
});
if(numMatched != 1) {
done(new Error('Report didnt match the shouldBePresentBrowsers for browser: ' + report.browser + ' numMatched: ' + numMatched));
} else {
var removeIndex = shouldBePresentBrowsers.indexOf(report.browser);
shouldBePresentBrowsers = shouldBePresentBrowsers.slice(0, removeIndex).concat(shouldBePresentBrowsers.slice(removeIndex + 1));
}
});
if(shouldBePresentBrowsers.length != 0) {
done(new Error('Browsers not Present in Report: ' + JSON.stringify(shouldBePresentBrowsers)));
}
done();
});
});
it('report keys should have suites and tests', function(done) {
var config = getBaseConfig();
browserstackRunner.run(config, function(err, reports) {
assert.equal(err, null);
reports.forEach(function(report) {
assert.notEqual(report.tests, null);
assert.notEqual(report.suites, null);
});
done();
});
});
describe('Test Tests', function() {
it('report should have proper number of tests', function(done) {
var config = getBaseConfig();
browserstackRunner.run(config, function(err, reports) {
assert.equal(err, null);
reports.forEach(function(report) {
assert.equal(report.tests.length, 3);
});
done();
});
});
it('Each test should have specific keys', function(done) {
var config = getBaseConfig();
browserstackRunner.run(config, function(err, reports) {
assert.equal(err, null);
reports.forEach(function(report) {
Object.keys(report.tests).forEach(function(reportKey) {
[ 'name', 'suiteName', 'status', 'runtime', 'errors' ].forEach(function(key) {
assert.notEqual(report.tests[reportKey][key], null);
});
report.tests[reportKey].assertions.forEach(function(assertion) {
[ 'passed', 'actual', 'expected', 'message' ].forEach(function(key) {
assert.notEqual(assertion[key], null);
});
});
});
});
done();
});
});
it('Each test should have message in assertions', function(done) {
var config = getBaseConfig();
browserstackRunner.run(config, function(err, reports) {
assert.equal(err, null);
reports.forEach(function(report) {
Object.keys(report.tests).forEach(function(reportKey) {
report.tests[reportKey].assertions.forEach(function(assertion) {
assert.notEqual(assertion['message'].match(/\d+ is .*an .* number/), null);
});
});
});
done();
});
});
});
describe('Test Suites', function() {
it('report should have Suite of tests', function(done) {
var config = getBaseConfig();
browserstackRunner.run(config, function(err, reports) {
assert.equal(err, null);
reports.forEach(function(report) {
assert.notEqual(report.suites, null);
});
done();
});
});
it('Each Suite should have specific keys', function(done) {
var config = getBaseConfig();
browserstackRunner.run(config, function(err, reports) {
assert.equal(err, null);
reports.forEach(function(report) {
[ 'childSuites', 'tests', 'runtime', 'status', 'testCounts' ].forEach(function(key) {
assert.notEqual(report.suites[key], null);
});
[ 'total', 'passed', 'failed', 'skipped' ].forEach(function(key) {
assert.notEqual(report.suites.testCounts[key], null);
});
});
done();
});
});
it('Suites should have correct passed/failed count', function(done) {
var config = getBaseConfig();
browserstackRunner.run(config, function(err, reports) {
assert.equal(err, null);
reports.forEach(function(report) {
assert.equal(report.suites.testCounts['total'], 3);
assert.equal(report.suites.testCounts['passed'], 1);
assert.equal(report.suites.testCounts['failed'], 2);
assert.equal(report.suites.testCounts['skipped'], 0);
});
done();
});
});
});
});