From 81947ecbd69ff8fd6175f84eb67baac000b4b9c3 Mon Sep 17 00:00:00 2001 From: Vasyl Martynych Date: Tue, 13 Apr 2021 23:06:00 +0300 Subject: [PATCH 1/6] add testData to _brs_ --- src/extensions/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/extensions/index.ts b/src/extensions/index.ts index 97367b9a9..b5735c5b6 100644 --- a/src/extensions/index.ts +++ b/src/extensions/index.ts @@ -26,6 +26,7 @@ export const _brs_ = new RoAssociativeArray([ { name: new BrsString("runInScope"), value: RunInScope }, { name: new BrsString("process"), value: Process }, { name: new BrsString("global"), value: mGlobal }, + { name: new BrsString("testData"), value: new RoAssociativeArray([]) }, { name: new BrsString("triggerKeyEvent"), value: triggerKeyEvent }, { name: new BrsString("getStackTrace"), value: GetStackTrace }, ]); From 1fe05140470f2ce0421c25fc9cf9c1edfc0a335b Mon Sep 17 00:00:00 2001 From: Vasyl Martynych Date: Wed, 14 Apr 2021 01:10:24 +0300 Subject: [PATCH 2/6] export method to clean testData on _brs_ --- src/extensions/index.ts | 4 ++++ src/index.ts | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/extensions/index.ts b/src/extensions/index.ts index b5735c5b6..9885327b1 100644 --- a/src/extensions/index.ts +++ b/src/extensions/index.ts @@ -30,3 +30,7 @@ export const _brs_ = new RoAssociativeArray([ { name: new BrsString("triggerKeyEvent"), value: triggerKeyEvent }, { name: new BrsString("getStackTrace"), value: GetStackTrace }, ]); + +export function _resetTestData() { + _brs_.set(new BrsString("testData"), new RoAssociativeArray([])); +} diff --git a/src/index.ts b/src/index.ts index 8836b1627..980d63a47 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,6 +16,7 @@ import { } from "./componentprocessor"; import { Parser } from "./parser"; import { Interpreter, ExecutionOptions, defaultExecutionOptions } from "./interpreter"; +import { _resetTestData } from "./extensions"; import * as BrsError from "./Error"; import * as LexerParser from "./LexerParser"; import { CoverageCollector } from "./coverage"; @@ -326,3 +327,8 @@ function run( return; } } + +/** resets _brs_.testData values to `{}` */ +export function resetTestData() { + _resetTestData(); +} From 386e1052e08852688ca796dad376f242a6b9dfe5 Mon Sep 17 00:00:00 2001 From: Vasyl Martynych Date: Wed, 14 Apr 2021 22:24:54 +0300 Subject: [PATCH 3/6] resolve PR comments(remove useless function wrap) --- src/extensions/index.ts | 3 ++- src/index.ts | 7 +------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/extensions/index.ts b/src/extensions/index.ts index 9885327b1..14b5c9da0 100644 --- a/src/extensions/index.ts +++ b/src/extensions/index.ts @@ -31,6 +31,7 @@ export const _brs_ = new RoAssociativeArray([ { name: new BrsString("getStackTrace"), value: GetStackTrace }, ]); -export function _resetTestData() { +/** resets _brs_.testData values to `{}` in brightscript representation */ +export function resetTestData() { _brs_.set(new BrsString("testData"), new RoAssociativeArray([])); } diff --git a/src/index.ts b/src/index.ts index 980d63a47..fe18cefff 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,7 @@ import { } from "./componentprocessor"; import { Parser } from "./parser"; import { Interpreter, ExecutionOptions, defaultExecutionOptions } from "./interpreter"; -import { _resetTestData } from "./extensions"; +export { resetTestData } from "./extensions"; import * as BrsError from "./Error"; import * as LexerParser from "./LexerParser"; import { CoverageCollector } from "./coverage"; @@ -327,8 +327,3 @@ function run( return; } } - -/** resets _brs_.testData values to `{}` */ -export function resetTestData() { - _resetTestData(); -} From 0f269ca32db94fb1011f5614d478cb406b21de44 Mon Sep 17 00:00:00 2001 From: Vasyl Martynych Date: Mon, 19 Apr 2021 14:00:32 +0300 Subject: [PATCH 4/6] add UT for testData --- test/extensions/testData.test.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/extensions/testData.test.js diff --git a/test/extensions/testData.test.js b/test/extensions/testData.test.js new file mode 100644 index 000000000..a391a3dea --- /dev/null +++ b/test/extensions/testData.test.js @@ -0,0 +1,29 @@ +const brs = require("brs"); +const { BrsString, BrsInvalid, ValueKind } = brs.types; +const { Interpreter } = require("../../lib/interpreter"); +const { identifier } = require("../parser/ParserTests"); + +describe("_brs_.testData", () => { + it("check testData object", () => { + let _brs_ = new Interpreter().environment.get(identifier("_brs_")); + let testData = _brs_.get(new BrsString("testData")); + + expect(testData.kind).toBe(ValueKind.Object); + expect(testData.componentName).toBe("roAssociativeArray"); + expect(testData.elements.size).toBe(0); + testData.set(new BrsString("foo"), BrsInvalid.Instance); + expect(testData.elements.size).toBe(1); + + testData = new Interpreter().environment + .get(identifier("_brs_")) + .get(new BrsString("testData")); + expect(testData.elements.size).toBe(1); + + brs.resetTestData(); // will clear testData for next new Interpreter instances + + testData = new Interpreter().environment + .get(identifier("_brs_")) + .get(new BrsString("testData")); + expect(testData.elements.size).toBe(0); + }); +}); From 1b1dbb1f6b01c6cdece5fcff3e7e9df64fbcaf68 Mon Sep 17 00:00:00 2001 From: Vasyl Martynych Date: Wed, 21 Apr 2021 17:20:47 +0300 Subject: [PATCH 5/6] add autocleaning testData between running test files --- src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index fe18cefff..1b25baf05 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,7 @@ import { } from "./componentprocessor"; import { Parser } from "./parser"; import { Interpreter, ExecutionOptions, defaultExecutionOptions } from "./interpreter"; -export { resetTestData } from "./extensions"; +import { resetTestData } from "./extensions"; import * as BrsError from "./Error"; import * as LexerParser from "./LexerParser"; import { CoverageCollector } from "./coverage"; @@ -231,6 +231,7 @@ export async function createExecuteWithScope( interpreter.errors = []; return (filenames: string[], args: BrsTypes.BrsType[]) => { + resetTestData(); let ast = lexParseSync(filenames, interpreter.options); let execErrors: BrsError.BrsError[] = []; let returnValue = interpreter.inSubEnv((subInterpreter) => { From 496265f2bf80989f9b09cadeffdd9d9ccdf54026 Mon Sep 17 00:00:00 2001 From: Vasyl Martynych Date: Wed, 21 Apr 2021 17:55:48 +0300 Subject: [PATCH 6/6] fix testData UT --- test/extensions/testData.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/extensions/testData.test.js b/test/extensions/testData.test.js index a391a3dea..97289d6e0 100644 --- a/test/extensions/testData.test.js +++ b/test/extensions/testData.test.js @@ -2,6 +2,7 @@ const brs = require("brs"); const { BrsString, BrsInvalid, ValueKind } = brs.types; const { Interpreter } = require("../../lib/interpreter"); const { identifier } = require("../parser/ParserTests"); +const { resetTestData } = require("../../lib/extensions"); describe("_brs_.testData", () => { it("check testData object", () => { @@ -19,7 +20,7 @@ describe("_brs_.testData", () => { .get(new BrsString("testData")); expect(testData.elements.size).toBe(1); - brs.resetTestData(); // will clear testData for next new Interpreter instances + resetTestData(); // will clear testData for next new Interpreter instances testData = new Interpreter().environment .get(identifier("_brs_"))