Skip to content

Commit 1a94e00

Browse files
committed
Merge pull request #152 from shirish87/ci
CI: Test with external repositories
2 parents c31790a + 6f49745 commit 1a94e00

File tree

5 files changed

+473
-3
lines changed

5 files changed

+473
-3
lines changed

.travis.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: node_js
2+
3+
node_js:
4+
- 'stable'
5+
6+
before_install:
7+
- npm install -g grunt-cli jshint gulp
8+
- true && `base64 --decode <<< ZXhwb3J0IEJST1dTRVJTVEFDS19VU0VSTkFNRT1icm93c2Vyc3RhY2tydW5uMQo=`
9+
- true && `base64 --decode <<< ZXhwb3J0IEJST1dTRVJTVEFDS19LRVk9NW5qc0d5emdqNkpWMmh3eUh1dHEK`
10+
11+
script:
12+
- npm run-script test-ci
13+
14+
cache:
15+
directories:
16+
- node_modules

lib/utils.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
var Log = require('./logger'),
22
logger = new Log(global.logLevel),
3-
config = require('./config'),
43
http = require('http'),
54
url = require('url'),
6-
querystring = require('querystring');
5+
querystring = require('querystring'),
6+
config;
77

88
String.prototype.escapeSpecialChars = function() {
99
return this.replace(/\n/g, '\\n')
@@ -51,6 +51,10 @@ var objectSize = function objectSize(obj) {
5151
};
5252

5353
var alertBrowserStack = function alertBrowserStack(subject, content, params, fn) {
54+
if (!config) {
55+
config = require('./config');
56+
}
57+
5458
var endpoint = config.alert_endpoint || 'http://www.browserstack.com/automate/alert';
5559
var urlObject = url.parse(endpoint);
5660

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
"browserstack-runner": "bin/cli.js"
2929
},
3030
"scripts": {
31-
"test": "node_modules/.bin/mocha tests/unit && node_modules/.bin/jshint lib/*.js bin/"
31+
"lint": "node_modules/.bin/jshint lib/*.js bin/ tests/*.js",
32+
"test-unit": "node_modules/.bin/mocha tests/unit",
33+
"test-ci": "npm run lint && npm run test-unit && TEST_MODE=all tests/external-tests.js",
34+
"test": "npm run lint && npm run test-unit && TEST_MODE=required tests/external-tests.js",
35+
"update-util": "node_modules/.bin/browserify lib/client-browserstack-util.js | node_modules/.bin/uglifyjs > lib/_patch/browserstack-util.js"
3236
}
3337
}

tests/external-tests.js

+187
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
#! /usr/bin/env node
2+
3+
var path = require('path');
4+
var Helper = require('./helper');
5+
6+
var browserstackConfig = {
7+
username: 'BROWSERSTACK_USERNAME',
8+
key: 'BROWSERSTACK_KEY'
9+
};
10+
11+
var mode = (process.env.TEST_MODE || 'all').toLowerCase();
12+
var runnerPath = path.resolve(path.join(__dirname, '..', 'bin', 'cli.js'));
13+
var testHome = path.resolve(__dirname);
14+
process.chdir(testHome);
15+
16+
var repositories = [
17+
{
18+
name: 'qunit',
19+
tag: '1.21.0',
20+
url: 'https://github.com/jquery/qunit.git',
21+
test_framework: 'qunit',
22+
browsers: [
23+
{
24+
'browser': 'firefox',
25+
'browser_version': '44.0',
26+
'os': 'OS X',
27+
'os_version': 'El Capitan'
28+
}
29+
],
30+
test_path: [
31+
'test/index.html'
32+
],
33+
expected_results: {
34+
tests: 534,
35+
passed: 534,
36+
failed: 0
37+
}
38+
},
39+
{
40+
name: 'mocha',
41+
tag: 'v2.4.5',
42+
url: 'https://github.com/mochajs/mocha.git',
43+
test_framework: 'mocha',
44+
browsers: [
45+
{
46+
'browser': 'ie',
47+
'browser_version': '11.0',
48+
'os': 'Windows',
49+
'os_version': '10'
50+
}
51+
],
52+
test_path: [
53+
'test/browser/index.html',
54+
'test/browser/large.html',
55+
'test/browser/opts.html'
56+
],
57+
expected_results: {
58+
tests: 89,
59+
passed: 80,
60+
failed: 9
61+
}
62+
},
63+
{
64+
name: 'spine',
65+
tag: 'v.1.6.2',
66+
url: 'https://github.com/spine/spine.git',
67+
test_framework: 'jasmine2',
68+
browsers: [
69+
{
70+
'browser': 'safari',
71+
'browser_version': '9.0',
72+
'os': 'OS X',
73+
'os_version': 'El Capitan'
74+
}
75+
],
76+
test_path: [
77+
'test/index.html'
78+
],
79+
expected_results: {
80+
tests: 161,
81+
passed: 161,
82+
failed: 0
83+
}
84+
},
85+
{
86+
name: 'spine',
87+
tag: 'v1.0.0',
88+
url: 'https://github.com/spine/spine.git',
89+
test_framework: 'jasmine',
90+
browsers: [
91+
{
92+
'browser': 'safari',
93+
'browser_version': '5.1',
94+
'os': 'OS X',
95+
'os_version': 'Snow Leopard'
96+
}
97+
],
98+
test_path: [
99+
'test/index.html'
100+
],
101+
patches: [
102+
{
103+
find: 'jasmine.getEnv().execute();',
104+
replace: 'window.onload = function () { jasmine.getEnv().execute(); };'
105+
}
106+
],
107+
expected_results: {
108+
tests: 63,
109+
passed: 63,
110+
failed: 0
111+
}
112+
}
113+
];
114+
115+
var repositoriesOptional = [
116+
{
117+
name: 'qunit',
118+
tag: 'v1.0.0',
119+
url: 'https://github.com/jquery/qunit.git',
120+
test_framework: 'qunit',
121+
browsers: [
122+
{
123+
'browser': 'firefox',
124+
'browser_version': '44.0',
125+
'os': 'OS X',
126+
'os_version': 'Snow Leopard'
127+
}
128+
],
129+
test_path: [
130+
'test/index.html',
131+
'test/logs.html'
132+
],
133+
expected_results: {
134+
tests: 323,
135+
passed: 323,
136+
failed: 0
137+
}
138+
},
139+
{
140+
name: 'mocha',
141+
tag: '1.21.5',
142+
url: 'https://github.com/mochajs/mocha.git',
143+
test_framework: 'mocha',
144+
browsers: [
145+
{
146+
'browser': 'ie',
147+
'browser_version': '10.0',
148+
'os': 'Windows',
149+
'os_version': '7'
150+
}
151+
],
152+
test_path: [
153+
'test/browser/index.html',
154+
'test/browser/large.html',
155+
'test/browser/opts.html'
156+
],
157+
expected_results: {
158+
tests: 84,
159+
passed: 77,
160+
failed: 7
161+
}
162+
}
163+
];
164+
165+
function run(repositories) {
166+
Helper.runRepositories(browserstackConfig, repositories, testHome, runnerPath, function (err) {
167+
if (err) {
168+
console.log(err.stack);
169+
throw err;
170+
}
171+
172+
console.log('Done.');
173+
});
174+
}
175+
176+
switch (mode) {
177+
case 'required':
178+
run(repositories);
179+
break;
180+
181+
case 'optional':
182+
run(repositoriesOptional);
183+
break;
184+
185+
default:
186+
run([].concat(repositories).concat(repositoriesOptional));
187+
}

0 commit comments

Comments
 (0)