Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 4f7bc5b

Browse files
committed
Run worker for module exports if queue consumer specified
Previously, queue consumers would never be triggered when running using the Miniflare test environments. This change ensures the worker script is executed, adding the `queue` event listener if present.
1 parent 1a2cc36 commit 4f7bc5b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/queues/src/plugin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ export class QueuesPlugin
122122
binding.queueName
123123
);
124124
}
125-
return { bindings };
125+
126+
const requiresModuleExports =
127+
this.queueConsumers !== undefined && this.queueConsumers.length > 0;
128+
return { bindings, requiresModuleExports };
126129
}
127130
}

packages/queues/test/plugin.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,18 @@ test("QueuesPlugin: setup: includes queues in bindings", async (t) => {
146146
t.true(result.bindings?.QUEUE1 instanceof WorkerQueue);
147147
t.true(result.bindings?.QUEUE2 instanceof WorkerQueue);
148148
});
149+
150+
test("QueuesPlugin: setup: requires module exports if consuming", async (t) => {
151+
const queueBroker = new QueueBroker();
152+
const pluginCtx: PluginContext = { ...ctx, queueBroker };
153+
let plugin = new QueuesPlugin(pluginCtx, {
154+
queueBindings: [{ name: "QUEUE", queueName: "queue" }],
155+
});
156+
let result = await plugin.setup(factory);
157+
t.false(result.requiresModuleExports);
158+
plugin = new QueuesPlugin(pluginCtx, {
159+
queueConsumers: ["queue"],
160+
});
161+
result = await plugin.setup(factory);
162+
t.true(result.requiresModuleExports);
163+
});

0 commit comments

Comments
 (0)