webpack/test/cases/chunks/context-weak/index.js

30 lines
1.1 KiB
JavaScript
Raw Normal View History

it("should not bundle context requires with asyncMode === 'weak'", function() {
2022-03-01 23:11:31 +08:00
var contextRequire = require.context(".", false, /two/, "weak");
expect(function() {
contextRequire("./two")
}).toThrowError(/not available/);
});
it("should not bundle context requires with asyncMode === 'weak' using import.meta.webpackContext", function() {
2022-02-27 04:16:21 +08:00
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() {
2022-03-01 23:11:31 +08:00
var 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() {
2022-03-01 23:11:31 +08:00
var 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
});