Skip to content

Commit

Permalink
implimented new hooks and moved logs into reporters
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdp committed Jan 10, 2025
1 parent 795890f commit 512ca3a
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 17 deletions.
34 changes: 19 additions & 15 deletions framework/src/source/BaseTestSuite.bs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace rooibos
'++++++++++++++++++++++++++++++++++++?+++++++++++++++++++++++++

function run()

m.notifyReportersOnSuiteBegin()
' ? ">>>>>>>>>>>>"
' ? " RUNNING TEST SUITE"
if m.isAsync = true
Expand Down Expand Up @@ -154,6 +154,7 @@ namespace rooibos
}
})
end if
m.notifyReportersOnSuiteComplete()
end function

function runASync()
Expand Down Expand Up @@ -184,12 +185,6 @@ namespace rooibos
group = m.currentGroup
m.testRunner.top.rooibosGroupFinished = false

? ""
? rooibos.common.fillText(">>>> Describe: " + group.name, ">", 80)
'bs:disable-next-line
? ` Location: file://${group.testSuite.filePath.trim()}:${group.lineNumber}`
? ""

m.testRunner.top.observeFieldScoped("rooibosGroupFinished", "rooibos_onGroupComplete")

group.run()
Expand Down Expand Up @@ -257,11 +252,6 @@ namespace rooibos
end function

function runTest(test as rooibos.Test)
? ""
? rooibos.common.fillText(">>>>>> It: " + test.name, ">", 80)
? ` Location: file://${test.testSuite.filePath.trim()}:${test.lineNumber}`
? ""

m.currentResult = test.result
m.currentResult.throwOnFailedAssertion = m.throwOnFailedAssertion
if m.catchCrashes and not test.noCatch and not m.noCatch
Expand All @@ -284,9 +274,6 @@ namespace rooibos
m.CleanStubs()
end if
end if

? rooibos.common.fillText("<<<< END It: " + test.name + " (" + m.currentResult.getStatusText() + ") ", "<", 80)

end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down Expand Up @@ -3050,6 +3037,7 @@ namespace rooibos

function testSuiteDone()
' ? "Async suite is complete"
m.notifyReportersOnSuiteComplete()
m.top.rooibosSuiteFinished = true
end function

Expand Down Expand Up @@ -3103,6 +3091,22 @@ namespace rooibos
end for
end function

private sub notifyReportersOnSuiteBegin()
for each reporter in m.testReporters
if rooibos.common.isFunction(reporter.onSuiteBegin)
reporter.onSuiteBegin(m)
end if
end for
end sub

private sub notifyReportersOnSuiteComplete()
for each reporter in m.testReporters
if rooibos.common.isFunction(reporter.onSuiteComplete)
reporter.onSuiteComplete(m)
end if
end for
end sub

end class


Expand Down
32 changes: 32 additions & 0 deletions framework/src/source/ConsoleTestReporter.bs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@ namespace rooibos
end if
end function

override function onSuiteBegin(suite as rooibos.BaseTestSuite)
? ""
? rooibos.common.fillText("> SUITE: " + suite.name, ">", 80)
end function

override function onTestGroupBegin(group as rooibos.TestGroup)
? ""
? rooibos.common.fillText(">>>> Describe: " + group.name, ">", 80)
'bs:disable-next-line
? ` Location: file://${group.testSuite.filePath.trim()}:${group.lineNumber}`
? ""
end function

override function onTestBegin(test as rooibos.Test)
? ""
? rooibos.common.fillText(">>>>>> It: " + test.name, ">", 80)
? ` Location: file://${test.testSuite.filePath.trim()}:${test.lineNumber}`
? ""
end function

override function onTestComplete(test as rooibos.Test)
? rooibos.common.fillText("<<<< END It: " + test.name + " (" + test.result.getStatusText() + ") ", "<", 80)
end function

' override function onTestGroupComplete(group as rooibos.TestGroup)
' 'override me
' end function

' override function onSuiteComplete(suite as rooibos.BaseTestSuite)
' 'override me
' end function

override function onEnd(ev as rooibos.ITestReporterOnEndEvent)
m.allStats = ev.stats
m.startReport()
Expand Down
48 changes: 48 additions & 0 deletions framework/src/source/MochaTestReporter.bs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,54 @@ namespace rooibos

private failureCount = 0

override function onSuiteBegin(suite as rooibos.BaseTestSuite)
? suite.name
end function

override function onTestGroupBegin(group as rooibos.TestGroup)
? tab(2) group.name
end function

' override function onTestBegin(test as rooibos.Test)
' 'override me
' end function

override function onTestComplete(test as rooibos.Test)
passed = test.result.getStatusText() = "PASS"
if passed
symbol = "✔"
else
symbol = "✖️"
end if

params = ""
if test.isParamTest
rawParams = invalid
if type(test.rawParams) = "roAssociativeArray"
rawParams = {}
for each key in test.rawParams
if type(test.rawParams[key]) <> "Function" and type(test.rawParams[key]) <> "roFunction"
rawParams[key] = test.rawParams[key]
end if
end for
else
rawParams = test.rawParams
end if

