vitest-plugin: waitOnExecutionContext() doesn't wait for imported waitUntil
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
- #16720 di @owreed — chiusa senza merge
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, node.js, typescript
Direzione di ricerca
Start with src/index.js and src/index.test.js in the reproduction, then read patchAndRunWithHandlerContext in dist/worker/lib/cloudflare/test-internal.mjs and the implementation of registerHandlerAndGlobalWaitUntil. Trace how imported waitUntil is connected to the current handler context, then run the reproduction with npm install && npx vitest run. Done means waitOnExecutionContext(ctx) waits for the imported waitUntil promise and the test observes log as ["done"].
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What versions & operating system are you using?
@cloudflare/vitest-plugin 1.5.1, vitest 5.0.5, wrangler 4.157.0, Node 26.13.0, macOS (arm64).
Please provide a link to a minimal reproduction
Inline below: five files, npm install && npx vitest run.
Describe the Bug
Since August 2025, waitUntil can be imported from cloudflare:workers, so code deep in an app can use it without being handed ctx. In tests, waitOnExecutionContext(ctx) waits only for promises passed to ctx.waitUntil. Work passed to the imported waitUntil is never awaited, so a test can't check its effect, a rejection doesn't fail the test, and late work spills into the next test.
The plugin tracks ctx.waitUntil on contexts from createExecutionContext() and on handler contexts it patches (patchAndRunWithHandlerContext in dist/worker/lib/cloudflare/test-internal.mjs). The imported function calls the native IoContext::current().addWaitUntil(), which the plugin never sees.
Expected: waitOnExecutionContext(ctx) also waits for work passed to the imported waitUntil while handling that request, the way registerHandlerAndGlobalWaitUntil already routes the plugin's own patched setTimeout promises to the current handler context.
src/index.js:
import { waitUntil } from "cloudflare:workers";
export const log = [];
export default {
async fetch() {
waitUntil(
new Promise((resolve) => setTimeout(resolve, 100)).then(() => {
log.push("done");
}),
);
return new Response("ok");
},
};
src/index.test.js:
import { createExecutionContext, env, waitOnExecutionContext } from "cloudflare:test";
import { expect, it } from "vitest";
import worker, { log } from "./index.js";
it("waits for work passed to the imported waitUntil", async () => {
const ctx = createExecutionContext();
await worker.fetch(new Request("https://example.com"), env, ctx);
await waitOnExecutionContext(ctx);
expect(log).toEqual(["done"]);
});
vitest.config.js:
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineConfig } from "vitest/config";
export default defineConfig({
plugins: [cloudflareTest({ wrangler: { configPath: "./wrangler.jsonc" } })],
});
wrangler.jsonc:
{
"name": "wait-until-repro",
"main": "src/index.js",
"compatibility_date": "2026-11-01"
}
package.json:
{
"name": "wait-until-repro",
"private": true,
"type": "module",
"devDependencies": {
"@cloudflare/vitest-plugin": "1.5.1",
"vitest": "5.0.5",
"wrangler": "4.157.0"
}
}
The test fails with log still []. Changing the worker to async fetch(request, env, ctx) and ctx.waitUntil(...) makes it pass.
Please provide any relevant error logs
AssertionError: expected [] to deeply equal [ 'done' ]
- Expected
+ Received
- [
- "done",
- ]
+ []
❯ src/index.test.js:13:15
- Lingua principale
- TypeScript
- Stelle
- 4.7k
- Fork
- 1.7k
- Merge medio
- 1g 22h
- PR unite (30g)
- 282
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di cloudflare/workers-sdk
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
cloudflare/workers-sdk#17215 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
cloudflare/workers-sdk#17189 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
cloudflare/workers-sdk#17187 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
cloudflare/workers-sdk#17175 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
cloudflare/workers-sdk#17174 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di cloudflare/workers-sdk
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
earendil-works/pi#12615 ·
I maintainer di solito rispondono entro 1 giorno
-
My Caps shows "Shared" on private Caps that were never sharedForse già presa @AksharP5 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
CapSoftware/Cap#4569 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
OHDSI/Data2Evidence#3749 ·
I maintainer di solito rispondono entro 4 giorni
-
PWA: Unique Page TitlesAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Flagsmith/flagsmith-nodejs-client#332 ·
I maintainer di solito rispondono entro 2 giorni