/
index.js
27 lines (24 loc) · 1.01 KB
/
index.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
it("import.meta.webpackContext without arguments should work", function() {
const contextRequire = import.meta.webpackContext("./dir");
expect(contextRequire("./four")).toBe(4);
});
it("should not bundle context requires with asyncMode === 'weak'", function() {
const contextRequire = import.meta.webpackContext(".", {
recursive: false,
regExp: /two/,
mode: "weak"
});
expect(function() {
contextRequire("./two")
}).toThrowError(/not available/);
});
it("should find module with asyncMode === 'weak' when required elsewhere", function() {
const contextRequire = require.context(".", false, /.+/, "weak");
expect(contextRequire("./three")).toBe(3);
require("./three"); // in a real app would be served as a separate chunk
});
it("should find module with asyncMode === 'weak' when required elsewhere (recursive)", function() {
const contextRequire = require.context(".", true, /.+/, "weak");
expect(contextRequire("./dir/four")).toBe(4);
require("./dir/four"); // in a real app would be served as a separate chunk
});