Clear additional global state between unit test runs

Clears out some global state that was being left over between unit tests runs, causing indeterminate results when running multiple tests against data at the global scope.
This commit is contained in:
Jason Perkins 2018-03-19 10:10:56 -04:00
parent 0c17303436
commit e34c23b64f

View File

@ -674,10 +674,23 @@
-- individual test runs.
---
local numBuiltInGlobalBlocks
function api.reset()
if numBuiltInGlobalBlocks == nil then
numBuiltInGlobalBlocks = #api.scope.global.blocks
end
for containerClass in p.container.eachChildClass(p.global) do
api.scope.global[containerClass.pluralName] = {}
end
api.scope.current = api.scope.global
local currentGlobalBlockCount = #api.scope.global.blocks
for i = currentGlobalBlockCount, numBuiltInGlobalBlocks + 1, -1 do
table.remove(api.scope.global.blocks, i)
end
end