Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sets default types for m.top and m.node in BaseTestSuite #301

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bsc-plugin/src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,9 @@ describe('RooibosPlugin', () => {
});

describe.skip('run a local project', () => {

// TODO: This project should include its own app to run tests on
// Perhaps using https://github.com/lvcabral/brs-engine to run non-node tests
it('sanity checks on parsing - only run this outside of ci', () => {
let programBuilder = new ProgramBuilder();
let swv = {
Expand Down
24 changes: 15 additions & 9 deletions framework/src/source/BaseTestSuite.bs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ namespace rooibos

public isDoneCalled = false

public top as NodeWithRooibosFields = invalid
' Reference to the tested node in Node tests
' Defined as object so it can be easily typed in tests
public top as object = invalid
' Reference to the 'm' of the tested node in node tests
' Defined as object so it can be easily typed in tests
public node as object = invalid

public tests as Test[] = []

Expand Down Expand Up @@ -200,23 +205,24 @@ namespace rooibos
m.finishAsyncGroups()
else
group = m.currentGroup
m.testRunner.top.rooibosGroupFinished = false
testRunnerTop as NodeWithRooibosFields = m.testRunner.top
testRunnerTop.rooibosGroupFinished = false

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

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

group.run()

if group.stats.hasFailures
? "Group failed before any async code could be executed"
m.testRunner.top.unobserveFieldScoped("rooibosGroupFinished")
testRunnerTop.unobserveFieldScoped("rooibosGroupFinished")
' m.testGroupDone()
m.onAsyncGroupComplete(group)
else if m.testRunner.top.rooibosGroupFinished
else if testRunnerTop.rooibosGroupFinished
m.onAsyncGroupComplete(group)
end if

Expand Down Expand Up @@ -2677,27 +2683,27 @@ namespace rooibos

function setAsync(isAsync as boolean)
? "Setting current test to async " isAsync
m.top.rooibosTestIsAsync = isAsync
(m.top as NodeWithRooibosFields).rooibosTestIsAsync = isAsync
end function

function done()
' ? "Async test is complete"
if m.isDoneCalled = false
m.isDoneCalled = true
m.top.rooibosTestFinished = true
(m.top as NodeWithRooibosFields).rooibosTestFinished = true
else
? "WARNING - extra done call after test is done ! Did you properly clean up your observers?"
end if
end function

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

function testGroupDone()
? "Async group is complete"
m.top.rooibosGroupFinished = true
(m.top as NodeWithRooibosFields).rooibosGroupFinished = true
end function

function assertAsyncField(target, fieldName, delay = 500, maxAttempts = 10)
Expand Down
11 changes: 6 additions & 5 deletions framework/src/source/TestGroup.bs
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,28 @@ namespace rooibos
'finished
m.finishAsyncTests()
else
m.testRunner.top.rooibosTestFinished = false
testRunnerTop as NodeWithRooibosFields = m.testRunner.top
testRunnerTop.rooibosTestFinished = false
isOk = m.runSuiteFunction(m.beforeEachFunctionName, "beforeEach", m.currentTest)
if isOk
'TODO - set a timeout here
currentTest = m.currentTest
if currentTest?.isAsync <> true
? "Executing test synchronously"
m.testSuite.runTest(currentTest)
m.testRunner.top.rooibosTestFinished = true
testRunnerTop.rooibosTestFinished = true
m.onAsyncTestComplete()
else
m.testRunner.top.observeFieldScoped("rooibosTestFinished", "rooibos_onTestComplete")
testRunnerTop.observeFieldScoped("rooibosTestFinished", "rooibos_onTestComplete")
if currentTest.isAsync = true
m.testSuite.setTestTimer(currentTest.asyncTimeout)
end if
m.testSuite.runTest(currentTest)

if currentTest.result.isFail
? "Test failed before any async code could be executed"
m.testRunner.top.unobserveFieldScoped("rooibosTestFinished")
m.testRunner.top.rooibosTestFinished = true
testRunnerTop.unobserveFieldScoped("rooibosTestFinished")
testRunnerTop.rooibosTestFinished = true
m.onAsyncTestComplete()
end if
end if
Expand Down
22 changes: 15 additions & 7 deletions framework/src/source/TestRunner.bs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace rooibos
public testSuites as BaseTestSuite[] = []
private runtimeConfig as RuntimeConfig = invalid
private stats as Stats = invalid
public top as NodeWithRooibosFields = invalid
public top as roSGNode = invalid
public node as roAssociativeArray = invalid
private nodeTestName = ""
private currentTestSuite as BaseTestSuite = invalid
public currentGroup as TestGroup = invalid
Expand Down Expand Up @@ -151,10 +152,10 @@ namespace rooibos
m.nodeTestName = nodeTestName
m.nodeContext.testRunner = m
m.nodeContext.top.addFields({
"rooibosSuiteFinished": false
"rooibosTestFinished": false
"rooibosTestIsAsync": false
"rooibosGroupFinished": false
rooibosSuiteFinished: false
rooibosTestFinished: false
rooibosTestIsAsync: false
rooibosGroupFinished: false
})

end if
Expand Down Expand Up @@ -244,7 +245,7 @@ namespace rooibos
? " +++++RUNNING NODE TEST"
? " node type is " ; testSuite.generatedNodeName

node = m.testScene.createChild(testSuite.generatedNodeName)
node = m.testScene.createChild(testSuite.generatedNodeName) as NodeWithRooibosFields
'wait on the field

if type(node) = "roSGNode"
Expand Down Expand Up @@ -276,7 +277,7 @@ namespace rooibos
else
? " ERROR! The node test"; testSuite.name; " did not indicate test completion. Did you call m.done() in your test? Did you correctly configure your node test? Please refer to : https://github.com/rokucommunity/rooibos/blob/master/docs/index.md#testing-scenegraph-nodes"
end if
m.testScene.removeChild(node)
m.testScene.removeChild(node as roSGNode)
return

else
Expand Down Expand Up @@ -362,6 +363,13 @@ namespace rooibos
rooibosTestFinished as boolean
rooibosTestIsAsync as boolean
rooibosGroupFinished as boolean
asyncRooibosTestResult
end interface

interface AsyncRooibosTestResult
stats as rooibos.Stats
tests as rooibos.Test[]
groups as rooibos.TestGroup[]
end interface

end namespace
43 changes: 4 additions & 39 deletions tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions tests/src/source/Assertion.spec.bs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import "pkg:/source/rooibos/BaseTestSuite.bs"
markwpearce marked this conversation as resolved.
Show resolved Hide resolved


namespace tests

@noEarlyExit
Expand Down