inngest-js icon indicating copy to clipboard operation
inngest-js copied to clipboard

Improve testing experience

Open MonsterDeveloper opened this issue 1 year ago • 4 comments

Is your feature request related to a problem? Please describe. Setting up unit tests for Inngest functions is currently challenging due to a lack of guidelines in the official documentation. Exporting from inngest.createFunction requires exporting both the function itself and the function passed to it for testing.

Describe the solution you'd like Enable the manual execution of declared functions. For example:

export const myFunction = inngest.createFunction(...)

myFunction.run()

Additionally, include testing guidelines in the docs with practical examples.

Describe alternatives you've considered Exporting the handler callbacks passed into inngest.createFunction and testing them using mock objects.

MonsterDeveloper avatar Jan 17 '24 13:01 MonsterDeveloper

Would it be possible to expose the test helpers?

brijmcq avatar Jun 07 '24 08:06 brijmcq

It's a mentioned issue, but commenting to highlight it.

@MonsterDeveloper just exposed InngestFunction#createExecution() over at #618, released in 3.19.16.

Note that it's an internal method that can still change at any time; we'll add first-party testing tooling at a later date, but for now createExecution() is indeed what we use for a lot of our internal unit tests.

cc @brijmcq

jpwilliams avatar Jun 18 '24 19:06 jpwilliams

Yep, now it's possible to test functions as follows. But beware that it's unstable and is subject to change without notice.

CleanShot 2024-06-18 at 21 33 42@2x

MonsterDeveloper avatar Jun 18 '24 19:06 MonsterDeveloper

Please see inngest/inngest#1680 for further conversation and progress on this. 🙂

  • inngest/inngest#1680

jpwilliams avatar Sep 02 '24 12:09 jpwilliams