Skip to content

Commit

Permalink
Integrated karma to make testing in-browser easier. Some tests are st…
Browse files Browse the repository at this point in the history
…ill failing. @jondeandres
  • Loading branch information
coryvirok committed Sep 12, 2015
1 parent d073ccd commit 835b528
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 16 deletions.
1 change: 1 addition & 0 deletions dist/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,7 @@
}
} catch (ex) {
//jquery source mentions firefox may error out while accessing the

//request members if there is a network error
//https://github.com/jquery/jquery/blob/a938d7b1282fc0e5c52502c225ae8f0cef219f0a/src/ajax/xhr.js#L111
var exc;
Expand Down
61 changes: 61 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Include the webpack config we use to build the tests.
// We export an array of webpack configurations from
// webpack.config.js so we only want the one for tests
// which is the 3rd element in the array.
//
var webpackConfig = require('./webpack.config.js')[2];
webpackConfig.devtool = 'inline-source-map';
delete webpackConfig.entry;
delete webpackConfig.output;

module.exports = function (config) {
config.set({
browsers: ['Chrome'],

// karma only needs to know about the test bundle
files: [
// Files that the tests will load
{
pattern: 'dist/rollbar.js',
included: false,
served: true,
watched: false
},

'test/*.test.js',
],

frameworks: ['chai', 'mocha', 'sinon', 'jquery-1.8.3'],

plugins: [
'karma-chai',
'karma-chrome-launcher',
'karma-jquery',
'karma-mocha',
'karma-mocha-reporter',
'karma-phantomjs-launcher',
'karma-sinon',
'karma-sourcemap-loader',
'karma-webpack',
],

// run the bundle through the webpack and sourcemap plugins
preprocessors: {
'test/*.test.js': ['webpack', 'sourcemap']
},

proxies: {
'/dist/rollbar.js': '/base/dist/rollbar.js'
},

reporters: ['mocha'],

singleRun: false,

webpack: webpackConfig,

webpackMiddleware: {
noInfo: true
}
});
};
16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
},
"main": "dist/rollbar.umd.nojson.min.js",
"devDependencies": {
"babel-core": "^5.8.24",
"babel-eslint": "^4.1.1",
"babel-loader": "^5.3.2",
"chai": "~1.8.1",
"chalk": "^1.1.1",
"error-stack-parser": "git:https://github.com/rollbar/error-stack-parser.git",
"eslint": "^1.3.1",
"eslint-loader": "^1.0.0",
Expand All @@ -30,10 +33,21 @@
"grunt-saucelabs": "~4.1.2",
"grunt-tagrelease": "~0.3.0",
"grunt-webpack": "1.0.8",
"jquery-mockjax": "^2.0.1",
"karma": "^0.13.9",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^0.2.0",
"karma-jquery": "^0.1.0",
"karma-mocha": "^0.2.0",
"karma-mocha-reporter": "^1.1.1",
"karma-phantomjs-launcher": "^0.2.1",
"karma-sinon": "^1.0.4",
"karma-sourcemap-loader": "^0.3.5",
"karma-webpack": "^1.7.0",
"mocha": "^1.21.4",
"mocha-phantomjs": "^3.5.0",
"node-libs-browser": "^0.5.2",
"phantomjs": "1.9.7-15",
"phantomjs": "^1.9.18",
"script-loader": "0.6.1",
"semver": "~2.2.1",
"sinon": "~1.7.3",
Expand Down
9 changes: 6 additions & 3 deletions test/plugins/jquery.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
var mockjax = require('jquery-mockjax');
$.mockjax = mockjax;

var expect = chai.expect;

it("should call the second attached callback", function() {
it('should call the second attached callback', function() {
// Variable to store result;
var result;

// Create an element
var $div = $("<div></div>");
var $div = $('<div></div>');

// Create a callback function creator
var result = [];
Expand Down Expand Up @@ -41,7 +44,7 @@ it("should call the second attached callback", function() {
});


it("should collect ajax fields", function(done) {
it('should collect ajax fields', function(done) {
this.timeout(1000);

var url = 'asdf';
Expand Down
6 changes: 5 additions & 1 deletion test/shim.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ var config = {


describe('window.Rollbar.init()', function() {
// Create a div to use in the tests
var eventDiv = window.document.createElement('div');
eventDiv.setAttribute('id', 'event-div');
window.document.body.appendChild(eventDiv);

it('should set window.Rollbar to the shim', function(done) {
// window.Rollbar will be exposed as a function since shim has
Expand Down Expand Up @@ -380,7 +384,7 @@ describe('window.Rollbar.loadFull()', function() {
var callback = snippetCallback(origShim, config);

// Brings in the full rollbar.js file into the DOM
window.Rollbar.loadFull(window, document, true, {rollbarJsUrl: '../dist/rollbar.js'}, callback);
window.Rollbar.loadFull(window, document, true, {rollbarJsUrl: 'dist/rollbar.js'}, callback);

// Wait before checking window.Rollbar
function test() {
Expand Down
22 changes: 11 additions & 11 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ var pluginConfig = {
var testsConfig = {
name: 'tests',
entry: {
browserify: './test/bundles/browserify.js',
error_parser: './test/bundles/error_parser.js',
json: './test/bundles/json.js',
mootools: './test/bundles/mootools.js',
notifier: './test/bundles/notifier.js',
'notifier-ratelimit': './test/bundles/notifier.ratelimit.js',
rollbar: './test/bundles/rollbar.js',
shim: './test/bundles/shim.js',
shimalias: './test/bundles/shimalias.js',
util: './test/bundles/util.js',
xhr: './test/bundles/xhr.js',
browserify: 'test/bundles/browserify.js',
error_parser: 'test/bundles/error_parser.js',
json: 'test/bundles/json.js',
mootools: 'test/bundles/mootools.js',
notifier: 'test/bundles/notifier.js',
'notifier-ratelimit': 'test/bundles/notifier.ratelimit.js',
rollbar: 'test/bundles/rollbar.js',
shim: 'test/bundles/shim.js',
shimalias: 'test/bundles/shimalias.js',
util: 'test/bundles/util.js',
xhr: 'test/bundles/xhr.js',
},
plugins: [defaultsPlugin],
output: {
Expand Down

0 comments on commit 835b528

Please sign in to comment.