forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContextModuleFactory.unittest.js
61 lines (59 loc) · 1.49 KB
/
ContextModuleFactory.unittest.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
50
51
52
53
54
55
56
57
58
59
60
61
"use strict";
const { createFsFromVolume, Volume } = require("memfs");
const ContextModuleFactory = require("../lib/ContextModuleFactory");
describe("ContextModuleFactory", () => {
describe("resolveDependencies", () => {
let factory, memfs;
beforeEach(() => {
factory = new ContextModuleFactory([]);
memfs = createFsFromVolume(new Volume());
});
it("should not report an error when ENOENT errors happen", done => {
memfs.readdir = (dir, callback) => {
setTimeout(() => callback(null, ["/file"]));
};
memfs.stat = (file, callback) => {
let err = new Error("fake ENOENT error");
err.code = "ENOENT";
setTimeout(() => callback(err, null));
};
factory.resolveDependencies(
memfs,
{
resource: "/",
recursive: true,
regExp: /.*/
},
(err, res) => {
expect(err).toBeFalsy();
expect(Array.isArray(res)).toBe(true);
expect(res.length).toBe(0);
done();
}
);
});
it("should report an error when non-ENOENT errors happen", done => {
memfs.readdir = (dir, callback) => {
setTimeout(() => callback(null, ["/file"]));
};
memfs.stat = (file, callback) => {
let err = new Error("fake EACCES error");
err.code = "EACCES";
setTimeout(() => callback(err, null));
};
factory.resolveDependencies(
memfs,
{
resource: "/",
recursive: true,
regExp: /.*/
},
(err, res) => {
expect(err).toBeInstanceOf(Error);
expect(res).toBeFalsy();
done();
}
);
});
});
});