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

View File

@ -44,8 +44,8 @@
"collectCoverageFrom": [
"src/**/*.js",
"!src/prerender.js",
"!src/service-worker.js",
"!src/setup-jest.js",
"!src/setup/service-worker.js",
"!src/setup/jest.js",
"!src/pages/**/config.js",
"!src/pages/**/browser.js"
],

View File

@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { translate, Trans } from 'react-i18next';
import { Raven } from 'sentry';
import Raven from 'raven-js';
import Message from 'components/Message';

View File

@ -1,10 +1,10 @@
jest.mock('raven-js');
import React from 'react';
import { shallow } from 'enzyme';
jest.mock('sentry');
import Raven from 'raven-js';
import { RavenError } from 'components/RavenError';
import { Raven } from 'sentry';
import translate from '__mocks__/translate';
const testError = { error: 'test error' };

View File

@ -1,18 +1,19 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Raven from 'raven-js';
import Component from './Component';
import RavenBoundary from 'components/RavenBoundary';
import 'site.css';
import 'i18n';
import { setupGA } from 'analytics';
import { Raven, setupRaven } from 'sentry';
import setupAnalytics from 'setup/analytics';
import setupRaven from 'setup/raven';
setupRaven();
try {
setupGA();
setupAnalytics();
ReactDOM.render(
<RavenBoundary>

View File

@ -1,19 +1,20 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Raven from 'raven-js';
import Component from './Component';
import RavenBoundary from 'components/RavenBoundary';
import 'site.css';
import 'i18n';
import { setupServiceWorker } from 'service-worker';
import { setupGA } from 'analytics';
import { Raven, setupRaven } from 'sentry';
import setupServiceWorker from 'setup/service-worker';
import setupAnalytics from 'setup/analytics';
import setupRaven from 'setup/raven';
setupRaven();
try {
setupGA();
setupAnalytics();
if (process.env.NODE_ENV === 'production') {
setupServiceWorker();
}

View File

@ -1,10 +1,10 @@
import ReactGA from 'react-ga';
const setupGA = () => {
const setupAnalytics = () => {
ReactGA.initialize(process.env.GA_PROPERTY, {
debug: (process.env.NODE_ENV !== 'production')
});
ReactGA.pageview(document.location.pathname);
};
export { setupGA };
export default setupAnalytics;

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();
});
});

View File

@ -9,4 +9,4 @@ const setupRaven = () => {
});
};
export { Raven, setupRaven };
export default setupRaven;

48
src/setup/raven.test.js Normal file
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'
}));
});
});

View File

@ -12,4 +12,4 @@ const setupServiceWorker = () => {
}
};
export { setupServiceWorker };
export default setupServiceWorker;