Cleanup setup modules

This commit is contained in:
Jeff Avallone
2018-02-15 17:33:14 -05:00
parent fcba4b75ec
commit d9af19ca63
10 changed files with 104 additions and 17 deletions
+10
View File
@@ -0,0 +1,10 @@
import ReactGA from 'react-ga';
const setupAnalytics = () => {
ReactGA.initialize(process.env.GA_PROPERTY, {
debug: (process.env.NODE_ENV !== 'production')
});
ReactGA.pageview(document.location.pathname);
};
export default setupAnalytics;
+37
View File
@@ -0,0 +1,37 @@
jest.mock('react-ga');
import ReactGA from 'react-ga';
import setupAnalytics from './analytics';
describe('setupAnalytics', () => {
beforeEach(() => {
process.env.GA_PROPERTY = 'test property';
});
it('initializes with the GA_PROPERTY', () => {
setupAnalytics();
expect(ReactGA.initialize).toHaveBeenCalledWith('test property', expect.anything());
});
it('enables debug mode in development', () => {
process.env.NODE_ENV = 'development';
setupAnalytics();
expect(ReactGA.initialize).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
debug: true
}));
});
it('disabled debug mode in production', () => {
process.env.NODE_ENV = 'production';
setupAnalytics();
expect(ReactGA.initialize).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
debug: false
}));
});
it('triggers a pageview', () => {
setupAnalytics();
expect(ReactGA.pageview).toHaveBeenCalled();
});
});
+12
View File
@@ -0,0 +1,12 @@
import Raven from 'raven-js';
const setupRaven = () => {
Raven.config(process.env.SENTRY_KEY, {
whitelistUrls: [/https:\/\/(.*\.)?regexper\.com/],
environment: process.env.NODE_ENV,
debug: (process.env.NODE_ENV !== 'production'),
release: process.env.BUILD_ID
});
};
export default setupRaven;
+48
View File
@@ -0,0 +1,48 @@
jest.mock('raven-js');
import Raven from 'raven-js';
import setupRaven from './raven';
describe('setupRaven', () => {
beforeEach(() => {
process.env.SENTRY_KEY='test key';
});
it('intializes with the SENTRY_KEY', () => {
setupRaven();
expect(Raven.config).toHaveBeenCalledWith('test key', expect.anything());
});
it('sets the environment', () => {
process.env.NODE_ENV='test environment';
setupRaven();
expect(Raven.config).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
environment: 'test environment'
}));
});
it('enables debug mode for development', () => {
process.env.NODE_ENV='development';
setupRaven();
expect(Raven.config).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
debug: true
}));
});
it('disables debug mode for production', () => {
process.env.NODE_ENV='production';
setupRaven();
expect(Raven.config).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
debug: false
}));
});
it('sets the release', () => {
process.env.BUILD_ID='test ID';
setupRaven();
expect(Raven.config).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
release: 'test ID'
}));
});
});
+15
View File
@@ -0,0 +1,15 @@
const setupServiceWorker = () => {
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js')
.then(registration => {
console.log('SW registered:', registration); // eslint-disable-line no-console
})
.catch(registrationError => {
console.log('SW registration failed:', registrationError); // eslint-disable-line no-console
});
});
}
};
export default setupServiceWorker;