Skip to content

Commit

Permalink
2.2.0 - adds ability to pass node scope into the test runner, for non…
Browse files Browse the repository at this point in the history
…-node tests so node-scoped functions/vars can be accessed
  • Loading branch information
George Cook committed Apr 27, 2019
1 parent 189b1be commit 67527eb
Show file tree
Hide file tree
Showing 24 changed files with 3,321 additions and 14 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Rooibos CHANGELOG

## 2.2.0

### Added

- sets the node property on non-node test suites. This allows you to access the global namespace, in case you are testing mixin methods, or other non-scoped code (i.e. the equivalent of accessing `method` as opposed to `m.method` or `myObject.method`)

### Changed

### Deprecated

### Removed

### Fixed

## 2.1.4

### Added
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.4
2.2.0
11 changes: 8 additions & 3 deletions dist/rooibosDist.brs
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
'/**
' * rooibos - simple, flexible, fun brightscript test framework for roku scenegraph apps
' * @version v2.1.4
' * @version v2.2.0
' * @link https://github.com/georgejecook/rooibos#readme
' * @license MIT
' */
function Rooibos__Init(preTestSetup = invalid, testUtilsDecoratorMethodName = invalid, testSceneName = "TestsScene") as void
function Rooibos__Init(preTestSetup = invalid, testUtilsDecoratorMethodName = invalid, testSceneName = invalid, nodeContext = invalid) as void
args = {}
if createObject("roAPPInfo").IsDev() <> true then
? " not running in dev mode! - rooibos tests only support sideloaded builds - aborting"
return
end if
args.testUtilsDecoratorMethodName = testUtilsDecoratorMethodName
args.nodeContext = nodeContext
screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
screen.setMessagePort(m.port)
if testSceneName = invalid
testSceneName = "TestsScene"
end if
? "Starting test using test scene with name TestsScene" ; testSceneName
scene = screen.CreateScene(testSceneName)
scene.id = "ROOT"
Expand Down Expand Up @@ -1924,6 +1928,7 @@ end function
function RBS_TR_TestRunner(args = {}) as object
this = {}
this.testScene = args.testScene
this.nodeContext = args.nodeContext
fs = CreateObject("roFileSystem")
defaultConfig = {
logLevel : 1,
Expand Down Expand Up @@ -2021,7 +2026,7 @@ sub RBS_TR_Run()
if (metaTestSuite.hasIgnoredTests)
totalStatObj.IgnoredTestNames.push("|-" + metaTestSuite.name)
end if
RBS_RT_RunItGroups(metaTestSuite, totalStatObj, m.testUtilsDecoratorMethodName, m.config, m.runtimeConfig)
RBS_RT_RunItGroups(metaTestSuite, totalStatObj, m.testUtilsDecoratorMethodName, m.config, m.runtimeConfig, m.nodeContext)
end if
skipSuite:
end for
Expand Down
30 changes: 28 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Simple, mocha-inspired, flexible, fun Brightscript test framework for ROKU apps

## FEATURES
- [Easy to integrate](#easy-to-integrate)
- [Compatible with legacy unit testing framework](#compatible-with-legacy-framework)
- [Simple, annotation-based, syntax for writing tests](#simple-syntax-for-writing-tests)
- [No need for special file names, or method names](#no-need-for-special-file-or-method-names)
- [Common TDD methods such as Setup/TearDown/BeforeEach/AfterEach](#common-tdd-methods)
Expand Down Expand Up @@ -563,7 +562,34 @@ end function

Note: The test utils decorator and all of it's dependencies must be visible to the current exeucting test. That means if you have a node test you must include the script file containing the `testCase.testUtils` method, and all other methods it invokes. The sample app contains an example.

Non-node tests should find all methods are automatically in scope
### Accessing global scope

Non-node tests should find all methods are automatically in scope; however, if you need to access the node scope to test anonymous, or mixin methods, this is also supported. You can make your global scope available by calling `Rooibos__Init` and passing in a reference to your scope, as such

```
sub Main(args as dynamic)
if (type(Rooibos__Init) = "Function") then Rooibos__Init(SetupGlobals, "AddTestUtils", invalid, m)
end sub
```

You can then access a node scoped method (i.e. one that is not on m, or on any other object) in the following way:

```
'@Test
function BT_globalScope() as void
m.assertNotInvalid(m.node)
BT_doSomethingInNodeScope(true)
m.assertInvalid(m._isNodeScopeVarSet)
m.assertTrue(m.node. _isNodeScopeVarSet)
end function
function BT_doSomethingInNodeScope(value)
m._isNodeScopeVarSet = value
end function
```


## Using mocks and stubs
<a name="mocks-and-stubs"></a>
Expand Down
2 changes: 1 addition & 1 deletion frameworkTests/source/main.brs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sub Main(args as dynamic)
if (type(Rooibos__Init) = "Function") then Rooibos__Init(SetupGlobals, "AddTestUtils")
if (type(Rooibos__Init) = "Function") then Rooibos__Init(SetupGlobals, "AddTestUtils", invalid, m)

InitScreen()
end sub
Expand Down
17 changes: 17 additions & 0 deletions frameworkTests/source/tests/BasicTests.brs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'@TestSuite [BT] Basic tests

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'@It tests the node context is available for a Node scope function
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'@Test
function BT_NodeScope() as void
m.assertNotInvalid(m.node)
BT_doSomethingInNodeScope(true)
m.assertInvalid(m._isNodeScopeVarSet)
m.assertTrue(m.node._isNodeScopeVarSet)
end function

function BT_doSomethingInNodeScope(value)
m._isNodeScopeVarSet = value
end function
8 changes: 8 additions & 0 deletions outRun/.roku-deploy-staging/components/TestsScene.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<component name="TestsScene" extends="Scene">
<children>
<LayoutGroup>
<Label text="Rooibos tests are running" />
</LayoutGroup>
</children>
</component>
4 changes: 4 additions & 0 deletions outRun/.roku-deploy-staging/manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
title=Rooibos
major_version=0
minor_version=2
build_version=0
57 changes: 57 additions & 0 deletions outRun/.roku-deploy-staging/source/main.brs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
sub Main(args as dynamic)
if (type(Rooibos__Init) = "Function") then Rooibos__Init(SetupGlobals, "AddTestUtils", invalid, m)

InitScreen()
end sub

function InitScreen() as void
'this will be where you setup your typical roku app
'it will not be launched when running unit tests
screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
screen.setMessagePort(m.port)

rootScene = screen.CreateScene("TestsScene")
rootScene.id = "ROOT"

screen.show()

SetupGlobals(screen)

while(true)
msg = wait(0, m.port)
msgType = type(msg)

if msgType = "roSGScreenEvent"
if msg.isScreenClosed()
return
end if
end if
end while
end function


'*************************************************************
'** SetupGlobals
'** @param screen as roScreen - screen to set globals on
'*************************************************************
function SetupGlobals(screen) as void
? "SETTTING UP GLOBALS - do your standard setup stuff here"

m.global = screen.getGlobalNode()

m.roDeviceInfo = CreateObject("roDeviceInfo")

m.displayInfo = {
resolution: m.roDeviceInfo.GetUIResolution()
displayType: m.roDeviceInfo.GetDisplayType()
width: m.roDeviceInfo.GetDisplaySize().w
height: m.roDeviceInfo.GetDisplaySize().h
wFactor: m.roDeviceInfo.GetDisplaySize().w/1920
hFactor: m.roDeviceInfo.GetDisplaySize().h/1080
}

m.modelLocator = {"displayInfo":m.displayInfo} ' contrived example : this would be a specifc modelLocator node/other setup thing

m.global.addFields({"modelLocator": m.modelLocator})
end function
Loading

0 comments on commit 67527eb

Please sign in to comment.