[ci skip] Index and singleton improvements with some more unit, more to come
This commit is contained in:
parent
cfd3d0fd37
commit
13b60eb75b
|
@ -1,10 +1,12 @@
|
|||
import RavenConfig from './raven_config';
|
||||
|
||||
RavenConfig.init({
|
||||
const index = RavenConfig.init.bind(RavenConfig, {
|
||||
sentryDsn: gon.sentry_dsn,
|
||||
currentUserId: gon.current_user_id,
|
||||
whitelistUrls: [gon.gitlab_url],
|
||||
isProduction: gon.is_production,
|
||||
});
|
||||
|
||||
export default RavenConfig;
|
||||
index();
|
||||
|
||||
export default index;
|
||||
|
|
|
@ -1,32 +1,35 @@
|
|||
import Raven from 'raven-js';
|
||||
import $ from 'jquery';
|
||||
|
||||
class RavenConfig {
|
||||
static init(options = {}) {
|
||||
const RavenConfig = {
|
||||
init(options = {}) {
|
||||
this.options = options;
|
||||
|
||||
this.configure();
|
||||
this.bindRavenErrors();
|
||||
if (this.options.currentUserId) this.setUser();
|
||||
}
|
||||
|
||||
static configure() {
|
||||
return this;
|
||||
},
|
||||
|
||||
configure() {
|
||||
Raven.config(this.options.sentryDsn, {
|
||||
whitelistUrls: this.options.whitelistUrls,
|
||||
environment: this.options.isProduction ? 'production' : 'development',
|
||||
}).install();
|
||||
}
|
||||
},
|
||||
|
||||
static setUser() {
|
||||
setUser() {
|
||||
Raven.setUserContext({
|
||||
id: this.options.currentUserId,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
static bindRavenErrors() {
|
||||
bindRavenErrors() {
|
||||
$(document).on('ajaxError.raven', this.handleRavenErrors);
|
||||
}
|
||||
},
|
||||
|
||||
static handleRavenErrors(event, req, config, err) {
|
||||
handleRavenErrors(event, req, config, err) {
|
||||
const error = err || req.statusText;
|
||||
|
||||
Raven.captureMessage(error, {
|
||||
|
@ -40,7 +43,7 @@ class RavenConfig {
|
|||
event,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export default RavenConfig;
|
||||
|
|
|
@ -3,13 +3,20 @@ require 'spec_helper'
|
|||
describe SentryHelper do
|
||||
describe '#sentry_dsn_public' do
|
||||
it 'returns nil if no sentry_dsn is set' do
|
||||
allow(ApplicationSetting.current).to receive(:sentry_dsn).and_return(nil)
|
||||
expect(helper.sentry_dsn_public).to eq(nil)
|
||||
mock_sentry_dsn(nil)
|
||||
|
||||
expect(helper.sentry_dsn_public).to eq nil
|
||||
end
|
||||
|
||||
it 'returns the uri string with no password if sentry_dsn is set' do
|
||||
allow(ApplicationSetting.current).to receive(:sentry_dsn).and_return('https://test:dsn@host/path')
|
||||
expect(helper.sentry_dsn_public).to eq('https://test@host/path')
|
||||
mock_sentry_dsn('https://test:dsn@host/path')
|
||||
|
||||
expect(helper.sentry_dsn_public).to eq 'https://test@host/path'
|
||||
end
|
||||
end
|
||||
|
||||
def mock_sentry_dsn(value)
|
||||
allow_message_expectations_on_nil
|
||||
allow(ApplicationSetting.current).to receive(:sentry_dsn).and_return(value)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,41 @@
|
|||
import RavenConfig from '~/raven/index';
|
||||
import RavenConfig from '~/raven/raven_config';
|
||||
import index from '~/raven/index';
|
||||
|
||||
describe('RavenConfig options', () => {
|
||||
it('should set sentryDsn');
|
||||
fdescribe('RavenConfig options', () => {
|
||||
let sentryDsn;
|
||||
let currentUserId;
|
||||
let gitlabUrl;
|
||||
let isProduction;
|
||||
let indexReturnValue;
|
||||
|
||||
it('should set currentUserId');
|
||||
beforeEach(() => {
|
||||
sentryDsn = 'sentryDsn';
|
||||
currentUserId = 'currentUserId';
|
||||
gitlabUrl = 'gitlabUrl';
|
||||
isProduction = 'isProduction';
|
||||
|
||||
it('should set whitelistUrls');
|
||||
window.gon = {
|
||||
sentry_dsn: sentryDsn,
|
||||
current_user_id: currentUserId,
|
||||
gitlab_url: gitlabUrl,
|
||||
is_production: isProduction,
|
||||
};
|
||||
|
||||
it('should set isProduction');
|
||||
spyOn(RavenConfig.init, 'bind');
|
||||
|
||||
indexReturnValue = index();
|
||||
});
|
||||
|
||||
it('should init with .sentryDsn, .currentUserId, .whitelistUrls and .isProduction', () => {
|
||||
expect(RavenConfig.init.bind).toHaveBeenCalledWith(RavenConfig, {
|
||||
sentryDsn,
|
||||
currentUserId,
|
||||
whitelistUrls: [gitlabUrl],
|
||||
isProduction,
|
||||
});
|
||||
});
|
||||
|
||||
it('should return RavenConfig', () => {
|
||||
expect(indexReturnValue).toBe(RavenConfig);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import Raven from 'raven-js';
|
||||
import RavenConfig from '~/raven/raven_config';
|
||||
import ClassSpecHelper from '../helpers/class_spec_helper';
|
||||
|
||||
fdescribe('RavenConfig', () => {
|
||||
describe('RavenConfig', () => {
|
||||
describe('init', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(RavenConfig, 'configure');
|
||||
|
@ -10,8 +9,6 @@ fdescribe('RavenConfig', () => {
|
|||
spyOn(RavenConfig, 'setUser');
|
||||
});
|
||||
|
||||
ClassSpecHelper.itShouldBeAStaticMethod(RavenConfig, 'init');
|
||||
|
||||
describe('when called', () => {
|
||||
let options;
|
||||
|
||||
|
@ -58,8 +55,6 @@ fdescribe('RavenConfig', () => {
|
|||
});
|
||||
|
||||
describe('configure', () => {
|
||||
ClassSpecHelper.itShouldBeAStaticMethod(RavenConfig, 'configure');
|
||||
|
||||
describe('when called', () => {
|
||||
let options;
|
||||
let raven;
|
||||
|
@ -112,24 +107,18 @@ fdescribe('RavenConfig', () => {
|
|||
});
|
||||
|
||||
describe('setUser', () => {
|
||||
ClassSpecHelper.itShouldBeAStaticMethod(RavenConfig, 'setUser');
|
||||
|
||||
describe('when called', () => {
|
||||
beforeEach(() => {});
|
||||
});
|
||||
});
|
||||
|
||||
describe('bindRavenErrors', () => {
|
||||
ClassSpecHelper.itShouldBeAStaticMethod(RavenConfig, 'bindRavenErrors');
|
||||
|
||||
describe('when called', () => {
|
||||
beforeEach(() => {});
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleRavenErrors', () => {
|
||||
ClassSpecHelper.itShouldBeAStaticMethod(RavenConfig, 'handleRavenErrors');
|
||||
|
||||
describe('when called', () => {
|
||||
beforeEach(() => {});
|
||||
});
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
/* eslint-disable space-before-function-paren */
|
||||
// PhantomJS (Teaspoons default driver) doesn't have support for
|
||||
// Function.prototype.bind, which has caused confusion. Use this polyfill to
|
||||
// avoid the confusion.
|
||||
/*= require support/bind-poly */
|
||||
|
||||
// You can require your own javascript files here. By default this will include
|
||||
// everything in application, however you may get better load performance if you
|
||||
// require the specific files that are being used in the spec that tests them.
|
||||
/*= require jquery */
|
||||
/*= require jquery.turbolinks */
|
||||
/*= require bootstrap */
|
||||
/*= require underscore */
|
||||
/*= require es6-promise.auto */
|
||||
|
||||
// Teaspoon includes some support files, but you can use anything from your own
|
||||
// support path too.
|
||||
// require support/jasmine-jquery-1.7.0
|
||||
// require support/jasmine-jquery-2.0.0
|
||||
/*= require support/jasmine-jquery-2.1.0 */
|
||||
|
||||
// require support/sinon
|
||||
// require support/your-support-file
|
||||
// Deferring execution
|
||||
// If you're using CommonJS, RequireJS or some other asynchronous library you can
|
||||
// defer execution. Call Teaspoon.execute() after everything has been loaded.
|
||||
// Simple example of a timeout:
|
||||
// Teaspoon.defer = true
|
||||
// setTimeout(Teaspoon.execute, 1000)
|
||||
// Matching files
|
||||
// By default Teaspoon will look for files that match
|
||||
// _spec.{js,js.es6}. Add a filename_spec.js file in your spec path
|
||||
// and it'll be included in the default suite automatically. If you want to
|
||||
// customize suites, check out the configuration in teaspoon_env.rb
|
||||
// Manifest
|
||||
// If you'd rather require your spec files manually (to control order for
|
||||
// instance) you can disable the suite matcher in the configuration and use this
|
||||
// file as a manifest.
|
||||
// For more information: http://github.com/modeset/teaspoon
|
||||
|
||||
// set our fixtures path
|
||||
jasmine.getFixtures().fixturesPath = '/teaspoon/fixtures';
|
||||
jasmine.getJSONFixtures().fixturesPath = '/teaspoon/fixtures';
|
||||
|
||||
// defined in ActionDispatch::TestRequest
|
||||
// see https://github.com/rails/rails/blob/v4.2.7.1/actionpack/lib/action_dispatch/testing/test_request.rb#L7
|
||||
window.gl = window.gl || {};
|
||||
window.gl.TEST_HOST = 'http://test.host';
|
||||
window.gon = window.gon || {};
|
Loading…
Reference in New Issue