Skip to content

Commit a5bfd5b

Browse files
Use non-global MessageChannel in worker_threads test
This actually now fails because the MessageChannel in the `node:worker_threads` module is pulled from the `global.MessageChannel` and that is only available if `expose_global_message_channel` compat flag is on...
1 parent b615e33 commit a5bfd5b

File tree

1 file changed

+7
-11
lines changed
  • packages/wrangler/e2e/unenv-preset/worker

1 file changed

+7
-11
lines changed

packages/wrangler/e2e/unenv-preset/worker/index.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,6 @@ export const WorkerdTests: Record<string, () => void> = {
904904
async testWorkerThreads() {
905905
const workerThreads = await import("node:worker_threads");
906906

907-
// Check if native workerd implementation is enabled via the compatibility flag
908-
const isNative =
909-
getRuntimeFlagValue("enable_nodejs_worker_threads_module") === true;
910-
911907
// Common exports available in both unenv stub and native workerd
912908
for (const target of [workerThreads, workerThreads.default]) {
913909
assertTypeOfProperties(target, {
@@ -923,6 +919,7 @@ export const WorkerdTests: Record<string, () => void> = {
923919
postMessageToThread: "function",
924920
isInternalThread: "boolean",
925921
BroadcastChannel: "function",
922+
MessageChannel: "function",
926923
Worker: "function",
927924
});
928925

@@ -962,15 +959,14 @@ export const WorkerdTests: Record<string, () => void> = {
962959
"getEnvironmentData should return the set value"
963960
);
964961

965-
// Test MessageChannel creates ports using native Web API
966-
// (MessageChannel is a native Web API available in workerd with recent compatibility dates)
967-
if (typeof MessageChannel !== "undefined") {
968-
const channel = new MessageChannel();
969-
assert.ok(channel.port1, "MessageChannel should have port1");
970-
assert.ok(channel.port2, "MessageChannel should have port2");
971-
}
962+
// Test MessageChannel creates ports
963+
const channel = new workerThreads.MessageChannel();
964+
assert.ok(channel.port1, "MessageChannel should have port1");
965+
assert.ok(channel.port2, "MessageChannel should have port2");
972966

973967
// Test behavioral differences between native workerd and unenv stub
968+
const isNative =
969+
getRuntimeFlagValue("enable_nodejs_worker_threads_module") === true;
974970
if (isNative) {
975971
// Native workerd: Worker and BroadcastChannel constructors throw
976972
assert.throws(

0 commit comments

Comments
 (0)