rooibos-roku 4.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -0
  3. package/dist/lib/framework/BaseTestReporter.bs +27 -0
  4. package/dist/lib/framework/BaseTestSuite.bs +2131 -0
  5. package/dist/lib/framework/CommonUtils.bs +732 -0
  6. package/dist/lib/framework/ConsoleTestReporter.bs +200 -0
  7. package/dist/lib/framework/Coverage.bs +51 -0
  8. package/dist/lib/framework/Matchers.bs +28 -0
  9. package/dist/lib/framework/Rooibos.bs +83 -0
  10. package/dist/lib/framework/RooibosScene.xml +50 -0
  11. package/dist/lib/framework/RuntimeConfig.bs +20 -0
  12. package/dist/lib/framework/Stats.bs +46 -0
  13. package/dist/lib/framework/Test.bs +109 -0
  14. package/dist/lib/framework/TestGroup.bs +109 -0
  15. package/dist/lib/framework/TestResult.bs +74 -0
  16. package/dist/lib/framework/TestRunner.bs +187 -0
  17. package/dist/lib/framework/Utils.bs +63 -0
  18. package/dist/lib/framework/unused/CodeCoverage.brs +35 -0
  19. package/dist/lib/framework/unused/CodeCoverage.xml +13 -0
  20. package/dist/lib/framework/unused/CodeCoverageSupport.brs +56 -0
  21. package/dist/lib/rooibos/Annotation.js +187 -0
  22. package/dist/lib/rooibos/Annotation.js.map +1 -0
  23. package/dist/lib/rooibos/CodeCoverageProcessor.js +114 -0
  24. package/dist/lib/rooibos/CodeCoverageProcessor.js.map +1 -0
  25. package/dist/lib/rooibos/CodeCoverageProcessor.spec.js +62 -0
  26. package/dist/lib/rooibos/CodeCoverageProcessor.spec.js.map +1 -0
  27. package/dist/lib/rooibos/CodeCoverageType.js +11 -0
  28. package/dist/lib/rooibos/CodeCoverageType.js.map +1 -0
  29. package/dist/lib/rooibos/FileFactory.js +92 -0
  30. package/dist/lib/rooibos/FileFactory.js.map +1 -0
  31. package/dist/lib/rooibos/RawCodeStatement.js +21 -0
  32. package/dist/lib/rooibos/RawCodeStatement.js.map +1 -0
  33. package/dist/lib/rooibos/RooibosConfig.js +11 -0
  34. package/dist/lib/rooibos/RooibosConfig.js.map +1 -0
  35. package/dist/lib/rooibos/RooibosSession.js +151 -0
  36. package/dist/lib/rooibos/RooibosSession.js.map +1 -0
  37. package/dist/lib/rooibos/RooibosSessionInfo.js +181 -0
  38. package/dist/lib/rooibos/RooibosSessionInfo.js.map +1 -0
  39. package/dist/lib/rooibos/TestCase.js +65 -0
  40. package/dist/lib/rooibos/TestCase.js.map +1 -0
  41. package/dist/lib/rooibos/TestGroup.js +86 -0
  42. package/dist/lib/rooibos/TestGroup.js.map +1 -0
  43. package/dist/lib/rooibos/TestSuite.js +118 -0
  44. package/dist/lib/rooibos/TestSuite.js.map +1 -0
  45. package/dist/lib/rooibos/TestSuiteBuilder.js +192 -0
  46. package/dist/lib/rooibos/TestSuiteBuilder.js.map +1 -0
  47. package/dist/lib/rooibos/TestSuiteBuilder.spec.js +1126 -0
  48. package/dist/lib/rooibos/TestSuiteBuilder.spec.js.map +1 -0
  49. package/dist/lib/rooibos/Utils.js +173 -0
  50. package/dist/lib/rooibos/Utils.js.map +1 -0
  51. package/dist/lib/utils/Diagnostics.js +116 -0
  52. package/dist/lib/utils/Diagnostics.js.map +1 -0
  53. package/dist/lib/utils/testHelpers.spec.js +24 -0
  54. package/dist/lib/utils/testHelpers.spec.js.map +1 -0
  55. package/dist/plugin.js +116 -0
  56. package/dist/plugin.js.map +1 -0
  57. package/package.json +110 -0
