sveltejs / sveltejs/kit

`Could not get the request store` During Server Test

Open
#14,249 8 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

Previously, the sequence() generated handle could be called from a test to simulate request handling. When upgrading to the latest SvelteKit version, this now raises an error: Could not get the request store. This is an internal error. It appears this is due to missing state expected by the new OpenTelemetry Tracing feature.

I am not aware of any other way of directly testing server hooks then by invoking them directly in a test. The only work around I found is by mocking the sequence helper in the test fixture.

Reproduction

This reproduction demonstrates the error:
sveltekit-issue-get-request-store

The repository also includes a working test, using SveltKit v2.21.2.

Logs
FAIL   server  src/hooks.server.test.ts > can call handler
Error: Could not get the request store. This is an internal error.
 ❯ get_request_store node_modules/@sveltejs/kit/src/exports/internal/event.js:48:9
 ❯ node_modules/@sveltejs/kit/src/exports/hooks/sequence.js:85:21
 ❯ src/hooks.server.test.ts:12:26
     10|   } as RequestEvent
     11|   const resolve = vi.fn().mockResolvedValue(new Response('OK'));
     12|   const response = await handle({ event : event, resolve : resolve });
       |                          ^
     13|   expect(response).toBeDefined();
     14| });

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯


 Test Files  1 failed (1)
      Tests  1 failed (1)
   Start at  11:37:10
   Duration  488ms (transform 53ms, setup 0ms, collect 67ms, tests 8ms, environment 0ms, prepare 127ms)
System Info
System:
    OS: Windows 11 10.0.26100
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 1.67 GB / 11.70 GB
  Binaries:
    Node: 22.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 4.9.2 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (138.0.3351.77)
    Internet Explorer: 11.0.26100.1882
  npmPackages:
    @sveltejs/adapter-auto: ^6.0.0 => 6.0.1
    @sveltejs/kit: ^2.31.1 => 2.21.2
    @sveltejs/vite-plugin-svelte: ^5.0.0 => 5.1.0
    svelte: ^5.0.0 => 5.33.18
    vite: ^6.2.6 => 6.3.5
Severity

annoyance

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the failing src/hooks.server.test.ts reproduction and compare the working SvelteKit v2.21.2 version. Trace the generated handler through node_modules/@sveltejs/kit/src/exports/hooks/sequence.js and get_request_store in src/exports/internal/event.js. Done means direct server-hook testing no longer raises the request-store error, with regression coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
backend, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.