Cleanup setup modules
This commit is contained in:
parent
fcba4b75ec
commit
d9af19ca63
@ -44,8 +44,8 @@
|
|||||||
"collectCoverageFrom": [
|
"collectCoverageFrom": [
|
||||||
"src/**/*.js",
|
"src/**/*.js",
|
||||||
"!src/prerender.js",
|
"!src/prerender.js",
|
||||||
"!src/service-worker.js",
|
"!src/setup/service-worker.js",
|
||||||
"!src/setup-jest.js",
|
"!src/setup/jest.js",
|
||||||
"!src/pages/**/config.js",
|
"!src/pages/**/config.js",
|
||||||
"!src/pages/**/browser.js"
|
"!src/pages/**/browser.js"
|
||||||
],
|
],
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { translate, Trans } from 'react-i18next';
|
import { translate, Trans } from 'react-i18next';
|
||||||
import { Raven } from 'sentry';
|
import Raven from 'raven-js';
|
||||||
|
|
||||||
import Message from 'components/Message';
|
import Message from 'components/Message';
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
|
jest.mock('raven-js');
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
import Raven from 'raven-js';
|
||||||
jest.mock('sentry');
|
|
||||||
|
|
||||||
import { RavenError } from 'components/RavenError';
|
import { RavenError } from 'components/RavenError';
|
||||||
import { Raven } from 'sentry';
|
|
||||||
import translate from '__mocks__/translate';
|
import translate from '__mocks__/translate';
|
||||||
|
|
||||||
const testError = { error: 'test error' };
|
const testError = { error: 'test error' };
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
import Raven from 'raven-js';
|
||||||
|
|
||||||
import Component from './Component';
|
import Component from './Component';
|
||||||
import RavenBoundary from 'components/RavenBoundary';
|
import RavenBoundary from 'components/RavenBoundary';
|
||||||
|
|
||||||
import 'site.css';
|
import 'site.css';
|
||||||
import 'i18n';
|
import 'i18n';
|
||||||
import { setupGA } from 'analytics';
|
import setupAnalytics from 'setup/analytics';
|
||||||
import { Raven, setupRaven } from 'sentry';
|
import setupRaven from 'setup/raven';
|
||||||
|
|
||||||
setupRaven();
|
setupRaven();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setupGA();
|
setupAnalytics();
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<RavenBoundary>
|
<RavenBoundary>
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
import Raven from 'raven-js';
|
||||||
|
|
||||||
import Component from './Component';
|
import Component from './Component';
|
||||||
import RavenBoundary from 'components/RavenBoundary';
|
import RavenBoundary from 'components/RavenBoundary';
|
||||||
|
|
||||||
import 'site.css';
|
import 'site.css';
|
||||||
import 'i18n';
|
import 'i18n';
|
||||||
import { setupServiceWorker } from 'service-worker';
|
import setupServiceWorker from 'setup/service-worker';
|
||||||
import { setupGA } from 'analytics';
|
import setupAnalytics from 'setup/analytics';
|
||||||
import { Raven, setupRaven } from 'sentry';
|
import setupRaven from 'setup/raven';
|
||||||
|
|
||||||
setupRaven();
|
setupRaven();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setupGA();
|
setupAnalytics();
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
setupServiceWorker();
|
setupServiceWorker();
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import ReactGA from 'react-ga';
|
import ReactGA from 'react-ga';
|
||||||
|
|
||||||
const setupGA = () => {
|
const setupAnalytics = () => {
|
||||||
ReactGA.initialize(process.env.GA_PROPERTY, {
|
ReactGA.initialize(process.env.GA_PROPERTY, {
|
||||||
debug: (process.env.NODE_ENV !== 'production')
|
debug: (process.env.NODE_ENV !== 'production')
|
||||||
});
|
});
|
||||||
ReactGA.pageview(document.location.pathname);
|
ReactGA.pageview(document.location.pathname);
|
||||||
};
|
};
|
||||||
|
|
||||||
export { setupGA };
|
export default setupAnalytics;
|
37
src/setup/analytics.test.js
Normal file
37
src/setup/analytics.test.js
Normal 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();
|
||||||
|
});
|
||||||
|
});
|
@ -9,4 +9,4 @@ const setupRaven = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export { Raven, setupRaven };
|
export default setupRaven;
|
48
src/setup/raven.test.js
Normal file
48
src/setup/raven.test.js
Normal 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'
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
@ -12,4 +12,4 @@ const setupServiceWorker = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export { setupServiceWorker };
|
export default setupServiceWorker;
|
Loading…
Reference in New Issue
Block a user