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

Issue #76 add cleaning testData before running each test file. #88

Merged
merged 8 commits into from
May 18, 2021
1 change: 1 addition & 0 deletions docs/api/reference/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ These extensions are all available on a global associative array called `_brs_`:
{
getStackTrace: function,
global: associative array,
testData: associative array,
mockComponent: function,
mockComponentPartial: function,
mockFunction: function,
Expand Down
20 changes: 20 additions & 0 deletions docs/api/reference/test-utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ print _brs_.global

------------

## \_brs_.testData

A reference to the temporary associative array, so that you can access it from everywhere inside your brs code. Mostly used for saving/accessing some test-specific data. Clears before running each test file.

### Usage
```brightscript
_brs_.testData._isFooAvailable = false
_brs_.mockFunction("isFooAvailable", sub()
return _brs_.testData._isFooAvailable
end sub)

isFooAvailable() ' => false

_brs_.testData._isFooAvailable = true ' something happened and now it is available
isFooAvailable() ' => true
```
<br/>

------------

# \_brs_.process

Allows you to access the command line arguments and locale.
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/before-after/before-after.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ describe("before-after", () => {

expect(results.stats).toMatchObject({
suites: 4,
tests: 12,
passes: 9,
tests: 14,
passes: 11,
pending: 3,
failures: 0,
});
Expand All @@ -85,9 +85,11 @@ describe("before-after", () => {
{ fullTitle: "nested root case 1" },
{ fullTitle: "nested root case 2" },
{ fullTitle: "nested root case 3" },
{ fullTitle: "nested root check _brs_.testData" },
{ fullTitle: "single-level root case 1" },
{ fullTitle: "single-level root case 2" },
{ fullTitle: "single-level root case 3" },
{ fullTitle: "single-level root check _brs_.testData" },
]);
});
});
10 changes: 10 additions & 0 deletions test/e2e/before-after/mixed/tests/01-nested.test.brs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ function main(args as object) as object
m.assert.equal(m.counterB, 11, "counterB must be incremented for each test case")
end sub)

m.it("check _brs_.testData", sub()
lkipke marked this conversation as resolved.
Show resolved Hide resolved
m.assert.isTrue(_brs_.testData <> invalid, "_brs_.testData should be presented")
m.assert.isTrue(_brs_.testData.count() = 0, "by default _brs_.testData should be equal to {}")

' change value to check whether it clears between different test files
_brs_.testData = {
ctx: "file 1"
}
end sub)

m.describe("suite 1", sub()
m.addContext({
counterC: 0
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/before-after/mixed/tests/02-single-level.test.brs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,15 @@ function main(args as object) as object
m.assert.isInvalid(m.counterB, "afterEach state must not spread to sibling suites")
m.assert.equal(m.counterA, 5, "counterA must be incremented for each test case")
end sub)

m.it("check _brs_.testData", sub()
m.assert.isTrue(_brs_.testData <> invalid, "_brs_.testData should be presented")
m.assert.isTrue(_brs_.testData.count() = 0, "by default _brs_.testData should be equal to {}")

' change value to check whether it clears between different test files
_brs_.testData = {
ctx: "file 1"
}
end sub)
end sub)
end function