write-tests
Write Busted test specs for Glu modules
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Write Busted test specs for Glu modules
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
| name | write-tests |
| description | Write Busted test specs for Glu modules |
Tests use the Busted framework and run inside Mudlet, so all Mudlet APIs are available.
src/resources/test/*_spec.lua
describe("<module> module", function()
local g
setup(function()
g = Glu("Glu")
end)
describe("<function_name>", function()
it("should <expected behavior>", function()
local result = g.<module>.<function_name>(<args>)
assert.are.equal(<expected>, result)
end)
end)
end)
Glu("Glu") in setup() — this gives access to all modules via g.<module>.<function>describe block per module, nested describe per functionassert.are.equal(expected, actual) for scalar comparisonassert.are.same(expected, actual) for deep table comparisonassert.is_true() / assert.is_false() for booleansassert.is_truthy() / assert.is_falsy() for nil checksassert.is_nil() for explicit nilassert.has_error(function() ... end) to test that code throwspending("description", function() ... end) for known-broken tests with a comment explaining the bugtable.size, table.index_of, table.keys, table.n_filter, table.is_empty are Mudlet extensions — they work in teststable.n_filter(t, fn) calls fn(element, index, table) — element is the first argtable.n_filter returns {} (empty table) when nothing matches, not nilrex.match, rex.find are available for PCRE regexstring.split is Mudlet's versionlfs (LuaFileSystem) is available___.v.type, ___.v.test, etc.) are activeMudlet's event loop doesn't yield to busted, so async code must be made synchronous via mocking. This pattern (used by Mudlet's own test suite) works for testing code that relies on tempTimer, installPackage, raiseEvent, and event handlers.
Mock tempTimer to execute callbacks immediately:
local real_tempTimer
before_each(function()
real_tempTimer = _G.tempTimer
_G.tempTimer = function(time, code)
if type(code) == "function" then
code()
elseif type(code) == "string" then
loadstring(code)()
end
end
end)
after_each(function()
_G.tempTimer = real_tempTimer
end)
Mock installPackage (or similar async triggers) to do nothing, then use raiseEvent to synchronously fire the event the code is waiting for:
before_each(function()
_G.installPackage = function() end
end)
it("should handle install", function()
-- set up the code under test, then manually fire the event
raiseEvent("sysInstall", "PackageName")
-- assertions run immediately — the handler fires synchronously
end)
Key insight: raiseEvent calls registered event handlers synchronously, so combining mocked tempTimer + mocked async triggers + raiseEvent lets the entire async chain execute within a single it block.
Always save and restore real globals in before_each/after_each to avoid polluting other tests.
Static test fixtures live in src/resources/test/fixtures/. In Mudlet, everything under resources/ is placed in the package's directory, where resources/ is the package root. So fixtures are accessible at runtime via:
local fixtures_dir = getMudletHomeDir() .. "/Glu/test/fixtures"
Use fixtures for read-only test data (sample files, etc.). For tests that need to write files, use g.fd.temp_dir() to create an isolated temp directory and clean it up in teardown.
npm test # all specs
src/scripts/<module>.luaself inside setup./test/run-tests.sh to verify