I have a Cloudflare Pages project with functions which used KV. I wish to test my functions with KV values that are seeded before the function is called. How do I do this?
Asked
Active
Viewed 180 times
1 Answers
0
The solution: On the root directory of your project … i.e. where the functions directory is, create a file in a directory:
.wrangler/state/kv/<bind-name>/<key>
<bind-name> is your KV namespace.
<key> is a file with the name of your key.
for me bind-name is TEST, key is BUG_TEST. So my file is:
.wrangler/state/kv/TEST/BUG_TEST
Inside the file place the value for the key.
Then when you start your wrangler use --persist. For me, using pages, the command is:
npx wrangler pages dev --kv=TEST --persist -- npm start
Also, if you are using git don’t forget to add .wrangler to .gitignore

Safa Alai
- 1,223
- 1
- 15
- 27
-
1Thanks for sharing, this works for v2. Have you got this working for wrangler/miniflare v3? – connorads Jul 24 '23 at 15:04
-
I did not get this working for v3 and abandoned the method. – Safa Alai Aug 22 '23 at 00:58