mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 06:14:59 +00:00
46 lines
1.1 KiB
Lua
46 lines
1.1 KiB
Lua
-- Test lifecycle hooks
|
|
-- Provides beforeAll, afterAll, beforeEach, afterEach
|
|
|
|
local suite = require("suite")
|
|
|
|
---@class HooksModule
|
|
local M = {}
|
|
|
|
---Setup hook run once before all tests in a suite
|
|
---@param fn function Setup function
|
|
function M.beforeAll(fn)
|
|
local currentSuite = suite.getCurrentSuite()
|
|
if currentSuite then
|
|
currentSuite.beforeAll = fn
|
|
end
|
|
end
|
|
|
|
---Teardown hook run once after all tests in a suite
|
|
---@param fn function Teardown function
|
|
function M.afterAll(fn)
|
|
local currentSuite = suite.getCurrentSuite()
|
|
if currentSuite then
|
|
currentSuite.afterAll = fn
|
|
end
|
|
end
|
|
|
|
---Setup hook run before each test in a suite
|
|
---@param fn function Setup function
|
|
function M.beforeEach(fn)
|
|
local currentSuite = suite.getCurrentSuite()
|
|
if currentSuite then
|
|
currentSuite.beforeEach = fn
|
|
end
|
|
end
|
|
|
|
---Teardown hook run after each test in a suite
|
|
---@param fn function Teardown function
|
|
function M.afterEach(fn)
|
|
local currentSuite = suite.getCurrentSuite()
|
|
if currentSuite then
|
|
currentSuite.afterEach = fn
|
|
end
|
|
end
|
|
|
|
return M
|