From ef3033c79e5d050c21fe4f092431354d17856a41 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sun, 12 Mar 2017 06:32:12 -0700 Subject: [PATCH] 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. --- frontend_tests/zjsunit/namespace.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.js index ddbe29bacf..43950c8d13 100644 --- a/frontend_tests/zjsunit/namespace.js +++ b/frontend_tests/zjsunit/namespace.js @@ -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'; }); };