Skip to content

Commit

Permalink
Fix expected assertions, TODO: create generic test context to store s…
Browse files Browse the repository at this point in the history
…uch information into, hopefull resulting in some cleaner code
  • Loading branch information
luttje committed Dec 4, 2024
1 parent d307592 commit 4cbad22
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 74 deletions.
30 changes: 22 additions & 8 deletions libs/jestronaut/environment/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,18 @@ function TEST_RUNNER:runTest(queuedTest)
status, errorMessage = self.modifyTestResultCallback(queuedTest.test, status, errorMessage)
end

-- TODO: Should this also run here for async tests? Even though those may not have finished yet?
if self.postTestCallback then
self.postTestCallback(queuedTest.test, queuedTest.status == "passed")
end

return status, errorMessage
end

function TEST_RUNNER:statusToPassFailText(status)
return status and "passed" or "failed"
end

function TEST_RUNNER:tick()
if self.isCompleted then
return false
Expand All @@ -149,19 +154,20 @@ function TEST_RUNNER:tick()
self:markFinished(queuedTest, "skipped")
elseif queuedTest.type == "sync" then
-- Run sync tests immediately
local status, errorMessage = self:runTest(queuedTest)
local success, errorMessage = self:runTest(queuedTest)

self:markFinished(queuedTest, status and "passed" or "failed", errorMessage)
self:markFinished(queuedTest, self:statusToPassFailText(success), errorMessage)
elseif queuedTest.type == "async" then
-- Start async test if not started
if queuedTest.status == "starting" then
queuedTest.startTime = os.time()
queuedTest.status = "pending"

local status, errorMessage = self:runTest(queuedTest)
local success, errorMessage = self:runTest(queuedTest)

if not status then
self:markFinished(queuedTest, "failed", errorMessage)
-- Failed even while starting the test
if not success then
self:markFinished(queuedTest, self:statusToPassFailText(success), errorMessage)
else
-- Test started, might need further processing
queuedTest.result = queuedTest
Expand All @@ -173,16 +179,24 @@ function TEST_RUNNER:tick()
-- while the loop already started
local elapsedTime = os.time() - queuedTest.startTime

if (queuedTest.asyncWrapper.isDone) then
self:markFinished(queuedTest, "passed")
elseif elapsedTime > queuedTest.timeout then
-- We check the timeout first, because even if 'done' is true, if it's late we should fail the test
if elapsedTime > queuedTest.timeout then
local status, errorMessage = false, "Test timed out after " .. queuedTest.timeout .. " seconds"

if self.modifyTestResultCallback then
status, errorMessage = self.modifyTestResultCallback(queuedTest.test, status, errorMessage)
end

self:markFinished(queuedTest, status and "passed" or "failed", errorMessage)
elseif (queuedTest.asyncWrapper.isDone) then
local errorMessage = queuedTest.asyncWrapper.errorMessage
local success = not errorMessage

if self.modifyTestResultCallback then
success, errorMessage = self.modifyTestResultCallback(queuedTest.test, success, errorMessage)
end

self:markFinished(queuedTest, self:statusToPassFailText(success), errorMessage)
else
-- Test still in progress
table.insert(remainingTests, queuedTest)
Expand Down
Loading

0 comments on commit 4cbad22

Please sign in to comment.