Skip to content

Commit d96de21

Browse files
authoredMay 8, 2023
Merge pull request #13384 from Automattic/vkarpov15/gh-13373
Add SUPPRESS_JEST_WARNINGS environment variable to hide jest warnings
2 parents 76e6456 + 0ab335f commit d96de21

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed
 

‎docs/jest.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Jest is a JavaScript runtime developed by Facebook that is usually used for test
44
Because Jest is designed primarily for testing React applications, using it to test Node.js server-side applications comes with a lot of caveats.
55
We strongly recommend using a different testing framework, like [Mocha](https://mochajs.org/).
66

7+
To suppress any Jest warnings from Mongoose, set the `SUPPRESS_JEST_WARNINGS` environment variable:
8+
9+
```
10+
env SUPPRESS_JEST_WARNINGS=1 npm test
11+
```
12+
713
If you choose to delve into dangerous waters and test Mongoose apps with Jest, here's what you need to know:
814

915
<h2 id="recommended-testenvironment"><a href="#recommended-testenvironment">Recommended <code>testEnvironment</code></a></h2>

‎lib/helpers/printJestWarning.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
const utils = require('../utils');
44

5-
if (typeof jest !== 'undefined' && typeof window !== 'undefined') {
6-
utils.warn('Mongoose: looks like you\'re trying to test a Mongoose app ' +
7-
'with Jest\'s default jsdom test environment. Please make sure you read ' +
8-
'Mongoose\'s docs on configuring Jest to test Node.js apps: ' +
9-
'https://mongoosejs.com/docs/jest.html');
10-
}
5+
if (typeof jest !== 'undefined' && !process.env.SUPPRESS_JEST_WARNINGS) {
6+
if (typeof window !== 'undefined') {
7+
utils.warn('Mongoose: looks like you\'re trying to test a Mongoose app ' +
8+
'with Jest\'s default jsdom test environment. Please make sure you read ' +
9+
'Mongoose\'s docs on configuring Jest to test Node.js apps: ' +
10+
'https://mongoosejs.com/docs/jest.html. Set the SUPPRESS_JEST_WARNINGS to true ' +
11+
'to hide this warning.');
12+
}
1113

12-
if (typeof jest !== 'undefined' && setTimeout.clock != null && typeof setTimeout.clock.Date === 'function') {
13-
utils.warn('Mongoose: looks like you\'re trying to test a Mongoose app ' +
14-
'with Jest\'s mock timers enabled. Please make sure you read ' +
15-
'Mongoose\'s docs on configuring Jest to test Node.js apps: ' +
16-
'https://mongoosejs.com/docs/jest.html');
14+
if (setTimeout.clock != null && typeof setTimeout.clock.Date === 'function') {
15+
utils.warn('Mongoose: looks like you\'re trying to test a Mongoose app ' +
16+
'with Jest\'s mock timers enabled. Please make sure you read ' +
17+
'Mongoose\'s docs on configuring Jest to test Node.js apps: ' +
18+
'https://mongoosejs.com/docs/jest.html. Set the SUPPRESS_JEST_WARNINGS to true ' +
19+
'to hide this warning.');
20+
}
1721
}

0 commit comments

Comments
 (0)
Please sign in to comment.