js: Use jQuery as a module.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-03-10 20:43:45 -08:00
parent ac36d59728
commit ea9ca6b7d0
211 changed files with 426 additions and 128 deletions

View File

@@ -12,12 +12,20 @@ let actual_load;
const module_mocks = new Map();
const used_module_mocks = new Set();
const jquery_path = require.resolve("jquery");
const real_jquery_path = require.resolve("../zjsunit/real_jquery.js");
function load(request, parent, isMain) {
const filename = Module._resolveFilename(request, parent, isMain);
if (module_mocks.has(filename)) {
used_module_mocks.add(filename);
return module_mocks.get(filename);
}
if (filename === jquery_path && parent.filename !== real_jquery_path) {
// jQuery exposes an incompatible API to Node vs. browser, so
// this wouldn't work.
throw new Error("This test will need jquery mocked using zjquery or real_jquery");
}
return actual_load(request, parent, isMain);
}