Skip to content

How to test async code?Β #424

@tmillr

Description

@tmillr

...for example, testing that an autocmd triggered as expected?

Or, testing that a timer fires sometime in the future as expected?

and how to keep the plenary test harness from returning/exiting while inside a test fn that I need to wait for a timer result in?

Or as another example, let's say that I have to test a function which creates/loads some ui (e.g. creates a new internal/nvim window) and I need to wait until the next turn of the event loop until the window has completely finished being created and displayed, without the test function (i.e. the fn passed to it()) returning in the meantime?

It's not clear how to do these kinds of tests from the docs/README alone, so help or guidance on this would be immensely appreciated as well as would potentially help any others who are similarly stuck on this. Thanks!

P.S. I think it's kinda unfortunate that lua doesn't already come with an easy-to-use async framework built-in, unlike say, javascript, which has had easy-to-use promises and foolproof async functionality built into the language for some time now. I kinda wish Neovim had just went with js and embedded v8 instead of using Lua lol. I feel like alot more people already know how to use js and it has alot more really great features (e.g. Promises/async, TypeScript and a plethora of tools and packages, highly optimized/advanced engines) compared to Lua. Anyway sorry for the rant lol.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions