Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
feat: remove logs when NODE_ENV != development
Browse files Browse the repository at this point in the history
  • Loading branch information
Leandro Soares authored and themariamarques committed Sep 1, 2020
1 parent 4149ec8 commit 4443d51
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/ResponsiveProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const ResponsiveProvider = ({
);

useEffect(() => {
if (!process || !process.env || process.env.NODE_ENV !== 'test') {
if (process && process.env && process.env.NODE_ENV === 'development') {
/* eslint-disable no-console */
console.group(
'%c @farfetch/react-context-responsive updated!',
Expand Down
35 changes: 21 additions & 14 deletions tests/ResponsiveProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,30 @@ describe('<ResponsiveProvider />', () => {
expect(listenersRemovedAfterUnmount).toBe(listenersAdded);
});

test('should not call console.log in the test environment', () => {
window.resizeTo(1024, 768);
test.each(
['production', 'test'],
'should not call console.log in the % environment',
(env) => {
process.env.NODE_ENV = env;
window.resizeTo(1024, 768);

render(
<ResponsiveProvider {...props}>
<div>Test</div>
</ResponsiveProvider>
);
render(
<ResponsiveProvider {...props}>
<div>Test</div>
</ResponsiveProvider>
);

expect(global.console.group).not.toHaveBeenCalled();
expect(global.console.log).not.toHaveBeenCalled();
expect(global.console.groupEnd).not.toHaveBeenCalled();
});
expect(global.console.group).not.toHaveBeenCalled();
expect(global.console.log).not.toHaveBeenCalled();
expect(global.console.groupEnd).not.toHaveBeenCalled();

// Clean the global changes
process.env.NODE_ENV = 'test';
}
);

test('should call console.log only outside the test environment', () => {
// Set this as prod environment
process.env.NODE_ENV = 'dev';
test('should call console.log only for development environment', () => {
process.env.NODE_ENV = 'development';
window.resizeTo(1024, 768);

const { unmount } = render(
Expand Down

0 comments on commit 4443d51

Please sign in to comment.