params = " " + formatJson(rawParams)
end if

? tab(4) symbol + " " + test.name + params
end function

' override function onTestGroupComplete(group as rooibos.TestGroup)
' 'override me
' end function

' override function onSuiteComplete(suite as rooibos.BaseTestSuite)
' 'override me
' end function

override function onEnd(ev as rooibos.ITestReporterOnEndEvent)
print "Rooibos Version:" m.testRunner.runtimeConfig.getVersionText()

Expand Down
39 changes: 39 additions & 0 deletions framework/src/source/TestGroup.bs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace rooibos
' ? ">>>>>>>>>>>>"
' ? " RUNNING TEST GROUP"
m.testRunner = m.testSuite.testRunner
m.notifyReportersOnTestGroupBegin()
m.testSuite.setTestTimer(0)
if m.testSuite.isAsync = true
' ? " THIS GROUP IS ASYNC"
Expand All @@ -83,7 +84,9 @@ namespace rooibos
isOk = m.runSuiteFunction(m.beforeEachFunctionName, "beforeEach", test)

if isOk
m.notifyReportersOnTestBegin(test)
m.testSuite.runTest(test)
m.notifyReportersOnTestComplete(test)
end if

m.runSuiteFunction(m.afterEachFunctionName, "afterEach", test)
Expand All @@ -98,6 +101,7 @@ namespace rooibos
else
? "ERROR running test setup function"
end if
m.notifyReportersOnTestGroupComplete()
m.runSuiteFunction(m.tearDownFunctionName, "tearDown")
end function

Expand Down Expand Up @@ -138,6 +142,7 @@ namespace rooibos
test = m.currentTest
if test.isAsync <> true
? "Executing test synchronously"
m.notifyReportersOnTestBegin(test)
m.testSuite.runTest(test)
m.testRunner.top.rooibosTestFinished = true
m.onAsyncTestComplete()
Expand All @@ -146,6 +151,7 @@ namespace rooibos
if test.isAsync = true
m.testSuite.setTestTimer(test.asyncTimeout)
end if
m.notifyReportersOnTestBegin(test)
m.testSuite.runTest(test)

if test.result.isFail
Expand All @@ -166,6 +172,7 @@ namespace rooibos

private function onAsyncTestComplete()
' ? "++ CURRENT TEST COMPLETED"
m.notifyReportersOnTestComplete(m.currentTest)
m.runSuiteFunction(m.afterEachFunctionName, "afterEach", m.currentTest)

m.testRunner.top.unobserveFieldScoped("rooibosTestFinished")
Expand Down Expand Up @@ -193,6 +200,7 @@ namespace rooibos
' tests: m.tests
' }
' })
m.notifyReportersOnTestGroupComplete()
m.testSuite.testGroupDone()
end function

Expand Down Expand Up @@ -220,6 +228,37 @@ namespace rooibos
return false
end function

private sub notifyReportersOnTestGroupBegin()
for each reporter in m.testSuite.testReporters
if rooibos.common.isFunction(reporter.onTestGroupBegin)
reporter.onTestGroupBegin(m)
end if
end for
end sub

private sub notifyReportersOnTestBegin(test as rooibos.Test)
for each reporter in m.testSuite.testReporters
if rooibos.common.isFunction(reporter.onTestBegin)
reporter.onTestBegin(test)
end if
end for
end sub

private sub notifyReportersOnTestComplete(test as rooibos.Test)
for each reporter in m.testSuite.testReporters
if rooibos.common.isFunction(reporter.onTestComplete)
reporter.onTestComplete(test)
end if
end for
end sub

private sub notifyReportersOnTestGroupComplete()
for each reporter in m.testSuite.testReporters
if rooibos.common.isFunction(reporter.onTestGroupComplete)
reporter.onTestGroupComplete(m)
end if
end for
end sub
end class

function onTestComplete()
Expand Down
5 changes: 3 additions & 2 deletions framework/src/source/TestRunner.bs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ namespace rooibos
testSuite = invalid
if suiteClass <> invalid
testSuite = suiteClass()
testSuite.testRunner = m
testSuite.testReporters = m.testReporters
testSuite.global = m.nodeContext.global
testSuite.context = m.nodeContext
testSuite.top = m.nodeContext.top
Expand Down Expand Up @@ -138,6 +140,7 @@ namespace rooibos

if suiteClass <> invalid
testSuite = suiteClass()
testSuite.testReporters = m.testReporters
testSuite.global = m.nodeContext.global
testSuite.node = m.nodeContext
testSuite.top = m.nodeContext.top
Expand Down Expand Up @@ -197,8 +200,6 @@ namespace rooibos

private function runTestSuite(testSuite) as void
if testSuite.groupsData <> invalid and testSuite.groupsData.count() > 0
? ""
? rooibos.common.fillText("> SUITE: " + testSuite.name, ">", 80)
m.testSuites.push(testSuite)

if testSuite.isNodeTest
Expand Down

0 comments on commit 512ca3a

Please sign in to comment.