Skip to content

Commit f74129d

Browse files
committed
return object instead of stringified JSON
1 parent 1ce5fc5 commit f74129d

File tree

6 files changed

+70
-64
lines changed

6 files changed

+70
-64
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ node_modules
33
browserstack.json
44
browserstack-runner.pid
55
lib/BrowserStackLocal
6+
tests/jasmine
7+
tests/jasmine2
8+
tests/mocha
9+
tests/qunit

bin/cli.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,11 @@ var statusPoller = {
306306
}
307307

308308
logger.trace('[%s] worker.activityTimeout: all tests done', worker.id, config.status && 'with failures');
309-
callback(null, 'All Tests Done');
309+
if(server && server.report) {
310+
callback(null, server.report);
311+
} else {
312+
callback(null, {});
313+
}
310314
}
311315
} else {
312316
logger.trace('[%s] worker.activityTimeout: already ackd', worker.id);
@@ -332,7 +336,11 @@ var statusPoller = {
332336
}
333337

334338
logger.trace('[%s] worker.testActivityTimeout: all tests done', worker.id, config.status && 'with failures');
335-
callback(null, 'All Tests Done');
339+
if(server && server.report) {
340+
callback(null, server.report);
341+
} else {
342+
callback(null, {});
343+
}
336344
}
337345
} else {
338346
logger.trace('[%s] worker.testActivityTimeout: not ackd', worker.id);
@@ -374,7 +382,7 @@ function runTests(config, callback) {
374382
logger.trace('runTests: creating tunnel');
375383
tunnel = new Tunnel(config.key, serverPort, config.tunnelIdentifier, config, function (err) {
376384
if(err) {
377-
cleanUpAndExit(null, err, '{}', callback);
385+
cleanUpAndExit(null, err, {}, callback);
378386
} else {
379387
logger.trace('runTests: created tunnel');
380388

lib/local.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ var Tunnel = function Tunnel(key, port, uniqueIdentifier, config, callback) {
2424
if (stdout.indexOf('Error') >= 0 || error) {
2525
logger.debug('[%s] Tunnel launching failed', new Date());
2626
logger.debug(stdout);
27-
throw new Error('[%s] Tunnel launching failed', new Date());
27+
callback(new Error(new Date() + ': Tunnel launching failed'));
2828
}
2929
});
3030

3131
var data = '';
3232
var running = false;
33-
var runMatcher = 'You can now access your local server(s)';
33+
var runMatchers = [ 'You can now access your local server(s)', 'Press Ctrl-C to exit' ];
3434

3535
setTimeout(function() {
3636
if (!running) {
@@ -46,7 +46,7 @@ var Tunnel = function Tunnel(key, port, uniqueIdentifier, config, callback) {
4646

4747
data += _data;
4848

49-
if (data.indexOf(runMatcher) >= 0) {
49+
if (data.indexOf(runMatchers[0]) >= 0 && data.indexOf(runMatchers[1]) >= 0) {
5050
running = true;
5151
logger.debug('[%s] Tunnel launched', new Date());
5252
setTimeout(function(){

lib/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ exports.Server = function Server(bsClient, workers, config, callback) {
322322
}
323323

324324
logger.trace('[%s] _report: checkAndTerminateWorker: all tests done', worker.id, config.status && 'with failures');
325-
callback(null, JSON.stringify(report));
325+
callback(null, report);
326326
}
327327
});
328328
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"scripts": {
3434
"lint": "node_modules/.bin/jshint lib/*.js bin/ tests/*.js",
3535
"test-unit": "node_modules/.bin/mocha tests/unit",
36-
"test-behaviour": "node_modules/.bin/mocha tests/behaviour",
36+
"test-behaviour": "node_modules/.bin/mocha tests/behaviour -R spec",
3737
"test-ci": "npm run lint && npm run test-unit && npm run test-behaviour && TEST_MODE=all tests/external-tests.js",
3838
"test": "npm run lint && npm run test-unit && npm run test-behaviour && TEST_MODE=required tests/external-tests.js",
3939
"update-util": "webpack"

tests/behaviour/runner.js

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
'use strict';
22

3-
global.logLevel = "silent";
3+
global.logLevel = 'silent';
44

5-
let assert = require('assert'),
5+
var assert = require('assert'),
66
sinon = require('sinon'),
77
path = require('path'),
8-
browserstackRunner = require('../../bin/cli.js');
8+
http = require('http'),
9+
browserstackRunner = require('../../bin/cli.js'),
10+
Tunnel = require('../../lib/local.js').Tunnel;
911

10-
let getBaseConfig = function() {
12+
var getBaseConfig = function() {
1113
return {
1214
username: 'BROWSERSTACK_USER',
1315
key: 'BROWSERSTACK_KEY',
1416
test_framework: 'qunit',
1517
test_path: path.resolve(__dirname, 'resources', 'qunit_sample.html'),
16-
build: "BrowserStack Runner Behaviour Tests",
18+
build: 'BrowserStack Runner Behaviour Tests',
1719
browsers: [ {
1820
browser: 'firefox',
1921
browser_version: '47.0',
@@ -38,26 +40,26 @@ describe('Config Assertions', function() {
3840
});
3941
});
4042
it('should have an error if test path is not valid', function(done) {
41-
let config = getBaseConfig();
42-
config.test_path = "Some invalid path";
43+
var config = getBaseConfig();
44+
config.test_path = 'Some invalid path';
4345
browserstackRunner.run(config, function(err) {
44-
assert.equal(err.message, "Test path: " + config.test_path + " is invalid.");
46+
assert.equal(err.message, 'Test path: ' + config.test_path + ' is invalid.');
4547
done();
4648
});
4749
});
4850
it('should have an error if config does not have a browsers key', function(done) {
49-
let config = getBaseConfig();
51+
var config = getBaseConfig();
5052
delete(config.browsers);
5153
browserstackRunner.run(config, function(err) {
52-
assert.equal(err.message, "Configuration parameter browsers is required.");
54+
assert.equal(err.message, 'Configuration parameter browsers is required.');
5355
done();
5456
});
5557
});
5658
it('should have an error if config does not have a test_path key', function(done) {
57-
let config = getBaseConfig();
59+
var config = getBaseConfig();
5860
delete(config.test_path);
5961
browserstackRunner.run(config, function(err) {
60-
assert.equal(err.message, "Configuration parameter test_path is required.");
62+
assert.equal(err.message, 'Configuration parameter test_path is required.');
6163
done();
6264
});
6365
});
@@ -70,18 +72,18 @@ describe('Config Assertions', function() {
7072
});
7173

7274
it('should have an error if config does not have a username', function(done) {
73-
let config = getBaseConfig();
75+
var config = getBaseConfig();
7476
delete(config.username);
7577
browserstackRunner.run(config, function(err) {
76-
assert.equal(err.message, "Configuration parameter username is required.");
78+
assert.equal(err.message, 'Configuration parameter username is required.');
7779
done();
7880
});
7981
});
8082
it('should have an error if config does not have a key', function(done) {
81-
let config = getBaseConfig();
83+
var config = getBaseConfig();
8284
delete(config.key);
8385
browserstackRunner.run(config, function(err) {
84-
assert.equal(err.message, "Configuration parameter key is required.");
86+
assert.equal(err.message, 'Configuration parameter key is required.');
8587
done();
8688
});
8789
});
@@ -96,47 +98,43 @@ describe('Pass/Fail reporting', function() {
9698
this.timeout(0);
9799

98100
it('report keys should have browser names', function(done) {
99-
let config = getBaseConfig();
101+
var config = getBaseConfig();
100102
browserstackRunner.run(config, function(err, report) {
101103
assert.equal(err, null);
102-
var parsedReport = JSON.parse(report);
103-
assert.notEqual(parsedReport["Windows 7, Chrome 52.0"], null);
104-
assert.notEqual(parsedReport["Windows 7, Firefox 47.0"], null);
104+
assert.notEqual(report['Windows 7, Chrome 52.0'], null);
105+
assert.notEqual(report['Windows 7, Firefox 47.0'], null);
105106
done();
106107
});
107108
});
108109
it('report keys should have assertions and tests', function(done) {
109-
let config = getBaseConfig();
110+
var config = getBaseConfig();
110111
browserstackRunner.run(config, function(err, report) {
111112
assert.equal(err, null);
112-
var parsedReport = JSON.parse(report);
113-
assert.notEqual(parsedReport["Windows 7, Chrome 52.0"].assertions, null);
114-
assert.notEqual(parsedReport["Windows 7, Chrome 52.0"].tests, null);
115-
assert.notEqual(parsedReport["Windows 7, Firefox 47.0"].assertions, null);
116-
assert.notEqual(parsedReport["Windows 7, Firefox 47.0"].tests, null);
113+
assert.notEqual(report['Windows 7, Chrome 52.0'].assertions, null);
114+
assert.notEqual(report['Windows 7, Chrome 52.0'].tests, null);
115+
assert.notEqual(report['Windows 7, Firefox 47.0'].assertions, null);
116+
assert.notEqual(report['Windows 7, Firefox 47.0'].tests, null);
117117
done();
118118
});
119119
});
120120
describe('Test Assertions', function() {
121121
it('report should have proper number of assertions for tests', function(done) {
122-
let config = getBaseConfig();
122+
var config = getBaseConfig();
123123
browserstackRunner.run(config, function(err, report) {
124124
assert.equal(err, null);
125-
var parsedReport = JSON.parse(report);
126125
// Only failed assertions are emitted
127-
assert.equal(parsedReport["Windows 7, Chrome 52.0"].assertions.length, 8);
128-
assert.equal(parsedReport["Windows 7, Firefox 47.0"].assertions.length, 8);
126+
assert.equal(report['Windows 7, Chrome 52.0'].assertions.length, 8);
127+
assert.equal(report['Windows 7, Firefox 47.0'].assertions.length, 8);
129128
done();
130129
});
131130
});
132131
it('report should have specific keys', function(done) {
133-
let config = getBaseConfig();
132+
var config = getBaseConfig();
134133
browserstackRunner.run(config, function(err, report) {
135134
assert.equal(err, null);
136-
var parsedReport = JSON.parse(report);
137-
Object.keys(parsedReport).forEach(function(reportKey) {
138-
parsedReport[reportKey].assertions.forEach(function(assertion) {
139-
[ "actual", "expected", "message", "source" ].forEach(function(key) {
135+
Object.keys(report).forEach(function(reportKey) {
136+
report[reportKey].assertions.forEach(function(assertion) {
137+
[ 'actual', 'expected', 'message', 'source' ].forEach(function(key) {
140138
assert.notEqual(assertion[key], null);
141139
});
142140
});
@@ -145,13 +143,12 @@ describe('Pass/Fail reporting', function() {
145143
});
146144
});
147145
it('report should have message in assertions', function(done) {
148-
let config = getBaseConfig();
146+
var config = getBaseConfig();
149147
browserstackRunner.run(config, function(err, report) {
150148
assert.equal(err, null);
151-
var parsedReport = JSON.parse(report);
152-
Object.keys(parsedReport).forEach(function(reportKey) {
153-
parsedReport[reportKey].assertions.forEach(function(assertion) {
154-
assert.notEqual(assertion["message"].match(/\d+ is .*an .* number/), null);
149+
Object.keys(report).forEach(function(reportKey) {
150+
report[reportKey].assertions.forEach(function(assertion) {
151+
assert.notEqual(assertion['message'].match(/\d+ is .*an .* number/), null);
155152
});
156153
});
157154
done();
@@ -160,23 +157,21 @@ describe('Pass/Fail reporting', function() {
160157
});
161158
describe('Test tests', function() {
162159
it('report should have proper number of tests', function(done) {
163-
let config = getBaseConfig();
160+
var config = getBaseConfig();
164161
browserstackRunner.run(config, function(err, report) {
165162
assert.equal(err, null);
166-
var parsedReport = JSON.parse(report);
167-
assert.equal(parsedReport["Windows 7, Chrome 52.0"].tests.length, 1);
168-
assert.equal(parsedReport["Windows 7, Firefox 47.0"].tests.length, 1);
163+
assert.equal(report['Windows 7, Chrome 52.0'].tests.length, 1);
164+
assert.equal(report['Windows 7, Firefox 47.0'].tests.length, 1);
169165
done();
170166
});
171167
});
172168
it('report should have specific keys', function(done) {
173-
let config = getBaseConfig();
169+
var config = getBaseConfig();
174170
browserstackRunner.run(config, function(err, report) {
175171
assert.equal(err, null);
176-
var parsedReport = JSON.parse(report);
177-
Object.keys(parsedReport).forEach(function(reportKey) {
178-
parsedReport[reportKey].tests.forEach(function(test) {
179-
[ "runtime", "total", "passed", "failed", "url" ].forEach(function(key) {
172+
Object.keys(report).forEach(function(reportKey) {
173+
report[reportKey].tests.forEach(function(test) {
174+
[ 'runtime', 'total', 'passed', 'failed', 'url' ].forEach(function(key) {
180175
assert.notEqual(test[key], null);
181176
});
182177
});
@@ -185,15 +180,14 @@ describe('Pass/Fail reporting', function() {
185180
});
186181
});
187182
it('report should have message in assertions', function(done) {
188-
let config = getBaseConfig();
183+
var config = getBaseConfig();
189184
browserstackRunner.run(config, function(err, report) {
190185
assert.equal(err, null);
191-
var parsedReport = JSON.parse(report);
192-
Object.keys(parsedReport).forEach(function(reportKey) {
193-
parsedReport[reportKey].tests.forEach(function(test) {
194-
assert.equal(test["total"], 3);
195-
assert.equal(test["passed"], 1);
196-
assert.equal(test["failed"], 2);
186+
Object.keys(report).forEach(function(reportKey) {
187+
report[reportKey].tests.forEach(function(test) {
188+
assert.equal(test['total'], 3);
189+
assert.equal(test['passed'], 1);
190+
assert.equal(test['failed'], 2);
197191
});
198192
});
199193
done();

0 commit comments

Comments
 (0)