Make require() reload modules when run in tests

develop
lethosor 2020-12-15 21:27:04 -05:00
parent d3aeca495f
commit bd92d8f27a
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
1 changed files with 11 additions and 0 deletions

@ -104,6 +104,16 @@ function delay(frames)
script.sleep(frames, 'frames') script.sleep(frames, 'frames')
end end
function clean_require(module)
-- wrapper around require() - forces a clean load of every module to ensure
-- that modules checking for dfhack.internal.IN_TEST at load time behave
-- properly
if package.loaded[module] then
reload(module)
end
return require(module)
end
function ensure_title_screen() function ensure_title_screen()
if df.viewscreen_titlest:is_instance(dfhack.gui.getCurViewscreen()) then if df.viewscreen_titlest:is_instance(dfhack.gui.getCurViewscreen()) then
return return
@ -153,6 +163,7 @@ function build_test_env()
}, },
expect = {}, expect = {},
delay = delay, delay = delay,
require = clean_require,
} }
local private = { local private = {
checks = 0, checks = 0,