@@ -0,0 +1,109 @@
1
+ namespace rooibos
2
+ class Test
3
+
4
+ public name
5
+ public isSolo
6
+ public noCatch = false
7
+ public funcName
8
+ public isIgnored
9
+ public lineNumber
10
+ public paramLineNumber
11
+ public testSuite = invalid
12
+ public testGroup = invalid
13
+
14
+ public rawParams
15
+ public paramTestIndex
16
+ public isParamTest = false
17
+ public isParamsValid = false
18
+ public expectedNumberOfParams = 0
19
+
20
+ public result = invalid
21
+
22
+ function new(testGroup, data)
23
+ m.testGroup = testGroup
24
+ m.testSuite = testGroup.testSuite
25
+ m.isSolo = data.isSolo
26
+ m.noCatch = data.noCatch
27
+ m.funcName = data.funcName
28
+ m.isIgnored = data.isIgnored
29
+ m.name = data.name
30
+ m.lineNumber = data.lineNumber
31
+ m.paramLineNumber = data.paramLineNumber
32
+ m.rawParams = data.rawParams
33
+ m.paramTestIndex = data.paramTestIndex
34
+ m.isParamTest = data.isParamTest
35
+ m.expectedNumberOfParams = data.expectedNumberOfParams
36
+
37
+ if m.isParamTest
38
+ m.name = m.name + stri(m.paramTestIndex)
39
+ end if
40
+
41
+ m.result = new TestResult(m)
42
+ return this
43
+ end function
44
+
45
+ function run()
46
+ timer = createObject("roTimespan")
47
+ timer.mark()
48
+
49
+ if m.isParamTest
50
+ m.runParamsTest()
51
+ else
52
+ m.testSuite[m.funcName]()
53
+ end if
54
+
55
+ m.result.time = timer.totalMilliseconds()
56
+
57
+ end function
58
+
59
+ function runParamsTest()
60
+ testParams = m.getTestParams()
61
+
62
+ if m.expectedNumberOfParams = 1
63
+ m.testSuite[m.funcName](testParams[0])
64
+ else if m.expectedNumberOfParams = 2
65
+ m.testSuite[m.funcName](testParams[0], testParams[1])
66
+ else if m.expectedNumberOfParams = 3
67
+ m.testSuite[m.funcName](testParams[0], testParams[1], testParams[2])
68
+ else if m.expectedNumberOfParams = 4
69
+ m.testSuite[m.funcName](testParams[0], testParams[1], testParams[2], testParams[3])
70
+ else if m.expectedNumberOfParams = 5
71
+ m.testSuite[m.funcName](testParams[0], testParams[1], testParams[2], testParams[3], testParams[4])
72
+ else if m.expectedNumberOfParams = 6
73
+ m.testSuite[m.funcName](testParams[0], testParams[1], testParams[2], testParams[3], testParams[4], testParams[5])
74
+ else if m.expectedNumberOfParams = 7
75
+ m.testSuite[m.funcName](testParams[0], testParams[1], testParams[2], testParams[3], testParams[4], testParams[5], testParams[6])
76
+ else if m.expectedNumberOfParams = 8
77
+ m.testSuite[m.funcName](testParams[0], testParams[1], testParams[2], testParams[3], testParams[4], testParams[5], testParams[6], testParams[7])
78
+ else if m.expectedNumberOfParams = 9
79
+ m.testSuite[m.funcName](testParams[0], testParams[1], testParams[2], testParams[3], testParams[4], testParams[5], testParams[6], testParams[7], testParams[8])
80
+ else if m.expectedNumberOfParams = 10
81
+ m.testSuite[m.funcName](testParams[0], testParams[1], testParams[2], testParams[3], testParams[4], testParams[5], testParams[6], testParams[7], testParams[8], testParams[9])
82
+ else if m.expectedNumberOfParams = 11
83
+ m.testSuite[m.funcName](testParams[0], testParams[1], testParams[2], testParams[3], testParams[4], testParams[5], testParams[6], testParams[7], testParams[8], testParams[9], testParams[10])
84
+ else if m.expectedNumberOfParams = 12
85
+ m.testSuite[m.funcName](testParams[0], testParams[1], testParams[2], testParams[3], testParams[4], testParams[5], testParams[6], testParams[7], testParams[8], testParams[9], testParams[10], testParams[11])
86
+ else if m.expectedNumberOfParams > 12
87
+ m.testSuite.fail("Test case had more than 12 params. Max of 12 params is supported")
88
+ end if
89
+ end function
90
+
91
+ function getTestParams()
92
+ params = []
93
+ for paramIndex = 0 to m.rawParams.count()
94
+ paramValue = m.rawParams[paramIndex]
95
+ if type(paramValue) = "roString" and len(paramValue) >= 8 and left(paramValue, 8) = "#RBSNode"
96
+ nodeType = "ContentNode"
97
+ paramDirectiveArgs = paramValue.split("|")
98
+ if paramDirectiveArgs.count() > 1
99
+ nodeType = paramDirectiveArgs[1]
100
+ end if
101
+ paramValue = createObject("roSGNode", nodeType)
102
+ end if
103
+ params.push(paramValue)
104
+ end for
105
+ return params
106
+ end function
107
+
108
+ end class
109
+ end namespace
@@ -0,0 +1,109 @@
1
+ namespace rooibos
2
+ ' /**
3
+ ' * @module TestSuite
4
+ ' * @description All brs files that include `'@TestSuite` annotations automatically extend the TestSuite.
5
+ ' * The base test suite contains all of the assertions, and utility methods required to write our tests, as well as being responsible for tracking the state of the tests and groups.
6
+ ' */
7
+ class TestGroup
8
+ 'test state
9
+ name = "Unnamed Suite"
10
+
11
+ testSuite = invalid
12
+ setupFunctionName = invalid
13
+ tearDownFunctionName = invalid
14
+ beforeEachFunctionName = invalid
15
+ afterEachFunctionName = invalid
16
+ isSolo = false
17
+ isLegacy = false
18
+ isIgnored = false
19
+ stats = invalid
20
+ scene = invalid
21
+ lineNumber = 00
22
+ top = invalid
23
+ valid = false
24
+ hasFailures = false
25
+ isNodeTest = false
26
+ nodeName = invalid
27
+ testsData = invalid
28
+ tests = []
29
+
30
+ function new(testSuite, data)
31
+ m.testSuite = testSuite
32
+ m.name = data.name
33
+ m.valid = data.valid
34
+ m.hasFailures = testSuite.hasFailures
35
+ m.isSolo = data.isSolo
36
+ m.isIgnored = data.isIgnored
37
+ m.testsData = data.testCases
38
+ m.isNodeTest = false
39
+ m.nodeName = invalid
40
+ m.setupFunctionName = data.setupFunctionName
41
+ m.tearDownFunctionName = data.tearDownFunctionName
42
+ m.beforeEachFunctionName = data.beforeEachFunctionName
43
+ m.afterEachFunctionName = data.afterEachFunctionName
44
+ m.lineNumber = data.lineNumber
45
+
46
+ 'bs:disable-next-line
47
+ m.global = testSuite.global
48
+ m.top = testSuite.top
49
+ m.scene = testSuite.scene
50
+ m.stats = new Stats()
51
+ end function
52
+
53
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54
+ '++ running
55
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
+
57
+ function run()
58
+ isOk = m.runSuiteFunction(m.setupFunctionName, "setup")
59
+
60
+ if isOk
61
+ for each testData in m.testsData
62
+ test = new Test(m, testData)
63
+ m.tests.push(test)
64
+
65
+ isOk = m.runSuiteFunction(m.beforeEachFunctionName, "beforeEach", test)
66
+
67
+ if isOk
68
+ m.testSuite.runTest(test)
69
+ end if
70
+
71
+ m.runSuiteFunction(m.afterEachFunctionName, "afterEach", test)
72
+
73
+ m.stats.appendTestResult(test.result)
74
+
75
+ if m.stats.hasFailures and m.testSuite.isFailingFast
76
+ ? "Terminating group due to failed test"
77
+ exit for
78
+ end if
79
+ end for
80
+ else
81
+ ? "ERROR running test setup function"
82
+ end if
83
+ m.runSuiteFunction(m.tearDownFunctionName, "tearDown")
84
+ end function
85
+
86
+ private function runSuiteFunction(methodName, defaultMethodName, test = invalid)
87
+
88
+ if methodName = invalid or methodName = ""
89
+ methodName = defaultMethodName
90
+ end if
91
+ if m.testSuite.catchCrashes and not m.testSuite.noCatch and not (test <> invalid and test.noCatch)
92
+ try
93
+ m.testSuite[methodName]()
94
+ return true
95
+ catch error
96
+ if test <> invalid
97
+ test.result.crash("function " + methodName + "crashed!", error)
98
+ end if
99
+ end try
100
+ else
101
+ m.testSuite[methodName]()
102
+ return true
103
+ end if
104
+
105
+ return false
106
+ end function
107
+
108
+ end class
109
+ end namespace
@@ -0,0 +1,74 @@
1
+ namespace rooibos
2
+ class TestResult
3
+
4
+ public isFail = false
5
+ public isCrash = false
6
+ public message = ""
7
+ public lineNumber = -1
8
+ public test = invalid
9
+ public time = 0
10
+ public error = invalid
11
+
12
+ function new(test)
13
+ m.test = test
14
+ end function
15
+
16
+ function reset() as void
17
+ m.isFail = false
18
+ m.isCrash = false
19
+ m.time = 0
20
+ m.message = ""
21
+ m.lineNumber = -1
22
+ end function
23
+
24
+ function fail(message as string, lineNumber = -1)
25
+ if message <> "" and not m.isFail
26
+ if not m.isFail
27
+ m.lineNumber = lineNumber
28
+ m.isFail = true
29
+ m.message = message
30
+ end if
31
+ end if
32
+ end function
33
+
34
+ function crash(message as string, error)
35
+ if message <> "" and not m.isCrash
36
+ if not m.isCrash
37
+ m.error = error
38
+ m.message = "test crashed!"
39
+ m.isFail = true
40
+ m.isCrash = true
41
+ end if
42
+ end if
43
+ end function
44
+
45
+ function getMessage() as string
46
+ if m.isFail
47
+ if m.message <> invalid
48
+ return m.message
49
+ else
50
+ return "unknown test failure"
51
+ end if
52
+ else if m.isCrash
53
+ if m.message <> invalid
54
+ return m.message
55
+ else
56
+ return "unknown test crash"
57
+ end if
58
+ else
59
+ return ""
60
+ end if
61
+ end function
62
+
63
+ function getStatusText()
64
+ if m.isCrash
65
+ return "CRASH"
66
+ else if m.isFail
67
+ return "FAIL"
68
+ else
69
+ return "PASS"
70
+ end if
71
+ end function
72
+
73
+ end class
74
+ end namespace
@@ -0,0 +1,187 @@
1
+ namespace rooibos
2
+ ' /**
3
+ ' * @module TestRunner
4
+ ' */
5
+
6
+ ' /**
7
+ ' * @memberof module:TestRunner
8
+ ' * @name Rooibos_TestRunner
9
+ ' * @function
10
+ ' * @description Creates an instance of the test runner
11
+ ' */
12
+ class TestRunner
13
+ public testScene = invalid
14
+ public testReporter = invalid
15
+ public nodeContext = invalid
16
+ public config = invalid
17
+ public testSuites = []
18
+ private runtimeConfig = invalid
19
+ private stats = invalid
20
+ private top = invalid
21
+
22
+ public function new(testScene, nodeContext)
23
+ m.testScene = testScene
24
+ if nodeContext.top = invalid
25
+ nodeContext.top = testScene
26
+ end if
27
+ nodeContext.scene = testScene
28
+
29
+ m.nodeContext = nodeContext
30
+
31
+ m.stats = new Stats()
32
+ m.runtimeConfig = new RuntimeConfig()
33
+ m.config = m.runtimeConfig.getRuntimeConfig()
34
+ 'TODO - allow providing different reporters via config
35
+ m.testReporter = new Rooibos.ConsoleTestReporter(m)
36
+ end function
37
+
38
+ ' /**
39
+ ' * @memberof module:TestRunner
40
+ ' * @name Run
41
+ ' * @function
42
+ ' * @instance
43
+ ' * @description Executes all tests for a project, as per the config
44
+ ' */
45
+ public function run()
46
+
47
+ timer = createObject("roTimespan")
48
+ timer.mark()
49
+ suiteNames = m.runtimeConfig.getAllTestSuitesNames()
50
+ includedSuites = []
51
+ for each name in suiteNames
52
+ 'bs:disable-next-line
53
+ suiteClass = m.runtimeConfig.getTestSuiteClassWithName(name)
54
+ testSuite = invalid
55
+ if suiteClass <> invalid
56
+ testSuite = suiteClass()
57
+ testSuite.global = m.nodeContext.global
58
+ testSuite.context = m.nodeContext
59
+ testSuite.top = m.nodeContext.top
60
+ testSuite.scene = m.nodeContext.global.testsScene
61
+ testSuite.catchCrashes = m.config.catchCrashes
62
+ m.runTestSuite(testSuite)
63
+ if m.stats.hasFailures = true and m.config.failFast = true
64
+ exit for
65
+ end if
66
+ else
67
+ ? "ERROR! could not create test for suite : "; name
68
+ end if
69
+ end for
70
+
71
+ m.stats.time = timer.totalMilliseconds()
72
+
73
+ m.testReporter.reportResults(m.stats)
74
+
75
+ 'code coverage is not enabled in rooibos 4.0.0 - will get added again in future
76
+ ' if Rooibos.Common.isFunction(RBS_reportCodeCoverage)
77
+ ' 'bs:disable-next-line
78
+ ' RBS_reportCodeCoverage()
79
+
80
+ ' if m.config.printLcov = true
81
+ ' Coverage.printLCovInfo()
82
+ ' end if
83
+ ' end if
84
+ m.sendHomeKeypress()
85
+ end function
86
+
87
+ public function runInNodeMode(nodeTestName)
88
+ 'bs:disable-next-line
89
+ suiteClass = m.getTestSuiteClassWithName(nodeTestName)
90
+ testSuite = invalid
91
+
92
+ if suiteClass <> invalid
93
+ testSuite = suiteClass(m.top)
94
+ end if
95
+
96
+ if testSuite <> invalid
97
+ testSuite.run()
98
+ return {
99
+ stats: testSuite.stats
100
+ tests: testSuite.tests
101
+ }
102
+ else
103
+ ? "[ERROR] could not create test suite " ; nodeTestName
104
+ end if
105
+
106
+ ? "ERROR! executing node test " + nodeTestName + " was unsuccesful."
107
+
108
+ return invalid
109
+ end function
110
+
111
+ private function runTestSuite(testSuite) as void
112
+ if testSuite.groupsData <> invalid and testSuite.groupsData.count() > 0
113
+ ? ""
114
+ ? Rooibos.Common.fillText("> SUITE: " + testSuite.name, ">", 80)
115
+ m.testSuites.push(testSuite)
116
+
117
+ if testSuite.isNodeTest
118
+ m.runNodeTest(testSuite)
119
+ else
120
+ testSuite.run()
121
+ end if
122
+
123
+ m.stats.merge(testSuite.stats)
124
+ end if
125
+ end function
126
+
127
+ private function runNodeTest(testSuite) as void
128
+ if testSuite.generatedNodeName <> ""
129
+ ? " +++++RUNNING NODE TEST"
130
+ ? " node type is " ; testSuite.generatedNodeName
131
+
132
+ node = m.testScene.createChild(testSuite.generatedNodeName)
133
+
134
+ if type(node) = "roSGNode"
135
+ nodeResults = node.rooibosTestResult
136
+ if nodeResults <> invalid
137
+ testSuite.stats = nodeResults.stats
138
+ testSuite.testCases = nodeResults.testCases
139
+ else
140
+ ? " ERROR! The node test"; testSuite.name; " did not return a result from from the rooibos_runNodeTestSuite method. This usually means you are not importing rooibos.brs and the required test file. Please refer to : https://github.com/georgejecook/rooibos/blob/master/docs/index.md#testing-scenegraph-nodes"
141
+ end if
142
+ m.testScene.removeChild(node)
143
+ return
144
+
145
+ else
146
+ ? " ERROR!! - could not create node required to execute tests for " ; testSuite.name
147
+ ? " Node of type " ; testSuite.generatedNodeName ; " was not found/could not be instantiated"
148
+ end if
149
+
150
+ else
151
+ ? " ERROR!! - could not create node required to execute tests for " ; testSuite.name
152
+ ? " No node type was provided"
153
+ end if
154
+
155
+ testSuite.stats.hasFailures = true
156
+ testSuite.failedCount += testSuite.testsData.count()
157
+ end function
158
+
159
+ private function sendHomeKeypress()
160
+ ut = createObject("roUrlTransfer")
161
+ ut.SetUrl("http://localhost:8060/keypress/Home")
162
+ ut.PostFromString("")
163
+ end function
164
+
165
+ end class
166
+
167
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
168
+ '++ This code is called inside of the node
169
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
170
+
171
+ function createTestNode(nodeType) as object
172
+ node = createObject("roSGNode", nodeType)
173
+
174
+ if type(node) = "roSGNode" and node.subType() = nodeType
175
+ m.top.AppendChild(node)
176
+ return node
177
+ else
178
+ ? " Error creating test node of type " ; nodeType
179
+ return invalid
180
+ end if
181
+ end function
182
+
183
+ function runNodeTestSuite(name)
184
+ nodeRunner = new TestRunner(m.top.getScene(), m)
185
+ return nodeRunner.runInNodeMode(name)
186
+ end function
187
+ end namespace