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

Run test suite in workerd #158

Closed
SokratisVidros opened this issue Nov 4, 2022 · 2 comments
Closed

Run test suite in workerd #158

SokratisVidros opened this issue Nov 4, 2022 · 2 comments

Comments

@SokratisVidros
Copy link

Hi there,

Is there a way to enable globalAsyncIO, globalTimers, and globalRandom for workerd in order to use the runtime for executing a tests suite that requires async IO, timers, and random generation outside handlers?

I can find the relevant options in the Miniflare API but I'd prefer to run the tests with workerd directly.

Thanks in advance.

@kentonv
Copy link
Member

kentonv commented Dec 7, 2022

No, there's no way to support I/O at the global scope. Instead, you will need to arrange for your test suite to be called from a fetch handler, or some other event handler.

Eventually I'd like for us to add some sort of build-in support for running tests. I'd imagine this would be accomplished through something like a "test handler" -- and event handler function which is only called for the purpose of running tests. This would be called with I/O fully enabled, etc.

But, disallowing I/O at the global scope is an important design decision for us, since it guarantees that the global scope is fully deterministic. I don't think we should make an exception for tests, because you probably want your tests to fail if you're doing something at the global scope which won't be allowed in production.

As a point of order, we like our issues to be restricted to specific actionable tasks, so I am going to close this. However, I think there's definitely an important discussion to be had about how to support unit tests in workerd. Please feel free to start a discussion under the discussion tab about this if you feel so inclined.

@kentonv kentonv closed this as completed Dec 7, 2022
@SokratisVidros
Copy link
Author

Thanks a lot, @kentonv. That makes perfect sense. I'd be more than happy to participate in the discussion about testing in workerd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants