-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
47 lines (32 loc) · 1.01 KB
/
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
46
'use strict';
const fs = require('fs');
const {reRequire} = require('mock-require');
const test = require('tape');
test('readdir withFileTypes: not supported', async (t) => {
const {readdir} = fs;
fs.readdir = (path, options, cb) => {
readdir(path, cb);
};
const read = reRequire('.');
const names = await read('.');
fs.readdir = readdir;
t.equal(typeof names[0], 'object', 'should return array of objects');
t.end();
});
test('readdir withFileTypes: empty', async (t) => {
const {readdir} = fs;
fs.readdir = (path, options, fn) => {
fn(null, []);
};
const read = reRequire('.');
const names = await read('.');
fs.readdir = readdir;
t.deepEqual(names, [], 'should equal');
t.end();
});
test('readdir withFileTypes: supported', async (t) => {
const read = reRequire('.');
const names = await read('.');
t.equal(typeof names[0], 'object', 'should return array of objects');
t.end();
});