Skip to content

Commit

Permalink
Merge pull request #46 from georgejecook/feature/code_coverage
Browse files Browse the repository at this point in the history
Feature/code coverage
  • Loading branch information
georgejecook authored May 26, 2019
2 parents f960e52 + 8d03468 commit 8773221
Show file tree
Hide file tree
Showing 34 changed files with 1,103 additions and 2,709 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ local.properties
#node
node_modules/
frameworkTests/source/tests/rooibosDist.brs
outRun
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Rooibos CHANGELOG

## 3.0.0-beta

### Added

- Code coverage support!

### Changed

- there are breaking changes in rooibos-preprocessor which, are required for code coverage. I'm keeping the major versions of rooibos and rooibos-preprocessor in sync, due to documentation, and everyone's sanity

### Deprecated

### Removed

### Fixed
- #45 - crash when checking an expect param, and one of the params is a mock/stub
- #40 - can now use / in the params - much better parsing, too

## 2.3.0

### Added
Expand Down
19 changes: 12 additions & 7 deletions dist/rooibosDist.brs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'/**
' * rooibos - simple, flexible, fun brightscript test framework for roku scenegraph apps
' * @version v2.3.0
' * @version v3.0.0-beta
' * @link https://github.com/georgejecook/rooibos#readme
' * @license MIT
' */
Expand Down Expand Up @@ -674,13 +674,15 @@ function RBS_BTS_EqAssocArray(Value1 , Value2 ) as dynamic
return false
else
for each k in Value1
if not Value2.DoesExist(k)
return false
else
v1 = Value1[k]
v2 = Value2[k]
if not RBS_BTS_EqValues(v1, v2)
if k <> "__mocks" and k <> "__stubs" 'fix infinite loop/box crash when doing equals on an aa with a mock
if not Value2.DoesExist(k)
return false
else
v1 = Value1[k]
v2 = Value2[k]
if not RBS_BTS_EqValues(v1, v2)
return false
end if
end if
end if
end for
Expand Down Expand Up @@ -2032,6 +2034,9 @@ sub RBS_TR_Run()
skipSuite:
end for
m.logger.PrintStatistic(totalStatObj)
if RBS_CMN_IsFunction(RBS_ReportCodeCoverage)
RBS_ReportCodeCoverage()
end if
RBS_TR_SendHomeKeypress()
end sub
sub RBS_RT_RunItGroups(metaTestSuite, totalStatObj, testUtilsDecoratorMethodName, config, runtimeConfig, nodeContext = invalid)
Expand Down
2 changes: 1 addition & 1 deletion docs/Rooibos.brs.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ <h1 class="page-title">Rooibos.brs</h1>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Apr 26 2019 22:57:27 GMT-0500 (-05) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat May 25 2019 22:57:12 GMT-0500 (-05) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
16 changes: 9 additions & 7 deletions docs/Rooibos_BaseTestSuite.brs.html
Original file line number Diff line number Diff line change
Expand Up @@ -1053,13 +1053,15 @@ <h1 class="page-title">Rooibos_BaseTestSuite.brs</h1>
return false
else
for each k in Value1
if not Value2.DoesExist(k)
return false
else
v1 = Value1[k]
v2 = Value2[k]
if not RBS_BTS_EqValues(v1, v2)
if k &lt;> "__mocks" and k &lt;> "__stubs" 'fix infinite loop/box crash when doing equals on an aa with a mock
if not Value2.DoesExist(k)
return false
else
v1 = Value1[k]
v2 = Value2[k]
if not RBS_BTS_EqValues(v1, v2)
return false
end if
end if
end if
end for
Expand Down Expand Up @@ -2003,7 +2005,7 @@ <h1 class="page-title">Rooibos_BaseTestSuite.brs</h1>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Apr 26 2019 22:57:27 GMT-0500 (-05) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat May 25 2019 22:57:12 GMT-0500 (-05) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Rooibos_CommonUtils.brs.html
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ <h1 class="page-title">Rooibos_CommonUtils.brs</h1>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Apr 26 2019 22:57:27 GMT-0500 (-05) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat May 25 2019 22:57:12 GMT-0500 (-05) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Rooibos_ItemGenerator.brs.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ <h1 class="page-title">Rooibos_ItemGenerator.brs</h1>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Apr 26 2019 22:57:27 GMT-0500 (-05) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat May 25 2019 22:57:12 GMT-0500 (-05) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
12 changes: 10 additions & 2 deletions docs/Rooibos_TestRunner.brs.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ <h1 class="page-title">Rooibos_TestRunner.brs</h1>
end if
skipSuite:
end for

m.logger.PrintStatistic(totalStatObj)

if RBS_CMN_IsFunction(RBS_ReportCodeCoverage)
RBS_ReportCodeCoverage()
end if
RBS_TR_SendHomeKeypress()
end sub

