mirror of https://github.com/zulip/zulip.git
node tests: Make with_overrides() more granular.
The with_overrides() function no longer works at the module level, so you can temporarily override one function in a module without breaking more permanent monkey patches. This makes us slightly more vulnerable to unintentional test leakages, but it solves the problem where you often need lots of temporary overrides for writer functions but you want to keep a more permanent override for some sort of reader function.
This commit is contained in:
parent
a98999ce27
commit
ef3033c79e
|
@ -61,15 +61,19 @@ exports.with_overrides = function (test_function) {
|
|||
var parts = name.split('.');
|
||||
var module = parts[0];
|
||||
var func_name = parts[1];
|
||||
var module_impl = {};
|
||||
module_impl[func_name] = f;
|
||||
set_global(module, module_impl);
|
||||
|
||||
if (!_.has(global, module)) {
|
||||
set_global(module, {});
|
||||
}
|
||||
|
||||
global[module][func_name] = f;
|
||||
|
||||
clobber_callbacks.push(function () {
|
||||
// If you get a failure from this, you probably just
|
||||
// need to have your test do its own overrides and
|
||||
// not cherry-pick off of the prior test's setup.
|
||||
set_global(module, 'UNCLEAN MODULE FROM PRIOR TEST');
|
||||
global[module][func_name] =
|
||||
'ATTEMPTED TO REUSE OVERRIDDEN VALUE FROM PRIOR TEST';
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue