Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions .travis.yml
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
15 changes: 11 additions & 4 deletions src/raven.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -1369,7 +1369,7 @@ Raven.prototype = {
var frames = [];
if (stackInfo.stack && stackInfo.stack.length) {
each(stackInfo.stack, function(i, stack) {
var frame = self._normalizeFrame(stack);
var frame = self._normalizeFrame(stack, stackInfo.url);
if (frame) {
frames.push(frame);
}
Expand All@@ -1386,9 +1386,7 @@ Raven.prototype = {
return frames;
},

_normalizeFrame: function(frame) {
if (!frame.url) return;

_normalizeFrame: function(frame, stackInfoUrl) {
// normalize the frames data
var normalized = {
filename: frame.url,
Expand All@@ -1397,6 +1395,15 @@ Raven.prototype = {
function: frame.func || '?'
};

// Case when we don't have any information about the error
// E.g. throwing a string or raw object, instead of an `Error` in Firefox
// Generating synthetic error doesn't add any value here
//
// We should probably somehow let a user know that they should fix their code
if (!frame.url) {
normalized.filename = stackInfoUrl; // fallback to whole stacks url from onerror handler
}

normalized.in_app = !// determine if an exception came from outside of our app
// first we check the global includePaths list.
(
Expand Down
40 changes: 19 additions & 21 deletions test/index.html
Original file line numberDiff line numberDiff 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>
64 changes: 64 additions & 0 deletions test/integration/frame.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,70 @@
clearTimeout(id);
};
}());

/**
* Custom event factories for cross-browser compatibility
*
* Gecko browsers are using non-standard `initKeyEvent`, where others implemented `initKeyboardEvent`.
* To make it more consistent, we try to use standardized `MouseEvent`/`KeyboardEvent` now
* and fallback to older implementations for legacy browsers only.
*
* See deprecation notes:
* https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyboardEvent
*
* References:
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent#Specifications
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Specifications
*/
function createMouseEvent (options) {
var options = {
bubbles: true,
cancelable: true,
view: window
}

if ('MouseEvent' in window) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wouldn't hurt to comment these branches with the browsers they're active on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these factories are way better though 👍

return new MouseEvent('click', options);
} else {
var event = document.createEvent('MouseEvent');
event.initMouseEvent(
'click',
options.bubbles,
options.cancelable,
options.view
);

return event;
}
}

function createKeyboardEvent (key) {
var options = {
bubbles: true,
cancelable: true,
view: window,
key: key || 'a'
}
options.charCode = options.key.charCodeAt();

if ('KeyboardEvent' in window) {
return new KeyboardEvent('keypress', options);
} else {
var event = document.createEvent('KeyboardEvent');
event.initKeyboardEvent(
'keypress',
options.bubbles,
options.cancelable,
options.view,
options.key,
options.charCode
);

return event;
}
}
</script>
<script src="../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../build/raven.js"></script>
Expand Down
36 changes: 17 additions & 19 deletions test/integration/index.html
Original file line numberDiff line numberDiff 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>
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions .travis.yml
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
15 changes: 11 additions & 4 deletions src/raven.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -1369,7 +1369,7 @@ Raven.prototype = {
var frames = [];
if (stackInfo.stack && stackInfo.stack.length) {
each(stackInfo.stack, function(i, stack) {
var frame = self._normalizeFrame(stack);
var frame = self._normalizeFrame(stack, stackInfo.url);
if (frame) {
frames.push(frame);
}
Expand All@@ -1386,9 +1386,7 @@ Raven.prototype = {
return frames;
},

_normalizeFrame: function(frame) {
if (!frame.url) return;

_normalizeFrame: function(frame, stackInfoUrl) {
// normalize the frames data
var normalized = {
filename: frame.url,
Expand All@@ -1397,6 +1395,15 @@ Raven.prototype = {
function: frame.func || '?'
};

// Case when we don't have any information about the error
// E.g. throwing a string or raw object, instead of an `Error` in Firefox
// Generating synthetic error doesn't add any value here
//
// We should probably somehow let a user know that they should fix their code
if (!frame.url) {
normalized.filename = stackInfoUrl; // fallback to whole stacks url from onerror handler
}

normalized.in_app = !// determine if an exception came from outside of our app
// first we check the global includePaths list.
(
Expand Down
40 changes: 19 additions & 21 deletions test/index.html
Original file line numberDiff line numberDiff 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>
64 changes: 64 additions & 0 deletions test/integration/frame.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,70 @@
clearTimeout(id);
};
}());

/**
* Custom event factories for cross-browser compatibility
*
* Gecko browsers are using non-standard `initKeyEvent`, where others implemented `initKeyboardEvent`.
* To make it more consistent, we try to use standardized `MouseEvent`/`KeyboardEvent` now
* and fallback to older implementations for legacy browsers only.
*
* See deprecation notes:
* https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyboardEvent
*
* References:
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent#Specifications
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Specifications
*/
function createMouseEvent (options) {
var options = {
bubbles: true,
cancelable: true,
view: window
}

if ('MouseEvent' in window) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wouldn't hurt to comment these branches with the browsers they're active on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these factories are way better though 👍

return new MouseEvent('click', options);
} else {
var event = document.createEvent('MouseEvent');
event.initMouseEvent(
'click',
options.bubbles,
options.cancelable,
options.view
);

return event;
}
}

function createKeyboardEvent (key) {
var options = {
bubbles: true,
cancelable: true,
view: window,
key: key || 'a'
}
options.charCode = options.key.charCodeAt();

if ('KeyboardEvent' in window) {
return new KeyboardEvent('keypress', options);
} else {
var event = document.createEvent('KeyboardEvent');
event.initKeyboardEvent(
'keypress',
options.bubbles,
options.cancelable,
options.view,
options.key,
options.charCode
);

return event;
}
}
</script>
<script src="../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../build/raven.js"></script>
Expand Down
36 changes: 17 additions & 19 deletions test/integration/index.html
Original file line numberDiff line numberDiff 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>
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions .travis.yml
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
15 changes: 11 additions & 4 deletions src/raven.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -1369,7 +1369,7 @@ Raven.prototype = {
var frames = [];
if (stackInfo.stack && stackInfo.stack.length) {
each(stackInfo.stack, function(i, stack) {
var frame = self._normalizeFrame(stack);
var frame = self._normalizeFrame(stack, stackInfo.url);
if (frame) {
frames.push(frame);
}
Expand All@@ -1386,9 +1386,7 @@ Raven.prototype = {
return frames;
},

_normalizeFrame: function(frame) {
if (!frame.url) return;

_normalizeFrame: function(frame, stackInfoUrl) {
// normalize the frames data
var normalized = {
filename: frame.url,
Expand All@@ -1397,6 +1395,15 @@ Raven.prototype = {
function: frame.func || '?'
};

// Case when we don't have any information about the error
// E.g. throwing a string or raw object, instead of an `Error` in Firefox
// Generating synthetic error doesn't add any value here
//
// We should probably somehow let a user know that they should fix their code
if (!frame.url) {
normalized.filename = stackInfoUrl; // fallback to whole stacks url from onerror handler
}

normalized.in_app = !// determine if an exception came from outside of our app
// first we check the global includePaths list.
(
Expand Down
40 changes: 19 additions & 21 deletions test/index.html
Original file line numberDiff line numberDiff 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>
64 changes: 64 additions & 0 deletions test/integration/frame.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,70 @@
clearTimeout(id);
};
}());

/**
* Custom event factories for cross-browser compatibility
*
* Gecko browsers are using non-standard `initKeyEvent`, where others implemented `initKeyboardEvent`.
* To make it more consistent, we try to use standardized `MouseEvent`/`KeyboardEvent` now
* and fallback to older implementations for legacy browsers only.
*
* See deprecation notes:
* https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyboardEvent
*
* References:
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent#Specifications
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Specifications
*/
function createMouseEvent (options) {
var options = {
bubbles: true,
cancelable: true,
view: window
}

if ('MouseEvent' in window) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wouldn't hurt to comment these branches with the browsers they're active on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these factories are way better though 👍

return new MouseEvent('click', options);
} else {
var event = document.createEvent('MouseEvent');
event.initMouseEvent(
'click',
options.bubbles,
options.cancelable,
options.view
);

return event;
}
}

function createKeyboardEvent (key) {
var options = {
bubbles: true,
cancelable: true,
view: window,
key: key || 'a'
}
options.charCode = options.key.charCodeAt();

if ('KeyboardEvent' in window) {
return new KeyboardEvent('keypress', options);
} else {
var event = document.createEvent('KeyboardEvent');
event.initKeyboardEvent(
'keypress',
options.bubbles,
options.cancelable,
options.view,
options.key,
options.charCode
);

return event;
}
}
</script>
<script src="../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../build/raven.js"></script>
Expand Down
36 changes: 17 additions & 19 deletions test/integration/index.html
Original file line numberDiff line numberDiff 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>
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions .travis.yml
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
15 changes: 11 additions & 4 deletions src/raven.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -1369,7 +1369,7 @@ Raven.prototype = {
var frames = [];
if (stackInfo.stack && stackInfo.stack.length) {
each(stackInfo.stack, function(i, stack) {
var frame = self._normalizeFrame(stack);
var frame = self._normalizeFrame(stack, stackInfo.url);
if (frame) {
frames.push(frame);
}
Expand All@@ -1386,9 +1386,7 @@ Raven.prototype = {
return frames;
},

_normalizeFrame: function(frame) {
if (!frame.url) return;

_normalizeFrame: function(frame, stackInfoUrl) {
// normalize the frames data
var normalized = {
filename: frame.url,
Expand All@@ -1397,6 +1395,15 @@ Raven.prototype = {
function: frame.func || '?'
};

// Case when we don't have any information about the error
// E.g. throwing a string or raw object, instead of an `Error` in Firefox
// Generating synthetic error doesn't add any value here
//
// We should probably somehow let a user know that they should fix their code
if (!frame.url) {
normalized.filename = stackInfoUrl; // fallback to whole stacks url from onerror handler
}

normalized.in_app = !// determine if an exception came from outside of our app
// first we check the global includePaths list.
(
Expand Down
40 changes: 19 additions & 21 deletions test/index.html
Original file line numberDiff line numberDiff 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>
64 changes: 64 additions & 0 deletions test/integration/frame.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,70 @@
clearTimeout(id);
};
}());

/**
* Custom event factories for cross-browser compatibility
*
* Gecko browsers are using non-standard `initKeyEvent`, where others implemented `initKeyboardEvent`.
* To make it more consistent, we try to use standardized `MouseEvent`/`KeyboardEvent` now
* and fallback to older implementations for legacy browsers only.
*
* See deprecation notes:
* https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyboardEvent
*
* References:
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent#Specifications
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Specifications
*/
function createMouseEvent (options) {
var options = {
bubbles: true,
cancelable: true,
view: window
}

if ('MouseEvent' in window) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wouldn't hurt to comment these branches with the browsers they're active on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these factories are way better though 👍

return new MouseEvent('click', options);
} else {
var event = document.createEvent('MouseEvent');
event.initMouseEvent(
'click',
options.bubbles,
options.cancelable,
options.view
);

return event;
}
}

function createKeyboardEvent (key) {
var options = {
bubbles: true,
cancelable: true,
view: window,
key: key || 'a'
}
options.charCode = options.key.charCodeAt();

if ('KeyboardEvent' in window) {
return new KeyboardEvent('keypress', options);
} else {
var event = document.createEvent('KeyboardEvent');
event.initKeyboardEvent(
'keypress',
options.bubbles,
options.cancelable,
options.view,
options.key,
options.charCode
);

return event;
}
}
</script>
<script src="../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../build/raven.js"></script>
Expand Down
36 changes: 17 additions & 19 deletions test/integration/index.html
Original file line numberDiff line numberDiff 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>
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions .travis.yml
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
15 changes: 11 additions & 4 deletions src/raven.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -1369,7 +1369,7 @@ Raven.prototype = {
var frames = [];
if (stackInfo.stack && stackInfo.stack.length) {
each(stackInfo.stack, function(i, stack) {
var frame = self._normalizeFrame(stack);
var frame = self._normalizeFrame(stack, stackInfo.url);
if (frame) {
frames.push(frame);
}
Expand All@@ -1386,9 +1386,7 @@ Raven.prototype = {
return frames;
},

_normalizeFrame: function(frame) {
if (!frame.url) return;

_normalizeFrame: function(frame, stackInfoUrl) {
// normalize the frames data
var normalized = {
filename: frame.url,
Expand All@@ -1397,6 +1395,15 @@ Raven.prototype = {
function: frame.func || '?'
};

// Case when we don't have any information about the error
// E.g. throwing a string or raw object, instead of an `Error` in Firefox
// Generating synthetic error doesn't add any value here
//
// We should probably somehow let a user know that they should fix their code
if (!frame.url) {
normalized.filename = stackInfoUrl; // fallback to whole stacks url from onerror handler
}

normalized.in_app = !// determine if an exception came from outside of our app
// first we check the global includePaths list.
(
Expand Down
40 changes: 19 additions & 21 deletions test/index.html
Original file line numberDiff line numberDiff 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>
64 changes: 64 additions & 0 deletions test/integration/frame.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,70 @@
clearTimeout(id);
};
}());

/**
* Custom event factories for cross-browser compatibility
*
* Gecko browsers are using non-standard `initKeyEvent`, where others implemented `initKeyboardEvent`.
* To make it more consistent, we try to use standardized `MouseEvent`/`KeyboardEvent` now
* and fallback to older implementations for legacy browsers only.
*
* See deprecation notes:
* https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyboardEvent
*
* References:
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent#Specifications
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Specifications
*/
function createMouseEvent (options) {
var options = {
bubbles: true,
cancelable: true,
view: window
}

if ('MouseEvent' in window) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wouldn't hurt to comment these branches with the browsers they're active on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these factories are way better though 👍

return new MouseEvent('click', options);
} else {
var event = document.createEvent('MouseEvent');
event.initMouseEvent(
'click',
options.bubbles,
options.cancelable,
options.view
);

return event;
}
}

function createKeyboardEvent (key) {
var options = {
bubbles: true,
cancelable: true,
view: window,
key: key || 'a'
}
options.charCode = options.key.charCodeAt();

if ('KeyboardEvent' in window) {
return new KeyboardEvent('keypress', options);
} else {
var event = document.createEvent('KeyboardEvent');
event.initKeyboardEvent(
'keypress',
options.bubbles,
options.cancelable,
options.view,
options.key,
options.charCode
);

return event;
}
}
</script>
<script src="../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../build/raven.js"></script>
Expand Down
36 changes: 17 additions & 19 deletions test/integration/index.html
Original file line numberDiff line numberDiff 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>
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions .travis.yml
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
15 changes: 11 additions & 4 deletions src/raven.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -1369,7 +1369,7 @@ Raven.prototype = {
var frames = [];
if (stackInfo.stack && stackInfo.stack.length) {
each(stackInfo.stack, function(i, stack) {
var frame = self._normalizeFrame(stack);
var frame = self._normalizeFrame(stack, stackInfo.url);
if (frame) {
frames.push(frame);
}
Expand All@@ -1386,9 +1386,7 @@ Raven.prototype = {
return frames;
},

_normalizeFrame: function(frame) {
if (!frame.url) return;

_normalizeFrame: function(frame, stackInfoUrl) {
// normalize the frames data
var normalized = {
filename: frame.url,
Expand All@@ -1397,6 +1395,15 @@ Raven.prototype = {
function: frame.func || '?'
};

// Case when we don't have any information about the error
// E.g. throwing a string or raw object, instead of an `Error` in Firefox
// Generating synthetic error doesn't add any value here
//
// We should probably somehow let a user know that they should fix their code
if (!frame.url) {
normalized.filename = stackInfoUrl; // fallback to whole stacks url from onerror handler
}

normalized.in_app = !// determine if an exception came from outside of our app
// first we check the global includePaths list.
(
Expand Down
40 changes: 19 additions & 21 deletions test/index.html
Original file line numberDiff line numberDiff 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>
64 changes: 64 additions & 0 deletions test/integration/frame.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,70 @@
clearTimeout(id);
};
}());

/**
* Custom event factories for cross-browser compatibility
*
* Gecko browsers are using non-standard `initKeyEvent`, where others implemented `initKeyboardEvent`.
* To make it more consistent, we try to use standardized `MouseEvent`/`KeyboardEvent` now
* and fallback to older implementations for legacy browsers only.
*
* See deprecation notes:
* https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyboardEvent
*
* References:
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent#Specifications
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Specifications
*/
function createMouseEvent (options) {
var options = {
bubbles: true,
cancelable: true,
view: window
}

if ('MouseEvent' in window) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wouldn't hurt to comment these branches with the browsers they're active on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these factories are way better though 👍

return new MouseEvent('click', options);
} else {
var event = document.createEvent('MouseEvent');
event.initMouseEvent(
'click',
options.bubbles,
options.cancelable,
options.view
);

return event;
}
}

function createKeyboardEvent (key) {
var options = {
bubbles: true,
cancelable: true,
view: window,
key: key || 'a'
}
options.charCode = options.key.charCodeAt();

if ('KeyboardEvent' in window) {
return new KeyboardEvent('keypress', options);
} else {
var event = document.createEvent('KeyboardEvent');
event.initKeyboardEvent(
'keypress',
options.bubbles,
options.cancelable,
options.view,
options.key,
options.charCode
);

return event;
}
}
</script>
<script src="../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../build/raven.js"></script>
Expand Down
36 changes: 17 additions & 19 deletions test/integration/index.html
Original file line numberDiff line numberDiff 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>
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions .travis.yml
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
15 changes: 11 additions & 4 deletions src/raven.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -1369,7 +1369,7 @@ Raven.prototype = {
var frames = [];
if (stackInfo.stack && stackInfo.stack.length) {
each(stackInfo.stack, function(i, stack) {
var frame = self._normalizeFrame(stack);
var frame = self._normalizeFrame(stack, stackInfo.url);
if (frame) {
frames.push(frame);
}
Expand All@@ -1386,9 +1386,7 @@ Raven.prototype = {
return frames;
},

_normalizeFrame: function(frame) {
if (!frame.url) return;

_normalizeFrame: function(frame, stackInfoUrl) {
// normalize the frames data
var normalized = {
filename: frame.url,
Expand All@@ -1397,6 +1395,15 @@ Raven.prototype = {
function: frame.func || '?'
};

// Case when we don't have any information about the error
// E.g. throwing a string or raw object, instead of an `Error` in Firefox
// Generating synthetic error doesn't add any value here
//
// We should probably somehow let a user know that they should fix their code
if (!frame.url) {
normalized.filename = stackInfoUrl; // fallback to whole stacks url from onerror handler
}

normalized.in_app = !// determine if an exception came from outside of our app
// first we check the global includePaths list.
(
Expand Down
40 changes: 19 additions & 21 deletions test/index.html
Original file line numberDiff line numberDiff 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>
64 changes: 64 additions & 0 deletions test/integration/frame.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,70 @@
clearTimeout(id);
};
}());

/**
* Custom event factories for cross-browser compatibility
*
* Gecko browsers are using non-standard `initKeyEvent`, where others implemented `initKeyboardEvent`.
* To make it more consistent, we try to use standardized `MouseEvent`/`KeyboardEvent` now
* and fallback to older implementations for legacy browsers only.
*
* See deprecation notes:
* https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyboardEvent
*
* References:
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent#Specifications
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Specifications
*/
function createMouseEvent (options) {
var options = {
bubbles: true,
cancelable: true,
view: window
}

if ('MouseEvent' in window) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wouldn't hurt to comment these branches with the browsers they're active on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these factories are way better though 👍

return new MouseEvent('click', options);
} else {
var event = document.createEvent('MouseEvent');
event.initMouseEvent(
'click',
options.bubbles,
options.cancelable,
options.view
);

return event;
}
}

function createKeyboardEvent (key) {
var options = {
bubbles: true,
cancelable: true,
view: window,
key: key || 'a'
}
options.charCode = options.key.charCodeAt();

if ('KeyboardEvent' in window) {
return new KeyboardEvent('keypress', options);
} else {
var event = document.createEvent('KeyboardEvent');
event.initKeyboardEvent(
'keypress',
options.bubbles,
options.cancelable,
options.view,
options.key,
options.charCode
);

return event;
}
}
</script>
<script src="../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../build/raven.js"></script>
Expand Down
36 changes: 17 additions & 19 deletions test/integration/index.html
Original file line numberDiff line numberDiff 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>
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions .travis.yml
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
15 changes: 11 additions & 4 deletions src/raven.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -1369,7 +1369,7 @@ Raven.prototype = {
var frames = [];
if (stackInfo.stack && stackInfo.stack.length) {
each(stackInfo.stack, function(i, stack) {
var frame = self._normalizeFrame(stack);
var frame = self._normalizeFrame(stack, stackInfo.url);
if (frame) {
frames.push(frame);
}
Expand All@@ -1386,9 +1386,7 @@ Raven.prototype = {
return frames;
},

_normalizeFrame: function(frame) {
if (!frame.url) return;

_normalizeFrame: function(frame, stackInfoUrl) {
// normalize the frames data
var normalized = {
filename: frame.url,
Expand All@@ -1397,6 +1395,15 @@ Raven.prototype = {
function: frame.func || '?'
};

// Case when we don't have any information about the error
// E.g. throwing a string or raw object, instead of an `Error` in Firefox
// Generating synthetic error doesn't add any value here
//
// We should probably somehow let a user know that they should fix their code
if (!frame.url) {
normalized.filename = stackInfoUrl; // fallback to whole stacks url from onerror handler
}

normalized.in_app = !// determine if an exception came from outside of our app
// first we check the global includePaths list.
(
Expand Down
40 changes: 19 additions & 21 deletions test/index.html
Original file line numberDiff line numberDiff 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>
64 changes: 64 additions & 0 deletions test/integration/frame.html
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,70 @@
clearTimeout(id);
};
}());

/**
* Custom event factories for cross-browser compatibility
*
* Gecko browsers are using non-standard `initKeyEvent`, where others implemented `initKeyboardEvent`.
* To make it more consistent, we try to use standardized `MouseEvent`/`KeyboardEvent` now
* and fallback to older implementations for legacy browsers only.
*
* See deprecation notes:
* https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyEvent
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/initKeyboardEvent
*
* References:
* https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent#Specifications
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Specifications
*/
function createMouseEvent (options) {
var options = {
bubbles: true,
cancelable: true,
view: window
}

if ('MouseEvent' in window) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wouldn't hurt to comment these branches with the browsers they're active on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these factories are way better though 👍

return new MouseEvent('click', options);
} else {
var event = document.createEvent('MouseEvent');
event.initMouseEvent(
'click',
options.bubbles,
options.cancelable,
options.view
);

return event;
}
}

function createKeyboardEvent (key) {
var options = {
bubbles: true,
cancelable: true,
view: window,
key: key || 'a'
}
options.charCode = options.key.charCodeAt();

if ('KeyboardEvent' in window) {
return new KeyboardEvent('keypress', options);
} else {
var event = document.createEvent('KeyboardEvent');
event.initKeyboardEvent(
'keypress',
options.bubbles,
options.cancelable,
options.view,
options.key,
options.charCode
);

return event;
}
}
</script>
<script src="../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../build/raven.js"></script>
Expand Down
36 changes: 17 additions & 19 deletions test/integration/index.html
Original file line numberDiff line numberDiff 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>
Loading