Expand Down Expand Up @@ -292,6 +295,7 @@ <h1 class="page-title">Rooibos_TestRunner.brs</h1>
end if

testTimer = CreateObject("roTimespan")
testCaseTimer = CreateObject("roTimespan")
testStatObj = RBS_STATS_CreateTestStatistic(testCase.Name)
testSuite.testCase = testCase.Func
testStatObj.filePath = metaTestSuite.filePath
Expand All @@ -315,6 +319,7 @@ <h1 class="page-title">Rooibos_TestRunner.brs</h1>
end if
testCaseParams.push(paramValue)
end for
testCaseTimer.mark()
'up to 6 param args supported for now
if (metaTestCase.expectedNumberOfParams = 1)
testSuite.testCase(testCaseParams[0])
Expand All @@ -329,8 +334,11 @@ <h1 class="page-title">Rooibos_TestRunner.brs</h1>
else if (metaTestCase.expectedNumberOfParams = 6)
testSuite.testCase(testCaseParams[0], testCaseParams[1], testCaseParams[2], testCaseParams[3], testCaseParams[4], testCaseParams[5])
end if
metaTestCase.time = testCaseTimer.totalMilliseconds()
else
testCaseTimer.mark()
testSuite.testCase()
metaTestCase.time = testCaseTimer.totalMilliseconds()
end if
else
testSuite.Fail("Could not parse args for test ")
Expand Down Expand Up @@ -428,7 +436,7 @@ <h1 class="page-title">Rooibos_TestRunner.brs</h1>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Apr 26 2019 22:57:27 GMT-0500 (-05) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat May 25 2019 22:57:12 GMT-0500 (-05) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Apr 26 2019 22:57:27 GMT-0500 (-05) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat May 25 2019 22:57:12 GMT-0500 (-05) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
78 changes: 68 additions & 10 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Simple, mocha-inspired, flexible, fun Brightscript test framework for ROKU apps
- [Hook into your global setup mechanisms](#hook-into-your-global-setup-mechanisms)
- [Only show output for failed tests](#only-show-output-for-failed-tests)
- [Easily integrate into any CI system](#easily-integrate-into-any-ci-system)
- [Generate code coverage](#generate-code-coverage)


## TABLE OF CONTENTS
Expand Down Expand Up @@ -81,13 +82,22 @@ To get the best performance and test flexibility, rooibos leverages a typescript
The following working gulpfile can be found in my [roku MVVM spike](https://github.com/georgejecook/rokuNavSpike/tree/feature/viewModels); but the process is as follows.

- `npm install rooibos-preprocessor --save-dev`
- Add the following to the top of gulpfile.ts `import { RooibosProcessor } from "rooibos-preprocessor";`
- Add the following to the top of gulpfile.ts `import { RooibosProcessor, createProcessorConfig, ProcessorConfig } from 'rooibos-preprocessor';`
- Create a task to process your test files, such as:

```
export async function prepareTests(cb) {
await rokuDeploy.prepublishToStaging(args);
let processor = new RooibosProcessor('build/.roku-deploy-staging/source/tests', 'build/.roku-deploy-staging', 'build/.roku-deploy-staging/source/tests');
let config = createProcessorConfig({
"projectPath": "build"
"testsFilePattern": [
"**/tests/**/*.brs",
"!**/rooibosDist.brs",
"!**/rooibosFunctionMap.brs",
"!**/TestsScene.brs"
]
});
let processor = new RooibosProcessor(config);
processor.processFiles();
cb();
Expand All @@ -105,26 +115,33 @@ There are two ways to invoke RooibosC:

1. Define a config file that returns a JSON object and tell RooibosC to use that via the `-c` flag:

```sh
```
rooibosC -c path/to/config.json
```

_To see an example config file take a look at the [Example app](../samples/example)_
<br>

2. Use the `-t -r -o` flags to set your paths like so:
2. Alternately, use the following flags to configure test behaviour, like so:

```sh
rooibosC -t source/tests/specs -r ./ -o source/tests/rooibos
rooibosC -p ./ -t source/tests
```
### Description of rooibosC flags


| flag | argument | Fescription |
|--- |--- |:-: |--: |--- |
| `-p` | `--projectPath` | the path to the root of your project. This is used to fix the `pkg:/locations` in rooibos's output. | |
| `-t` | `--testsFilePattern` | array of globs, specifying which test files (i.e. your test _.brs_ files) to include. Relative to projectPath, relative to _"projectPath"_ | |
| `-o` | `--outputPath` | you can also specity the _"outputPath"_. This is where rooibosC will write the map file, and other files it needs which informs rooibos about your tests. It is relative to |
| `-v` | `--isRecordingCodeCoverage` | indicates that we want to generate coverage
| `-s` | `--sourceFilePattern` | array of globs, specifying which files to include/exclude in code coverage. Relative to projectPath. Required if `-v` is set. |

`-t` is the _"testPath"_ where your `.brs` test specs live

`-r` is the _"rootPath"_, i.e. the path to the root of your project. This is used to fix the `pkg:/locations` in rooibos's output.

`-o` is the _"outputPath"_. This is where rooibosC will write the map file which informs rooibos about your tests.
### Configuring Rooibos's runtime behaviour

### Configuring Rooibos
Rooibos's configuration is controlled via a json config file. The default location for this file is `pkg:/source/tests/rooibos/testconfig.json`.
See [Example app](../samples/example)
If the no testconfig is found a default one will be used.
Expand All @@ -140,6 +157,8 @@ An example config file looks like this:
}
```

_Deprecation warning: This behaviour is going to change - in future, these json settings will be merged with the preprocessor config._

## Creating test suites
<a name="organize-tests-by-suites-groups-and-cases"></a>

Expand Down Expand Up @@ -987,4 +1006,43 @@ end function

Rooibos is no longer backward compatible with the [legacy framework](https://github.com/rokudev/unit-testing-framework/), since version 2.0.0.

It is recommended that you upgrade your legacy tests to the new syntax for maximum flexibility and comfort.
It is recommended that you upgrade your legacy tests to the new syntax for maximum flexibility and comfort.

## Generate code coverage

Rooibos can measure and report the test coverage your unit tests are producing.

### Code coverage recording is desctructive!

Recording coverage means modifying your sources! you should only run the coverage on a project path pointing to a build folder _not_ your source.

These files should be cleaned and recopied _every time you run coverage_ or you will get compile errors/other undetermined behaviour.

### Recording coverage
To record coverage, set the `sourceFilePattern` to a glob matching (including and excluding) the files that should be included in your coverage report, and set the `isRecordingCodeCoverage` flag to true. An example, using a json config file is :

```
{
"projectPath": "build",
"sourceFilePattern": [
"**/*.brs",
"**/*.xml",
"!**/tests",
"!**/rLog",
"!**/rLogComponents",
"!**/rooibosDist.brs",
"!**/rooibosFunctionMap.brs",
"!**/TestsScene.brs",
"!**/ThreadUtils.brs"
],
"testsFilePattern": [
"**/tests/**/*.brs",
"!**/rooibosDist.brs",
"!**/rooibosFunctionMap.brs",
"!**/TestsScene.brs"
],
"isRecordingCodeCoverage": true
}```
This can be done, from the command line also, with the flags:
2 changes: 1 addition & 1 deletion docs/module-BaseTestSuite.html
Original file line number Diff line number Diff line change
Expand Up @@ -12420,7 +12420,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Apr 26 2019 22:57:27 GMT-0500 (-05) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat May 25 2019 22:57:12 GMT-0500 (-05) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-CommonUtils.html
Original file line number Diff line number Diff line change
Expand Up @@ -5062,7 +5062,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Apr 26 2019 22:57:27 GMT-0500 (-05) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat May 25 2019 22:57:12 GMT-0500 (-05) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-ItemGenerator.html
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Apr 26 2019 22:57:27 GMT-0500 (-05) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat May 25 2019 22:57:12 GMT-0500 (-05) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-TestRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ <h4 class="name" id="Run"><span class="type-signature"></span>Run<span class="si
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Apr 26 2019 22:57:27 GMT-0500 (-05) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat May 25 2019 22:57:12 GMT-0500 (-05) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-rooibosh.html
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ <h5>Parameters:</h5>
<br class="clear">

<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Fri Apr 26 2019 22:57:27 GMT-0500 (-05) using the Minami theme.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat May 25 2019 22:57:12 GMT-0500 (-05) using the Minami theme.
</footer>

<script>prettyPrint();</script>
Expand Down
31 changes: 31 additions & 0 deletions frameworkTests/source/tests/BasicTests.brs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,35 @@ end function

function BT_doSomethingInNodeScope(value)
m._isNodeScopeVarSet = value
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'@It tests aa's with a mock will not crash the box!
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'@Test
function BT_EqualsFixForStubbedAAs() as void
aa = {"test":"value"}
m.expectOnce(aa, "getStubbedObject", [aa])

aa.getStubbedObject(aa)
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'@It url in params
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'@Test simple
'@Params["http://101.rooibos.com"]
function BT_urlParams(url) as void
m.assertEqual(url, "http://101.rooibos.com")
end function

'@Test on objects
'@Params[{"url":"http://101.rooibos.com", "othervalue":2}]
'@Params[{url:"http://101.rooibos.com", "othervalue":2}]
'@Params[{url:"http://101.rooibos.com", othervalue:2}]
function BT_urlParams_objects(aa) as void
m.assertEqual(aa.url, "http://101.rooibos.com")
m.assertEqual(aa.othervalue, 2)
end function
Loading

0 comments on commit 8773221

Please sign in to comment.