cloudflare / cloudflare/workerd
🐛 Bug Report — Runtime APIs: `export default`ed `test` handler not found if not last entry
- Dominant language
- C++
- Stars
- 8.7k
- Forks
- 739
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 174
Description
Hey! 👋 With the following `workerd` configuration...
```capnp
// config.capnp
using Workerd = import "/workerd/workerd.capnp";
const unitTests :Workerd.Config = (
services = [
( name = "test",
worker = (
modules = [
( name = "test.mjs", esModule = embed "test.mjs" )
],
bindings = [
( name = "SERVICE", service = "test" )
],
compatibilityDate = "2023-08-01",
)
),
],
);
```
```js
// test.mjs
export default {
async test(ctrl, env, ctx) {
const response = await env.SERVICE.fetch("http://placeholder/");
if (await response.text() !== "body") throw new Error("Aaah!");
},
async fetch(request, env, ctx) {
return new Response("body");
},
}
```
Running `workerd test config.capnp` results in...
```
workerd/server/server.c++:2972: error: No tests found!
Tests failed!
```
However, moving the `fetch` handler before `test` in the `export`ed object results in...
```
workerd/server/server.c++:2941: info: [ TEST ] test
workerd/server/server.c++:2949: info: [ PASS ] test
```
...as expected. Adding an arbitrary entry to the end of the object like `a: 1`, again results in `No tests found!`.
Contributor guide
Assessment
This issue has not been assessed yet.