-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjest.TestFrameworkSetup.js
49 lines (44 loc) · 1.73 KB
/
jest.TestFrameworkSetup.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
37
38
39
40
41
42
43
44
45
46
47
48
49
import fs from 'fs'
import os from 'os'
import path from 'path'
// module mocks ***************************************/
jest.mock('fs')
jest.mock('os')
/** * **************************************************/
// Useful function mocks ******************************/
function mockReadFile (DataObj) {
const stringData = JSON.stringify(DataObj, 'utf8')
fs.readFileSync.mockReturnValue(stringData)
}
function mockWriteFile (DataObj) {
fs.writeFile.mockImplementation(() => { return DataObj })
}
const NOOP = () => {} // classical no operation function
/** * *************************************************/
// Pre-Mocked modules ********************************/
const mockHomeDir = path.join('C:', 'User', 'home')
const mockInstallDir = path.join('C:', 'Program Files (x86)', 'World of Warcraft', 'Interface', 'AddOns')
os.homedir.mockReturnValue(mockHomeDir)
// fs module - anything that can create things
fs.WriteStream.mockImplementation(NOOP)
fs.mkdir.mockImplementation(NOOP)
fs.mkdirSync.mockImplementation(NOOP)
fs.readdirSync.mockImplementation(NOOP)
fs.chmod.mockImplementation(NOOP)
fs.chmodSync.mockImplementation(NOOP)
fs.chown.mockImplementation(NOOP)
fs.chownSync.mockImplementation(NOOP)
fs.write.mockImplementation(NOOP)
fs.writeSync.mockImplementation(NOOP)
fs.writeFile.mockImplementation(NOOP)
fs.writeFileSync.mockImplementation(NOOP)
fs.copyFile.mockImplementation(NOOP)
fs.copyFileSync.mockImplementation(NOOP)
/** * ***********************************************/
// Testing globals *********************************/
global.mockReadFile = mockReadFile
global.mockWriteFile = mockWriteFile
global.NOOP = NOOP
global.mockHomeDir = mockHomeDir
global.mockInstallDir = mockInstallDir
/** * ***********************************************/