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

feat(extensions): Add _brs_.testData associative array #646

Merged
merged 6 commits into from
Apr 30, 2021

Conversation

Vasya-M
Copy link
Contributor

@Vasya-M Vasya-M commented Apr 13, 2021

fix for issue #623
added testData to _brs_ object
exported new method resetTestData for cleaning testData before runing test suites(test files)
linked roca PR: hulu/roca#88

@Vasya-M Vasya-M changed the title Add testData to _brs_ Issue #623 Add testData to _brs_ Apr 14, 2021
@lkipke lkipke added documentation Affects how this project is documented; includes clarifications, corrections, and additions enhancement Any addition to this project's existing capabilities labels Apr 14, 2021
Copy link
Collaborator

@lkipke lkipke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just a couple of small nits 😄

src/index.ts Outdated Show resolved Hide resolved
src/extensions/index.ts Outdated Show resolved Hide resolved
@lkipke lkipke self-requested a review April 14, 2021 23:14
Copy link
Collaborator

@lkipke lkipke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me! Can we also add a test case for this?

Copy link
Collaborator

@alimnios72 alimnios72 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to test case but changes look good

Copy link
Owner

@sjbarag sjbarag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this, @Vasya-M! It looks like _brs_ persists across Interpreter instances, which may be the motivation behind exposing resetTestData() outside of this module. I'm curious if we could ensure each Interpreter instance gets its own copy of _brs_ and solve this problem without having to export a new function that consumers might forget to call!

.get(new BrsString("testData"));
expect(testData.elements.size).toBe(1);

brs.resetTestData(); // will clear testData for next new Interpreter instances
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the _brs_.testData to persist across interpreter instances? IIRC there's only one created as part of roca anyway. We'll still want this type of behavior, but perhaps simpler solution would be for each Interpreter instance to get its own copy of the _brs_ extensions 🤔

src/index.ts Outdated
@@ -16,6 +16,7 @@ import {
} from "./componentprocessor";
import { Parser } from "./parser";
import { Interpreter, ExecutionOptions, defaultExecutionOptions } from "./interpreter";
export { resetTestData } from "./extensions";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this needs to be exposed from the root of the module. If it does need to be exposed, I'd like for us to find (or add) a new property to put it on instead of it being a sibling of brs.lexer, brs.parser, brs.types, etc. Those are all very low-level concepts, and resetTestData doesn't match those 😃

@lkipke lkipke requested a review from sjbarag April 23, 2021 17:02
@@ -230,6 +231,7 @@ export async function createExecuteWithScope(
interpreter.errors = [];

return (filenames: string[], args: BrsTypes.BrsType[]) => {
resetTestData();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this solution better than exporting it!

Copy link
Owner

@sjbarag sjbarag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

@sjbarag sjbarag changed the title Issue #623 Add testData to _brs_ feat(extensions): Add _brs_.testData associative array Apr 30, 2021
@sjbarag sjbarag merged commit 3afccef into sjbarag:main Apr 30, 2021
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Affects how this project is documented; includes clarifications, corrections, and additions enhancement Any addition to this project's existing capabilities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants