Skip to content

Commit f638521

Browse files
committed
build: Use Headless Chrome instead of PhantomJS for testing
- Use Headless Chrome instead of PhantomJS - Reconfigure TravisCI to utilize new setup - Remove PhantomJS guards in integration tests - Start partial migration to npm scripts instead of Grunt - Remove lodash and use native functions instead - Remove redundant packages
1 parent b89d9da commit f638521

File tree

6 files changed

+97
-138
lines changed

6 files changed

+97
-138
lines changed

.travis.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- "4"
4+
- "8"
5+
dist: trusty
6+
addons:
7+
chrome: stable
8+
cache:
9+
directories:
10+
- node_modules
511
script:
6-
- npm test
12+
- npm test

Gruntfile.js

+14-49
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
module.exports = function(grunt) {
4-
var _ = require('lodash');
54
var path = require('path');
65
var os = require('os');
76
var through = require('through2');
@@ -14,7 +13,7 @@ module.exports = function(grunt) {
1413

1514
var plugins = grunt.option('plugins');
1615
// Create plugin paths and verify they exist
17-
plugins = _.map(plugins ? plugins.split(',') : [], function(plugin) {
16+
plugins = (plugins ? plugins.split(',') : []).map(function(plugin) {
1817
var p = 'plugins/' + plugin + '.js';
1918

2019
if (!grunt.file.exists(p))
@@ -51,12 +50,12 @@ module.exports = function(grunt) {
5150
}
5251
};
5352

54-
var excluded = _.map(excludedPlugins, function(plugin) {
53+
var excluded = excludedPlugins.map(function(plugin) {
5554
return 'plugins/' + plugin + '.js';
5655
});
5756

5857
// Remove the plugins that we don't want to build
59-
a = _.filter(a, function(n) {
58+
a = a.filter(function(n) {
6059
return excluded.indexOf(n) === -1;
6160
});
6261

@@ -88,21 +87,17 @@ module.exports = function(grunt) {
8887
});
8988

9089
var pluginCombinations = combine(plugins);
91-
var pluginConcatFiles = _.reduce(
92-
pluginCombinations,
93-
function(dict, comb) {
94-
var key = _.map(comb, function(plugin) {
95-
return path.basename(plugin, '.js');
96-
});
97-
key.sort();
90+
var pluginConcatFiles = pluginCombinations.reduce(function(dict, comb) {
91+
var key = comb.map(function(plugin) {
92+
return path.basename(plugin, '.js');
93+
});
94+
key.sort();
9895

99-
var dest = path.join('build/', key.join(','), '/raven.js');
100-
dict[dest] = ['src/singleton.js'].concat(comb);
96+
var dest = path.join('build/', key.join(','), '/raven.js');
97+
dict[dest] = ['src/singleton.js'].concat(comb);
10198

102-
return dict;
103-
},
104-
{}
105-
);
99+
return dict;
100+
}, {});
106101

107102
var browserifyConfig = {
108103
options: {
@@ -202,30 +197,6 @@ module.exports = function(grunt) {
202197
}
203198
},
204199

205-
eslint: {
206-
target: ['.']
207-
},
208-
209-
mocha: {
210-
options: {
211-
mocha: {
212-
ignoreLeaks: true,
213-
grep: grunt.option('grep')
214-
},
215-
log: true,
216-
reporter: 'Dot',
217-
run: true
218-
},
219-
unit: {
220-
src: ['test/index.html'],
221-
nonull: true
222-
},
223-
integration: {
224-
src: ['test/integration/index.html'],
225-
nonull: true
226-
}
227-
},
228-
229200
release: {
230201
options: {
231202
npm: false,
@@ -338,12 +309,10 @@ module.exports = function(grunt) {
338309

339310
// 3rd party Grunt tasks
340311
grunt.loadNpmTasks('grunt-browserify');
341-
grunt.loadNpmTasks('grunt-mocha');
342312
grunt.loadNpmTasks('grunt-release');
343313
grunt.loadNpmTasks('grunt-s3');
344314
grunt.loadNpmTasks('grunt-gitinfo');
345315
grunt.loadNpmTasks('grunt-sri');
346-
grunt.loadNpmTasks('grunt-eslint');
347316

348317
// Build tasks
349318
grunt.registerTask('_prep', ['clean', 'gitinfo', 'version']);
@@ -355,7 +324,7 @@ module.exports = function(grunt) {
355324
'_prep',
356325
'browserify:plugins-combined'
357326
]);
358-
grunt.registerTask('build.test', ['_prep', 'browserify:test']);
327+
grunt.registerTask('build.test', ['_prep', 'browserify.core', 'browserify:test']);
359328
grunt.registerTask('build.core', ['browserify.core', 'uglify', 'sri:dist']);
360329
grunt.registerTask('build.plugins-combined', [
361330
'browserify.plugins-combined',
@@ -366,13 +335,9 @@ module.exports = function(grunt) {
366335
grunt.registerTask('build', ['build.plugins-combined']);
367336
grunt.registerTask('dist', ['build.core', 'copy:dist']);
368337

369-
// Test task
370-
grunt.registerTask('test', ['eslint', 'browserify.core', 'browserify:test', 'mocha']);
371-
372338
// Webserver tasks
373339
grunt.registerTask('run:test', ['connect:test']);
374340
grunt.registerTask('run:docs', ['connect:docs']);
375341

376-
grunt.registerTask('publish', ['test', 'build.plugins-combined', 's3']);
377-
grunt.registerTask('default', ['test']);
342+
grunt.registerTask('publish', ['build.plugins-combined', 's3']);
378343
};

package.json

+7-9
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
"scripts": {
1818
"lint": "eslint .",
1919
"precommit": "lint-staged",
20-
"pretest": "npm install",
21-
"test": "grunt test && npm run-script test-typescript",
22-
"test-typescript": "node_modules/typescript/bin/tsc --noEmit --noImplicitAny typescript/raven-tests.ts"
20+
"publish": "npm run test && grunt publish",
21+
"test": "npm run lint && grunt build.test && npm run test:unit && npm run test:integration && npm run test:typescript",
22+
"test:unit": "mocha-chrome test/index.html",
23+
"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"
2325
},
2426
"devDependencies": {
2527
"bluebird": "^3.4.1",
@@ -28,27 +30,23 @@
2830
"chai": "2.3.0",
2931
"derequire": "2.0.3",
3032
"es6-promise": "^4.0.5",
33+
"eslint": "^4.6.1",
3134
"eslint-config-prettier": "^2.3.0",
3235
"grunt": "^0.4.5",
3336
"grunt-browserify": "^4.0.1",
3437
"grunt-cli": "^0.1.13",
3538
"grunt-contrib-clean": "^0.7.0",
36-
"grunt-contrib-concat": "^0.5.1",
3739
"grunt-contrib-connect": "^0.11.2",
3840
"grunt-contrib-copy": "^0.8.2",
39-
"grunt-contrib-jshint": "^0.11.3",
4041
"grunt-contrib-uglify": "^0.11.0",
41-
"grunt-eslint": "^20.0.0",
4242
"grunt-gitinfo": "^0.1.7",
43-
"grunt-mocha": "1.0.4",
4443
"grunt-release": "^0.13.0",
4544
"grunt-s3": "0.2.0-alpha.3",
4645
"grunt-sri": "mattrobenolt/grunt-sri#pretty",
4746
"husky": "^0.14.3",
48-
"jquery": "^2.1.4",
4947
"lint-staged": "^4.0.4",
50-
"lodash": "^3.10.1",
5148
"mocha": "2.5.3",
49+
"mocha-chrome": "^0.2.1",
5250
"prettier": "^1.6.1",
5351
"proxyquireify": "^3.0.2",
5452
"sinon": "1.7.3",

test/index.html

+19-21
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,27 @@
3333
<script src="../build/raven.test.js"></script>
3434

3535
<script>
36-
if (!window.PHANTOMJS) {
37-
(function(runner){
38-
var failed = [];
36+
(function(runner){
37+
var failed = [];
3938

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-
});
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+
});
5049

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-
}
50+
runner.on('end', function(){
51+
runner.stats.failed = failed;
52+
if (typeof global !== "undefined") {
53+
global.mochaResults = runner.stats;
54+
}
55+
});
56+
})(mocha.run());
5957
</script>
6058
</body>
6159
</html>

test/integration/index.html

+17-19
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,26 @@
3939
<script src="test.js"></script>
4040

4141
<script>
42-
if (!window.PHANTOMJS) {
43-
(function (runner) {
44-
window.runner = runner;
45-
var failed = [];
42+
(function (runner) {
43+
window.runner = runner;
44+
var failed = [];
4645

47-
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-
}
55-
});
46+
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+
}
5654
});
55+
});
5756

58-
runner.on('end', function () {
59-
runner.stats.failed = failed;
60-
window.mochaResults = runner.stats;
61-
});
62-
})(mocha.run());
63-
}
57+
runner.on('end', function () {
58+
runner.stats.failed = failed;
59+
window.mochaResults = runner.stats;
60+
});
61+
})(mocha.run());
6462
</script>
6563
</body>
6664
</html>

test/integration/test.js

+32-38
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ describe('integration', function() {
189189

190190
// same error message, but different stacks means that these are considered
191191
// different errors
192-
// NOTE: PhantomJS can't derive function/lineno/colno from evaled frames, must
193-
// use frames declared in frame.html (foo(), bar())
194192

195193
// stack:
196194
// bar
@@ -918,46 +916,43 @@ describe('integration', function() {
918916
);
919917
});
920918

921-
// doesn't work in PhantomJS
922-
if (!/PhantomJS/.test(window.navigator.userAgent)) {
923-
it('should bail out if accessing the `type` and `target` properties of an event throw an exception', function(
924-
done
925-
) {
926-
// see: https://github.com/getsentry/raven-js/issues/768
927-
var iframe = this.iframe;
928-
929-
iframeExecute(
930-
iframe,
931-
done,
932-
function() {
933-
setTimeout(done);
934-
935-
// some browsers trigger onpopstate for load / reset breadcrumb state
936-
Raven._breadcrumbs = [];
919+
it('should bail out if accessing the `type` and `target` properties of an event throw an exception', function(
920+
done
921+
) {
922+
// see: https://github.com/getsentry/raven-js/issues/768
923+
var iframe = this.iframe;
937924

938-
// click <input/>
939-
var evt = createMouseEvent();
925+
iframeExecute(
926+
iframe,
927+
done,
928+
function() {
929+
setTimeout(done);
940930

941-
function kaboom() {
942-
throw new Error('lol');
943-
}
944-
Object.defineProperty(evt, 'type', {get: kaboom});
945-
Object.defineProperty(evt, 'target', {get: kaboom});
931+
// some browsers trigger onpopstate for load / reset breadcrumb state
932+
Raven._breadcrumbs = [];
946933

947-
var input = document.querySelector('.a'); // leaf node
948-
input.dispatchEvent(evt);
949-
},
950-
function() {
951-
var Raven = iframe.contentWindow.Raven,
952-
breadcrumbs = Raven._breadcrumbs;
934+
// click <input/>
935+
var evt = createMouseEvent();
953936

954-
assert.equal(breadcrumbs.length, 1);
955-
assert.equal(breadcrumbs[0].category, 'ui.click');
956-
assert.equal(breadcrumbs[0].message, '<unknown>');
937+
function kaboom() {
938+
throw new Error('lol');
957939
}
958-
);
959-
});
960-
} // if PhantomJS
940+
Object.defineProperty(evt, 'type', {get: kaboom});
941+
Object.defineProperty(evt, 'target', {get: kaboom});
942+
943+
var input = document.querySelector('.a'); // leaf node
944+
input.dispatchEvent(evt);
945+
},
946+
function() {
947+
var Raven = iframe.contentWindow.Raven,
948+
breadcrumbs = Raven._breadcrumbs;
949+
950+
assert.equal(breadcrumbs.length, 1);
951+
assert.equal(breadcrumbs[0].category, 'ui.click');
952+
assert.equal(breadcrumbs[0].message, '<unknown>');
953+
}
954+
);
955+
});
961956

962957
it('should record consecutive keypress events into a single "input" breadcrumb', function(
963958
done
@@ -1159,7 +1154,6 @@ describe('integration', function() {
11591154
assert.equal(breadcrumbs[2].category, 'navigation'); // bar?a=1#fragment => [object%20Object]
11601155
assert.equal(breadcrumbs[3].category, 'navigation'); // [object%20Object] => bar?a=1#fragment (back button)
11611156

1162-
// assert end of string because PhantomJS uses full system path
11631157
assert.ok(
11641158
/\/test\/integration\/frame\.html$/.test(Raven._breadcrumbs[0].data.from),
11651159
"'from' url is incorrect"

0 commit comments

Comments
 (0)