summaryrefslogtreecommitdiff
path: root/spec/javascripts/raven
diff options
context:
space:
mode:
authorLuke "Jared" Bennett <lbennett@gitlab.com>2017-04-18 18:58:03 +0100
committerLuke "Jared" Bennett <lbennett@gitlab.com>2017-04-18 18:58:03 +0100
commitaf6e3e57e4c0ee861e26310c65be2e5e8547ca68 (patch)
tree5a73c7a4917d146d185f17827c9a0ce49e138562 /spec/javascripts/raven
parent86b4f49c8c76a322d2f12f61e5a2d27d3c5c4671 (diff)
downloadgitlab-ce-af6e3e57e4c0ee861e26310c65be2e5e8547ca68.tar.gz
Added sampling function and blacklisted common urls and error messages
Diffstat (limited to 'spec/javascripts/raven')
-rw-r--r--spec/javascripts/raven/raven_config_spec.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/javascripts/raven/raven_config_spec.js b/spec/javascripts/raven/raven_config_spec.js
index 55f3949c740..78251b4f61b 100644
--- a/spec/javascripts/raven/raven_config_spec.js
+++ b/spec/javascripts/raven/raven_config_spec.js
@@ -2,6 +2,28 @@ import Raven from 'raven-js';
import RavenConfig from '~/raven/raven_config';
describe('RavenConfig', () => {
+ describe('IGNORE_ERRORS', () => {
+ it('should be an array of strings', () => {
+ const areStrings = RavenConfig.IGNORE_ERRORS.every(error => typeof error === 'string');
+
+ expect(areStrings).toBe(true);
+ });
+ });
+
+ describe('IGNORE_URLS', () => {
+ it('should be an array of regexps', () => {
+ const areRegExps = RavenConfig.IGNORE_URLS.every(url => url instanceof RegExp);
+
+ expect(areRegExps).toBe(true);
+ });
+ });
+
+ describe('SAMPLE_RATE', () => {
+ it('should be a finite number', () => {
+ expect(typeof RavenConfig.SAMPLE_RATE).toEqual('number');
+ });
+ });
+
describe('init', () => {
let options;
@@ -76,6 +98,9 @@ describe('RavenConfig', () => {
expect(Raven.config).toHaveBeenCalledWith(options.sentryDsn, {
whitelistUrls: options.whitelistUrls,
environment: 'production',
+ ignoreErrors: Raven.IGNORE_ERRORS,
+ ignoreUrls: Raven.IGNORE_URLS,
+ shouldSendCallback: Raven.shouldSendSample,
});
});
@@ -93,6 +118,9 @@ describe('RavenConfig', () => {
expect(Raven.config).toHaveBeenCalledWith(options.sentryDsn, {
whitelistUrls: options.whitelistUrls,
environment: 'development',
+ ignoreErrors: Raven.IGNORE_ERRORS,
+ ignoreUrls: Raven.IGNORE_URLS,
+ shouldSendCallback: Raven.shouldSendSample,
});
});
});
@@ -213,4 +241,38 @@ describe('RavenConfig', () => {
});
});
});
+
+ describe('shouldSendSample', () => {
+ let randomNumber;
+
+ beforeEach(() => {
+ RavenConfig.SAMPLE_RATE = 50;
+
+ spyOn(Math, 'random').and.callFake(() => randomNumber);
+ });
+
+ it('should call Math.random', () => {
+ RavenConfig.shouldSendSample();
+
+ expect(Math.random).toHaveBeenCalled();
+ });
+
+ it('should return true if the sample rate is greater than the random number * 100', () => {
+ randomNumber = 0.1;
+
+ expect(RavenConfig.shouldSendSample()).toBe(true);
+ });
+
+ it('should return false if the sample rate is less than the random number * 100', () => {
+ randomNumber = 0.9;
+
+ expect(RavenConfig.shouldSendSample()).toBe(false);
+ });
+
+ it('should return true if the sample rate is equal to the random number * 100', () => {
+ randomNumber = 0.5;
+
+ expect(RavenConfig.shouldSendSample()).toBe(true);
+ });
+ });
});