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

Feature/runtime global function mocking #250

Conversation

chrisdp
Copy link
Collaborator

@chrisdp chrisdp commented Jan 11, 2024

Adds a new way to mock global functions via a m.stubCall() api.

Examples mocking two global functions:
image

Copy link
Collaborator

@georgejecook georgejecook left a comment

Choose a reason for hiding this comment

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

as we discussed; we should add this to the standard mockCall behavior so that
mockCall(pointerToFunction, returnResultGeneratorFunction) where returnResultGeneratorFunction is either a function, or a pointer to a function, would automatically trigger this behavior.

I am happy to add that; but I want to see a unit test with generated output for your files first, so that I can quickly check I'm doing the same thing.

If you get a test added (see my other tests like plugin.spec.ts `it('correctly transpiles global function calls'), with the functionality you already have here, I can then put it where I believe it better fits, and you can take a look at it.

bsc-plugin/src/lib/rooibos/MockUtil.ts Outdated Show resolved Hide resolved
framework/src/source/BaseTestSuite.bs Outdated Show resolved Hide resolved
@chrisdp chrisdp marked this pull request as ready for review January 18, 2024 19:37
Comment on lines -162 to -163
if (testSuite.isNodeTest) {
this.session.createNodeFile(event.program, testSuite);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Was moved to be done earlier in the process due to an order of ops issue

body.split('end function')[0]
);

let [, result] = /instance.[\w_]+\s?\= function\(\)\s?([\S\s]*|.*)(?=^\s*end function\s+instance\.)/img.exec(contents);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated so that it work with anon funcs in the test function body.


if (!noEarlyExit) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed some undefined ast being injected resulting in this annotation causing down stream crashes at transpile. Required to be able to run the test app on device,

@@ -58,6 +46,9 @@ export class RooibosSession {
console.log('Efficient global stubbing is enabled');
this.namespaceLookup = this.getNamespaces(program);
for (let testSuite of this.sessionInfo.testSuitesToRun) {
if (testSuite.isNodeTest) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need to add the component file to the program before we start looking for stub and expect calls to be modified now that we use the file scopes to reliably know if a global is in scope for this suite.

@@ -267,7 +267,7 @@ namespace rooibos
if m.catchCrashes and not test.noCatch and not m.noCatch
try
test.run()
if m.isAutoAssertingMocks = true
if m.isAutoAssertingMocks = true and not test.isAsync
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

With the current set up mocks and stubs will be cleaned the moment after calling the async test. Meaning this are nearly guaranteed to run into errors or failures if the async test is relying on them. For not I opted to disable the auto mock logic here and plan to make some updates/fixes to async tests overall. Like running this after the async test has finished or failed.

@chrisdp chrisdp added the enhancement New feature or request label Jan 20, 2024
@chrisdp
Copy link
Collaborator Author

chrisdp commented Jan 20, 2024

@georgejecook Added some comments in in some places I thought you might have questions. This is ready for final review.

@chrisdp chrisdp changed the base branch from master to feature/runtime-global-function-mocking January 22, 2024 16:47
@chrisdp chrisdp merged commit 5d6bbca into rokucommunity:feature/runtime-global-function-mocking Jan 22, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants