forked from Pythagora-io/pythagora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckDirectoryExists.test.js
45 lines (31 loc) · 1.42 KB
/
checkDirectoryExists.test.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
describe('checkDirectoryExists', () => {
test('should return true when directory exists', async () => {
const { checkDirectoryExists } = require('../../../../../src/utils/common.js');
const fs = require('fs');
fs.mkdirSync('test-dir');
const exists = await checkDirectoryExists('test-dir');
fs.rmdirSync('test-dir');
expect(exists).toBe(true);
});
test('should return false when directory does not exist', async () => {
const { checkDirectoryExists } = require('../../../../../src/utils/common.js');
const exists = await checkDirectoryExists('nonexistent-dir');
expect(exists).toBe(false);
});
test('should return false when provided path is to a file', async () => {
const { checkDirectoryExists } = require('../../../../../src/utils/common.js');
const fs = require('fs');
fs.writeFileSync('test-file.txt', 'test contents');
const exists = await checkDirectoryExists('test-file.txt');
fs.unlinkSync('test-file.txt');
expect(exists).toBe(false);
});
test('should handle null input', async () => {
const { checkDirectoryExists } = require('../../../../../src/utils/common.js');
await expect(checkDirectoryExists(null)).rejects.toThrow();
});
test('should handle undefined input', async () => {
const { checkDirectoryExists } = require('../../../../../src/utils/common.js');
await expect(checkDirectoryExists(undefined)).rejects.toThrow();
});
});