mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +00:00
- Implemented core testing functionalities including describe/it blocks, before/after hooks, and assertion methods. - Added support for mocks and spies to facilitate testing of functions and methods. - Introduced helper utilities for generating test data, parameterized tests, and snapshot testing. - Developed a test runner that executes suites and generates detailed reports in both text and JSON formats. - Created a manifest for the lua_test package to define scripts and their purposes. feat(screenshot_analyzer): introduce screenshot analysis package - Added metadata for the screenshot_analyzer package, detailing its components and scripts. - Defined dependencies and bindings for browser interactions.
146 lines
2.5 KiB
Lua
146 lines
2.5 KiB
Lua
-- Core test framework with describe/it blocks
|
|
-- Provides BDD-style test organization
|
|
|
|
local M = {}
|
|
|
|
-- Test suite state
|
|
M._suites = {}
|
|
M._currentSuite = nil
|
|
M._config = {
|
|
timeout = 5000,
|
|
verbose = true,
|
|
stopOnFirstFailure = false,
|
|
filter = nil
|
|
}
|
|
|
|
-- Create a new test suite
|
|
function M.createSuite(name)
|
|
local suite = {
|
|
name = name,
|
|
tests = {},
|
|
beforeAll = nil,
|
|
afterAll = nil,
|
|
beforeEach = nil,
|
|
afterEach = nil,
|
|
nested = {},
|
|
parent = nil
|
|
}
|
|
return suite
|
|
end
|
|
|
|
-- Describe block - groups related tests
|
|
function M.describe(name, fn)
|
|
local parentSuite = M._currentSuite
|
|
local suite = M.createSuite(name)
|
|
suite.parent = parentSuite
|
|
|
|
if parentSuite then
|
|
parentSuite.nested[#parentSuite.nested + 1] = suite
|
|
else
|
|
M._suites[#M._suites + 1] = suite
|
|
end
|
|
|
|
M._currentSuite = suite
|
|
fn()
|
|
M._currentSuite = parentSuite
|
|
|
|
return suite
|
|
end
|
|
|
|
-- It block - defines a single test
|
|
function M.it(name, fn)
|
|
if not M._currentSuite then
|
|
error("it() must be called inside a describe() block")
|
|
end
|
|
|
|
local test = {
|
|
name = name,
|
|
fn = fn,
|
|
status = "pending",
|
|
error = nil,
|
|
duration = 0,
|
|
skipped = false
|
|
}
|
|
|
|
M._currentSuite.tests[#M._currentSuite.tests + 1] = test
|
|
return test
|
|
end
|
|
|
|
-- Skip a test
|
|
function M.xit(name, fn)
|
|
if not M._currentSuite then
|
|
error("xit() must be called inside a describe() block")
|
|
end
|
|
|
|
local test = {
|
|
name = name,
|
|
fn = fn,
|
|
status = "skipped",
|
|
error = nil,
|
|
duration = 0,
|
|
skipped = true
|
|
}
|
|
|
|
M._currentSuite.tests[#M._currentSuite.tests + 1] = test
|
|
return test
|
|
end
|
|
|
|
-- Only run this test (for debugging)
|
|
function M.fit(name, fn)
|
|
local test = M.it(name, fn)
|
|
test.only = true
|
|
return test
|
|
end
|
|
|
|
-- Setup hooks
|
|
function M.beforeAll(fn)
|
|
if M._currentSuite then
|
|
M._currentSuite.beforeAll = fn
|
|
end
|
|
end
|
|
|
|
function M.afterAll(fn)
|
|
if M._currentSuite then
|
|
M._currentSuite.afterAll = fn
|
|
end
|
|
end
|
|
|
|
function M.beforeEach(fn)
|
|
if M._currentSuite then
|
|
M._currentSuite.beforeEach = fn
|
|
end
|
|
end
|
|
|
|
function M.afterEach(fn)
|
|
if M._currentSuite then
|
|
M._currentSuite.afterEach = fn
|
|
end
|
|
end
|
|
|
|
-- Configure the test framework
|
|
function M.configure(options)
|
|
for k, v in pairs(options) do
|
|
if M._config[k] ~= nil then
|
|
M._config[k] = v
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Get all registered suites
|
|
function M.getSuites()
|
|
return M._suites
|
|
end
|
|
|
|
-- Reset all suites (for fresh test runs)
|
|
function M.reset()
|
|
M._suites = {}
|
|
M._currentSuite = nil
|
|
end
|
|
|
|
-- Get current config
|
|
function M.getConfig()
|
|
return M._config
|
|
end
|
|
|
|
return M
|