Skip to content

Commit e8319b7

Browse files
committed
build: Integrate SauceLabs for automated cross-browser testing
- Use grunt-saucelabs to run all the tests - Add README badges for SauceLabs - Update Grunt tasks CI tests
1 parent f4159af commit e8319b7

File tree

6 files changed

+122
-70
lines changed

6 files changed

+122
-70
lines changed

Gruntfile.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,32 @@ module.exports = function(grunt) {
197197
}
198198
},
199199

200+
'saucelabs-mocha': {
201+
all: {
202+
options: {
203+
urls: [
204+
'http://127.0.0.1:9999/test/index.html',
205+
'http://127.0.0.1:9999/test/integration/index.html'
206+
],
207+
sauceConfig: {
208+
'record-video': false,
209+
'record-screenshots': false
210+
},
211+
build: process.env.TRAVIS_BUILD_NUMBER,
212+
testname:
213+
'Raven.js' +
214+
(process.env.TRAVIS_JOB_NUMBER ? ' #' + process.env.TRAVIS_JOB_NUMBER : ''),
215+
browsers: [
216+
['macOS 10.12', 'chrome', 'latest'],
217+
['macOS 10.12', 'firefox', 'latest'],
218+
['macOS 10.12', 'safari', '10.0']
219+
],
220+
public: 'public',
221+
tunnelArgs: ['--verbose']
222+
}
223+
}
224+
},
225+
200226
release: {
201227
options: {
202228
npm: false,
@@ -229,6 +255,12 @@ module.exports = function(grunt) {
229255
},
230256

231257
connect: {
258+
ci: {
259+
options: {
260+
port: 9999
261+
}
262+
},
263+
232264
test: {
233265
options: {
234266
port: 8000,
@@ -301,6 +333,14 @@ module.exports = function(grunt) {
301333
grunt.config.set('pkg', pkg);
302334
});
303335

336+
grunt.registerTask('config:ci', 'Verify CI config', function() {
337+
if (!process.env.SAUCE_USERNAME)
338+
console.warn('No SAUCE_USERNAME env variable defined.');
339+
if (!process.env.SAUCE_ACCESS_KEY)
340+
console.warn('No SAUCE_ACCESS_KEY env variable defined.');
341+
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) process.exit(1);
342+
});
343+
304344
// Grunt contrib tasks
305345
grunt.loadNpmTasks('grunt-contrib-uglify');
306346
grunt.loadNpmTasks('grunt-contrib-clean');
@@ -313,6 +353,7 @@ module.exports = function(grunt) {
313353
grunt.loadNpmTasks('grunt-s3');
314354
grunt.loadNpmTasks('grunt-gitinfo');
315355
grunt.loadNpmTasks('grunt-sri');
356+
grunt.loadNpmTasks('grunt-saucelabs');
316357

317358
// Build tasks
318359
grunt.registerTask('_prep', ['clean', 'gitinfo', 'version']);
@@ -335,6 +376,13 @@ module.exports = function(grunt) {
335376
grunt.registerTask('build', ['build.plugins-combined']);
336377
grunt.registerTask('dist', ['build.core', 'copy:dist']);
337378

379+
grunt.registerTask('test:ci', [
380+
'config:ci',
381+
'build.test',
382+
'connect:ci',
383+
'saucelabs-mocha'
384+
]);
385+
338386
// Webserver tasks
339387
grunt.registerTask('run:test', ['connect:test']);
340388
grunt.registerTask('run:docs', ['connect:docs']);

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
<h1>Raven.js - Sentry SDK for JavaScript</h1>
77
</p>
88

9-
[![Build Status](https://travis-ci.org/getsentry/raven-js.svg?branch=master)](https://travis-ci.org/getsentry/raven-js) [![npm](https://img.shields.io/npm/v/raven-js.svg)](https://www.npmjs.com/package/raven-js) [![npm](https://img.shields.io/npm/dm/raven-js.svg)](https://www.npmjs.com/package/raven-js)
9+
[![Sauce Test Status](https://saucelabs.com/buildstatus/kamilsentry)](https://saucelabs.com/u/kamilsentry)[![Build Status](https://travis-ci.org/getsentry/raven-js.svg?branch=master)](https://travis-ci.org/getsentry/raven-js) [![npm](https://img.shields.io/npm/v/raven-js.svg)](https://www.npmjs.com/package/raven-js) [![npm](https://img.shields.io/npm/dm/raven-js.svg)](https://www.npmjs.com/package/raven-js)
10+
11+
[![Sauce Test Status](https://saucelabs.com/browser-matrix/kamilsentry.svg)](https://saucelabs.com/u/kamilsentry)
1012

1113
## Requirements
1214

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"test": "npm run lint && grunt build.test && npm run test:unit && npm run test:integration && npm run test:typescript",
2222
"test:unit": "mocha-chrome test/index.html",
2323
"test:integration": "mocha-chrome test/integration/index.html --chrome-flags '[\"--disable-web-security\"]' --ignore-resource-errors --ignore-exceptions",
24-
"test:typescript": "tsc --noEmit --noImplicitAny typescript/raven-tests.ts"
24+
"test:typescript": "tsc --noEmit --noImplicitAny typescript/raven-tests.ts",
25+
"test:ci": "npm run lint && grunt test:ci"
2526
},
2627
"devDependencies": {
2728
"bluebird": "^3.4.1",
@@ -42,6 +43,7 @@
4243
"grunt-gitinfo": "^0.1.7",
4344
"grunt-release": "^0.13.0",
4445
"grunt-s3": "0.2.0-alpha.3",
46+
"grunt-saucelabs": "^9.0.0",
4547
"grunt-sri": "mattrobenolt/grunt-sri#pretty",
4648
"husky": "^0.14.3",
4749
"lint-staged": "^4.0.4",

test/index.html

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,65 @@
44
<title>Raven.js Test Suite</title>
55
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
66
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
7-
</head>
8-
<body>
9-
<div id="mocha"></div>
7+
108
<!-- Mocha -->
119
<script src="../node_modules/mocha/mocha.js"></script>
1210
<script src="../node_modules/chai/chai.js"></script>
1311
<script>
14-
mocha.ui('bdd');
15-
mocha.reporter('html');
16-
var assert = chai.assert
12+
mocha.ui('bdd');
13+
mocha.reporter('html');
14+
var assert = chai.assert
1715
</script>
1816

1917
<!-- Mocking -->
2018
<script src="../node_modules/sinon/pkg/sinon.js"></script>
2119
<script>
22-
window.__DEV__ = true;
23-
beforeEach(function() {
20+
window.__DEV__ = true;
21+
22+
beforeEach(function() {
2423
this.sinon = sinon.sandbox.create();
25-
});
24+
});
2625

27-
afterEach(function() {
26+
afterEach(function() {
2827
this.sinon.restore();
29-
});
28+
});
3029
</script>
3130

3231
<!-- Tests -->
3332
<script src="../build/raven.test.js"></script>
33+
</head>
34+
<body>
35+
<div id="mocha"></div>
3436

3537
<script>
36-
(function(runner){
37-
var failed = [];
38-
39-
runner.on('fail', function(test, err){
40-
failed.push({
41-
title: test.title,
42-
fullTitle: test.fullTitle(),
43-
error: {
44-
message: err.message,
45-
stack: err.stack
46-
}
47-
});
48-
});
38+
window.onload = function () {
39+
var runner = mocha.run();
40+
var failedTests = [];
4941

50-
runner.on('end', function(){
51-
runner.stats.failed = failed;
52-
if (typeof global !== "undefined") {
53-
global.mochaResults = runner.stats;
54-
}
42+
var flattenTitles = function (test) {
43+
var titles = [];
44+
while (test.parent.title){
45+
titles.push(test.parent.title);
46+
test = test.parent;
47+
}
48+
return titles.reverse();
49+
};
50+
51+
runner.on('fail', function (test, err) {
52+
failedTests.push({
53+
name: test.title,
54+
result: false,
55+
message: err.message,
56+
stack: err.stack,
57+
titles: flattenTitles(test)
5558
});
56-
})(mocha.run());
59+
});
60+
61+
runner.on('end', function () {
62+
window.mochaResults = runner.stats;
63+
window.mochaResults.reports = failedTests;
64+
});
65+
};
5766
</script>
5867
</body>
5968
</html>

test/integration/frame.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
33
<head>
44
<meta charset="utf-8">

test/integration/index.html

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,52 @@
44
<title>Raven.js Test Suite</title>
55
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
66
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
7-
</head>
8-
<body>
9-
<div id="mocha"></div>
7+
108
<!-- Mocha -->
119
<script src="../../node_modules/mocha/mocha.js"></script>
1210
<script src="../../node_modules/chai/chai.js"></script>
1311
<script>
14-
mocha.ui('bdd');
15-
mocha.reporter('html');
16-
var assert = chai.assert
17-
</script>
18-
19-
<!-- Mocking -->
20-
<script src="../../node_modules/sinon/pkg/sinon.js"></script>
21-
<script src="../../build/raven.js"></script>
22-
<script>
23-
beforeEach(function() {
24-
this.sinon = sinon.sandbox.create();
25-
var xhr = sinon.useFakeXMLHttpRequest();
26-
window.requests = this.requests = [];
27-
28-
xhr.onCreate = function (xhr) {
29-
requests.push(xhr);
30-
};
31-
});
32-
33-
afterEach(function() {
34-
this.sinon.restore();
35-
});
12+
mocha.ui('bdd');
13+
mocha.reporter('html');
14+
var assert = chai.assert
3615
</script>
3716

3817
<!-- Tests -->
18+
<script src="../../build/raven.js"></script>
3919
<script src="test.js"></script>
20+
</head>
21+
<body>
22+
<div id="mocha"></div>
4023

4124
<script>
42-
(function (runner) {
43-
window.runner = runner;
44-
var failed = [];
25+
window.onload = function () {
26+
var runner = mocha.run();
27+
var failedTests = [];
28+
29+
var flattenTitles = function (test) {
30+
var titles = [];
31+
while (test.parent.title){
32+
titles.push(test.parent.title);
33+
test = test.parent;
34+
}
35+
return titles.reverse();
36+
};
4537

4638
runner.on('fail', function (test, err) {
47-
failed.push({
48-
title: test.title,
49-
fullTitle: test.fullTitle(),
50-
error: {
51-
message: err.message,
52-
stack: err.stack
53-
}
39+
failedTests.push({
40+
name: test.title,
41+
result: false,
42+
message: err.message,
43+
stack: err.stack,
44+
titles: flattenTitles(test)
5445
});
5546
});
5647

5748
runner.on('end', function () {
58-
runner.stats.failed = failed;
5949
window.mochaResults = runner.stats;
50+
window.mochaResults.reports = failedTests;
6051
});
61-
})(mocha.run());
52+
};
6253
</script>
6354
</body>
6455
</html>

0 commit comments

Comments
 (0)