-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.js
36 lines (31 loc) · 1.09 KB
/
jest.setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// XXX Unlike what could be expected, once an ENV var is found by dotenv, it won't be overridden
// So, the order must be from the most important to the less important
// See https://github.com/motdotla/dotenv/issues/256#issuecomment-598676663
require('dotenv').config({ path: '.env.local' })
require('dotenv').config({ path: '.env' })
// Backup of the native console object for later re-use
global._console = global.console
// Force mute console by returning a mock object that mocks the props we use
global.muteConsole = () => {
return {
debug: jest.fn(),
error: jest.fn(),
info: jest.fn(),
log: jest.fn(),
warn: jest.fn(),
}
}
// Force mute console by returning a mock object that mocks the props we use, except for "log"
global.muteConsoleButLog = () => {
return {
debug: jest.fn(),
error: jest.fn(),
info: jest.fn(),
log: _console.log,
warn: jest.fn(),
}
}
// Restore previously made "console" object
global.unmuteConsole = () => _console
// Mock __non_webpack_require__ to use the standard node.js "require"
global['__non_webpack_require__'] = require