Skip to content

Commit 4ef56b5

Browse files
committed
Integrate SauceLabs automated testing
1 parent 05e78d9 commit 4ef56b5

File tree

5 files changed

+114
-72
lines changed

5 files changed

+114
-72
lines changed

Gruntfile.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,25 @@ module.exports = function(grunt) {
226226
}
227227
},
228228

229+
'saucelabs-mocha': {
230+
all: {
231+
options: {
232+
urls: [
233+
'http://127.0.0.1:9999/test/index.html',
234+
'http://127.0.0.1:9999/test/integration/index.html'
235+
],
236+
sauceConfig: {
237+
'video-upload-on-pass': false
238+
},
239+
build: process.env.TRAVIS_BUILD_NUMBER,
240+
testname:
241+
'Raven.js' +
242+
(process.env.TRAVIS_JOB_NUMBER ? ' #' + process.env.TRAVIS_JOB_NUMBER : ''),
243+
browsers: [['macOS 10.12', 'chrome', 'latest']]
244+
}
245+
}
246+
},
247+
229248
release: {
230249
options: {
231250
npm: false,
@@ -258,6 +277,12 @@ module.exports = function(grunt) {
258277
},
259278

260279
connect: {
280+
ci: {
281+
options: {
282+
port: 9999
283+
}
284+
},
285+
261286
test: {
262287
options: {
263288
port: 8000,
@@ -330,6 +355,14 @@ module.exports = function(grunt) {
330355
grunt.config.set('pkg', pkg);
331356
});
332357

358+
grunt.registerTask('config:ci', 'Verify CI config', function() {
359+
if (!process.env.SAUCE_USERNAME)
360+
console.warn('No SAUCE_USERNAME env variable defined.');
361+
if (!process.env.SAUCE_ACCESS_KEY)
362+
console.warn('No SAUCE_ACCESS_KEY env variable defined.');
363+
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) process.exit(1);
364+
});
365+
333366
// Grunt contrib tasks
334367
grunt.loadNpmTasks('grunt-contrib-uglify');
335368
grunt.loadNpmTasks('grunt-contrib-clean');
@@ -344,6 +377,7 @@ module.exports = function(grunt) {
344377
grunt.loadNpmTasks('grunt-gitinfo');
345378
grunt.loadNpmTasks('grunt-sri');
346379
grunt.loadNpmTasks('grunt-eslint');
380+
grunt.loadNpmTasks('grunt-saucelabs');
347381

348382
// Build tasks
349383
grunt.registerTask('_prep', ['clean', 'gitinfo', 'version']);
@@ -368,6 +402,13 @@ module.exports = function(grunt) {
368402

369403
// Test task
370404
grunt.registerTask('test', ['eslint', 'browserify.core', 'browserify:test', 'mocha']);
405+
grunt.registerTask('test-ci', [
406+
'config:ci',
407+
'browserify.core',
408+
'browserify:test',
409+
'connect:ci',
410+
'saucelabs-mocha'
411+
]);
371412

372413
// Webserver tasks
373414
grunt.registerTask('run:test', ['connect:test']);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"grunt-mocha": "1.0.4",
4444
"grunt-release": "^0.13.0",
4545
"grunt-s3": "0.2.0-alpha.3",
46+
"grunt-saucelabs": "^9.0.0",
4647
"grunt-sri": "mattrobenolt/grunt-sri#pretty",
4748
"husky": "^0.14.3",
4849
"jquery": "^2.1.4",

test/index.html

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,67 @@
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-
if (!window.PHANTOMJS) {
37-
(function(runner){
38-
var failed = [];
39-
40-
runner.on('fail', function(test, err){
41-
failed.push({
42-
title: test.title,
43-
fullTitle: test.fullTitle(),
44-
error: {
45-
message: err.message,
46-
stack: err.stack
47-
}
48-
});
49-
});
50-
51-
runner.on('end', function(){
52-
runner.stats.failed = failed;
53-
if (typeof global !== "undefined") {
54-
global.mochaResults = runner.stats;
55-
}
56-
});
57-
})(mocha.run());
58-
}
38+
if (!window.PHANTOMJS) {
39+
window.onload = function () {
40+
var runner = mocha.run();
41+
var failedTests = [];
42+
43+
var flattenTitles = function (test) {
44+
var titles = [];
45+
while (test.parent.title){
46+
titles.push(test.parent.title);
47+
test = test.parent;
48+
}
49+
return titles.reverse();
50+
};
51+
52+
runner.on('fail', function (test, err) {
53+
failedTests.push({
54+
name: test.title,
55+
result: false,
56+
message: err.message,
57+
stack: err.stack,
58+
titles: flattenTitles(test)
59+
});
60+
});
61+
62+
runner.on('end', function () {
63+
window.mochaResults = runner.stats;
64+
window.mochaResults.reports = failedTests;
65+
});
66+
};
67+
}
5968
</script>
6069
</body>
6170
</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,62 +4,53 @@
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>
4225
if (!window.PHANTOMJS) {
43-
(function (runner) {
44-
window.runner = runner;
45-
var failed = [];
26+
window.onload = function () {
27+
var runner = mocha.run();
28+
var failedTests = [];
29+
30+
var flattenTitles = function (test) {
31+
var titles = [];
32+
while (test.parent.title){
33+
titles.push(test.parent.title);
34+
test = test.parent;
35+
}
36+
return titles.reverse();
37+
};
4638

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

5849
runner.on('end', function () {
59-
runner.stats.failed = failed;
6050
window.mochaResults = runner.stats;
51+
window.mochaResults.reports = failedTests;
6152
});
62-
})(mocha.run());
53+
};
6354
}
6455
</script>
6556
</body>

0 commit comments

Comments
 (0)