-
Notifications
You must be signed in to change notification settings - Fork 451
/
path.ts
33 lines (27 loc) · 874 Bytes
/
path.ts
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
import { } from 'jest';
import { } from 'node';
interface MockedPath {
__setBaseDir(newBaseDir);
resolve(...args);
dirname(...args);
join(...args);
}
const path = require.requireActual('path');
const mockedPath = jest.genMockFromModule<MockedPath>('path');
// This is a custom function that our tests can use during setup to specify
// what the files on the "mock" filesystem should look like when any of the
// `fs` APIs are used.
let baseDir = '';
function __setBaseDir(newBaseDir) {
baseDir = newBaseDir;
}
// A custom version of `readdirSync` that reads from the special mocked out
// file list set via __setMockFiles
function resolve(...args) {
return path.resolve(baseDir, ...args);
}
mockedPath.__setBaseDir = __setBaseDir;
mockedPath.resolve = resolve;
mockedPath.dirname = path.dirname;
mockedPath.join = path.join;
module.exports = mockedPath;