-
Notifications
You must be signed in to change notification settings - Fork 29
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
Feature/runtime global function mocking #250
Conversation
There was a problem hiding this 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.
…ed with async tests
if (testSuite.isNodeTest) { | ||
this.session.createNodeFile(event.program, testSuite); | ||
} |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
@georgejecook Added some comments in in some places I thought you might have questions. This is ready for final review. |
5d6bbca
into
rokucommunity:feature/runtime-global-function-mocking
Adds a new way to mock global functions via a
m.stubCall()
api.Examples mocking two global functions: