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

Commit 4443d51

Browse files
Leandro Soaresthemariamarques
authored andcommitted
feat: remove logs when NODE_ENV != development
1 parent 4149ec8 commit 4443d51

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

src/ResponsiveProvider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ const ResponsiveProvider = ({
115115
);
116116

117117
useEffect(() => {
118-
if (!process || !process.env || process.env.NODE_ENV !== 'test') {
118+
if (process && process.env && process.env.NODE_ENV === 'development') {
119119
/* eslint-disable no-console */
120120
console.group(
121121
'%c @farfetch/react-context-responsive updated!',

tests/ResponsiveProvider.test.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,30 @@ describe('<ResponsiveProvider />', () => {
152152
expect(listenersRemovedAfterUnmount).toBe(listenersAdded);
153153
});
154154

155-
test('should not call console.log in the test environment', () => {
156-
window.resizeTo(1024, 768);
155+
test.each(
156+
['production', 'test'],
157+
'should not call console.log in the % environment',
158+
(env) => {
159+
process.env.NODE_ENV = env;
160+
window.resizeTo(1024, 768);
157161

158-
render(
159-
<ResponsiveProvider {...props}>
160-
<div>Test</div>
161-
</ResponsiveProvider>
162-
);
162+
render(
163+
<ResponsiveProvider {...props}>
164+
<div>Test</div>
165+
</ResponsiveProvider>
166+
);
163167

164-
expect(global.console.group).not.toHaveBeenCalled();
165-
expect(global.console.log).not.toHaveBeenCalled();
166-
expect(global.console.groupEnd).not.toHaveBeenCalled();
167-
});
168+
expect(global.console.group).not.toHaveBeenCalled();
169+
expect(global.console.log).not.toHaveBeenCalled();
170+
expect(global.console.groupEnd).not.toHaveBeenCalled();
171+
172+
// Clean the global changes
173+
process.env.NODE_ENV = 'test';
174+
}
175+
);
168176

169-
test('should call console.log only outside the test environment', () => {
170-
// Set this as prod environment
171-
process.env.NODE_ENV = 'dev';
177+
test('should call console.log only for development environment', () => {
178+
process.env.NODE_ENV = 'development';
172179
window.resizeTo(1024, 768);
173180

174181
const { unmount } = render(

0 commit comments

Comments
 (0)