Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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
  • Loading branch information
kamilogorek committed Sep 8, 2017
commit bafa99c408cdf9d4ca44c7c1f3f491bde842d0cb
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
sudo: false
language: node_js
node_js:
- "4"
- "8"
dist: trusty
addons:
chrome: stable
cache:
directories:
- node_modules
script:
- npm test
- npm test
63 changes: 14 additions & 49 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

module.exports = function(grunt) {
var _ = require('lodash');
var path = require('path');
var os = require('os');
var through = require('through2');
Expand All @@ -14,7 +13,7 @@ module.exports = function(grunt) {

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

if (!grunt.file.exists(p))
Expand Down Expand Up @@ -51,12 +50,12 @@ module.exports = function(grunt) {
}
};

var excluded = _.map(excludedPlugins, function(plugin) {
var excluded = excludedPlugins.map(function(plugin) {
return 'plugins/' + plugin + '.js';
});

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

Expand Down Expand Up @@ -88,21 +87,17 @@ module.exports = function(grunt) {
});

var pluginCombinations = combine(plugins);
var pluginConcatFiles = _.reduce(
pluginCombinations,
function(dict, comb) {
var key = _.map(comb, function(plugin) {
return path.basename(plugin, '.js');
});
key.sort();
var pluginConcatFiles = pluginCombinations.reduce(function(dict, comb) {
var key = comb.map(function(plugin) {
return path.basename(plugin, '.js');
});
key.sort();

var dest = path.join('build/', key.join(','), '/raven.js');
dict[dest] = ['src/singleton.js'].concat(comb);
var dest = path.join('build/', key.join(','), '/raven.js');
dict[dest] = ['src/singleton.js'].concat(comb);

return dict;
},
{}
);
return dict;
}, {});

var browserifyConfig = {
options: {
Expand Down Expand Up @@ -202,30 +197,6 @@ module.exports = function(grunt) {
}
},

eslint: {
target: ['.']
},

mocha: {
options: {
mocha: {
ignoreLeaks: true,
grep: grunt.option('grep')
},
log: true,
reporter: 'Dot',
run: true
},
unit: {
src: ['test/index.html'],
nonull: true
},
integration: {
src: ['test/integration/index.html'],
nonull: true
}
},

release: {
options: {
npm: false,
Expand Down Expand Up @@ -338,12 +309,10 @@ module.exports = function(grunt) {

// 3rd party Grunt tasks
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-mocha');
grunt.loadNpmTasks('grunt-release');
grunt.loadNpmTasks('grunt-s3');
grunt.loadNpmTasks('grunt-gitinfo');
grunt.loadNpmTasks('grunt-sri');
grunt.loadNpmTasks('grunt-eslint');

// Build tasks
grunt.registerTask('_prep', ['clean', 'gitinfo', 'version']);
Expand All @@ -355,7 +324,7 @@ module.exports = function(grunt) {
'_prep',
'browserify:plugins-combined'
]);
grunt.registerTask('build.test', ['_prep', 'browserify:test']);
grunt.registerTask('build.test', ['_prep', 'browserify.core', 'browserify:test']);
grunt.registerTask('build.core', ['browserify.core', 'uglify', 'sri:dist']);
grunt.registerTask('build.plugins-combined', [
'browserify.plugins-combined',
Expand All @@ -366,13 +335,9 @@ module.exports = function(grunt) {
grunt.registerTask('build', ['build.plugins-combined']);
grunt.registerTask('dist', ['build.core', 'copy:dist']);

// Test task
grunt.registerTask('test', ['eslint', 'browserify.core', 'browserify:test', 'mocha']);

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

grunt.registerTask('publish', ['test', 'build.plugins-combined', 's3']);
grunt.registerTask('default', ['test']);
grunt.registerTask('publish', ['build.plugins-combined', 's3']);
};
16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
"scripts": {
"lint": "eslint .",
"precommit": "lint-staged",
"pretest": "npm install",
"test": "grunt test && npm run-script test-typescript",
"test-typescript": "node_modules/typescript/bin/tsc --noEmit --noImplicitAny typescript/raven-tests.ts"
"publish": "npm run test && grunt publish",
"test": "npm run lint && grunt build.test && npm run test:unit && npm run test:integration && npm run test:typescript",
"test:unit": "mocha-chrome test/index.html",
"test:integration": "mocha-chrome test/integration/index.html --chrome-flags '[\"--disable-web-security\"]' --ignore-resource-errors --ignore-exceptions",
"test:typescript": "tsc --noEmit --noImplicitAny typescript/raven-tests.ts"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally link linking to the version found in node_modules because collaborators often don't have node_modules/.bin on their PATH.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when you run things using yarn/npm, it'll add node_modules/.bin to search path.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah

},
"devDependencies": {
"bluebird": "^3.4.1",
Expand All @@ -28,27 +30,23 @@
"chai": "2.3.0",
"derequire": "2.0.3",
"es6-promise": "^4.0.5",
"eslint": "^4.6.1",
"eslint-config-prettier": "^2.3.0",
"grunt": "^0.4.5",
"grunt-browserify": "^4.0.1",
"grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-connect": "^0.11.2",
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-jshint": "^0.11.3",
"grunt-contrib-uglify": "^0.11.0",
"grunt-eslint": "^20.0.0",
"grunt-gitinfo": "^0.1.7",
"grunt-mocha": "1.0.4",
"grunt-release": "^0.13.0",
"grunt-s3": "0.2.0-alpha.3",
"grunt-sri": "mattrobenolt/grunt-sri#pretty",
"husky": "^0.14.3",
"jquery": "^2.1.4",
"lint-staged": "^4.0.4",
"lodash": "^3.10.1",
"mocha": "2.5.3",
"mocha-chrome": "^0.2.1",
"prettier": "^1.6.1",
"proxyquireify": "^3.0.2",
"sinon": "1.7.3",
Expand Down
40 changes: 19 additions & 21 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,27 @@
<script src="../build/raven.test.js"></script>

<script>
if (!window.PHANTOMJS) {
(function(runner){
var failed = [];
(function(runner){
var failed = [];

runner.on('fail', function(test, err){
failed.push({
title: test.title,
fullTitle: test.fullTitle(),
error: {
message: err.message,
stack: err.stack
}
});
});
runner.on('fail', function(test, err){
failed.push({
title: test.title,
fullTitle: test.fullTitle(),
error: {
message: err.message,
stack: err.stack
}
});
});

runner.on('end', function(){
runner.stats.failed = failed;
if (typeof global !== "undefined") {
global.mochaResults = runner.stats;
}
});
})(mocha.run());
}
runner.on('end', function(){
runner.stats.failed = failed;
if (typeof global !== "undefined") {
global.mochaResults = runner.stats;
}
});
})(mocha.run());
</script>
</body>
</html>
36 changes: 17 additions & 19 deletions test/integration/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,26 @@
<script src="test.js"></script>

<script>
if (!window.PHANTOMJS) {
(function (runner) {
window.runner = runner;
var failed = [];
(function (runner) {
window.runner = runner;
var failed = [];

runner.on('fail', function (test, err) {
failed.push({
title: test.title,
fullTitle: test.fullTitle(),
error: {
message: err.message,
stack: err.stack
}
});
runner.on('fail', function (test, err) {
failed.push({
title: test.title,
fullTitle: test.fullTitle(),
error: {
message: err.message,
stack: err.stack
}
});
});

runner.on('end', function () {
runner.stats.failed = failed;
window.mochaResults = runner.stats;
});
})(mocha.run());
}
runner.on('end', function () {
runner.stats.failed = failed;
window.mochaResults = runner.stats;
});
})(mocha.run());
</script>
</body>
</html>
70 changes: 32 additions & 38 deletions test/integration/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ describe('integration', function() {

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

// stack:
// bar
Expand Down Expand Up @@ -918,46 +916,43 @@ describe('integration', function() {
);
});

// doesn't work in PhantomJS
if (!/PhantomJS/.test(window.navigator.userAgent)) {
it('should bail out if accessing the `type` and `target` properties of an event throw an exception', function(
done
) {
// see: https://github.com/getsentry/raven-js/issues/768
var iframe = this.iframe;

iframeExecute(
iframe,
done,
function() {
setTimeout(done);

// some browsers trigger onpopstate for load / reset breadcrumb state
Raven._breadcrumbs = [];
it('should bail out if accessing the `type` and `target` properties of an event throw an exception', function(
done
) {
// see: https://github.com/getsentry/raven-js/issues/768
var iframe = this.iframe;

// click <input/>
var evt = createMouseEvent();
iframeExecute(
iframe,
done,
function() {
setTimeout(done);

function kaboom() {
throw new Error('lol');
}
Object.defineProperty(evt, 'type', {get: kaboom});
Object.defineProperty(evt, 'target', {get: kaboom});
// some browsers trigger onpopstate for load / reset breadcrumb state
Raven._breadcrumbs = [];

var input = document.querySelector('.a'); // leaf node
input.dispatchEvent(evt);
},
function() {
var Raven = iframe.contentWindow.Raven,
breadcrumbs = Raven._breadcrumbs;
// click <input/>
var evt = createMouseEvent();

assert.equal(breadcrumbs.length, 1);
assert.equal(breadcrumbs[0].category, 'ui.click');
assert.equal(breadcrumbs[0].message, '<unknown>');
function kaboom() {
throw new Error('lol');
}
);
});
} // if PhantomJS
Object.defineProperty(evt, 'type', {get: kaboom});
Object.defineProperty(evt, 'target', {get: kaboom});

var input = document.querySelector('.a'); // leaf node
input.dispatchEvent(evt);
},
function() {
var Raven = iframe.contentWindow.Raven,
breadcrumbs = Raven._breadcrumbs;

assert.equal(breadcrumbs.length, 1);
assert.equal(breadcrumbs[0].category, 'ui.click');
assert.equal(breadcrumbs[0].message, '<unknown>');
}
);
});

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

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