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
@@ -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,
20 changes: 20 additions & 0 deletions docs/api/reference/test-utilities.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion src/runner/JestRunner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Config } from "@jest/types";
import { ExecuteWithScope, types as BrsTypes } from "brs";
import { resetTestData, ExecuteWithScope, types as BrsTypes } from "brs";
import { JestReporter } from "../reporter/JestReporter";
import { TestRunner } from "./TestRunner";

@@ -33,6 +33,7 @@ export class JestRunner extends TestRunner {
testFiles.forEach((filename, index) => {
this.reporter.onFileStart(filename);
try {
resetTestData();
lkipke marked this conversation as resolved.
Show resolved Hide resolved
execute([filename], [executeArgs]);
} catch (reason) {
this.reporter.onFileExecError(filename, index, reason);
3 changes: 2 additions & 1 deletion src/runner/TestRunner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from "path";
import { types as BrsTypes, ExecuteWithScope } from "brs";
import { resetTestData, types as BrsTypes, ExecuteWithScope } from "brs";
import { formatInterpreterError } from "../util";

export class TestRunner {
@@ -41,6 +41,7 @@ export class TestRunner {
// Set the index so that our TAP reporting is correct.
executeArgs.elements.set("index", new BrsTypes.Int32(index));
try {
resetTestData();
execute([filename], [executeArgs]);
} catch (e) {
console.error(