Cleanup setup modules
This commit is contained in:
@@ -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;
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
@@ -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'
|
||||
}));
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user