File
Blob: src/workerd/api/tests/ctx-props-test.wd-test
| 1 | using Workerd = import "/workerd/workerd.capnp"; |
| 2 | |
| 3 | const unitTests :Workerd.Config = ( |
| 4 | services = [ |
| 5 | ( name = "ctx-props-test-disabled", |
| 6 | worker = ( |
| 7 | modules = [ |
| 8 | (name = "worker-props-disabled", esModule = |
| 9 | `import assert from 'node:assert'; |
| 10 | `export default { |
| 11 | ` async fetch(request, env, ctx) { |
| 12 | ` return new Response(JSON.stringify(ctx.props)); |
| 13 | ` }, |
| 14 | ` async test(request, env, ctx) { |
| 15 | ` const resp = await env.SERVICE.fetch(new Request("https://placeholder/hello")); |
| 16 | ` const body = await resp.json(); |
| 17 | ` assert.strictEqual(JSON.stringify(body), '{}'); |
| 18 | ` }, |
| 19 | `}; |
| 20 | ) |
| 21 | ], |
| 22 | bindings = [ |
| 23 | ( name = "SERVICE", service = (name = "ctx-props-test-disabled", props = (json = "false"))), |
| 24 | ], |
| 25 | compatibilityFlags = ["nodejs_compat", "nonclass_entrypoint_reuses_ctx_across_invocations"], |
| 26 | ) |
| 27 | ), |
| 28 | ( name = "ctx-props-test-enabled", |
| 29 | worker = ( |
| 30 | modules = [ |
| 31 | (name = "worker-props-enabled", esModule = |
| 32 | `import assert from 'node:assert'; |
| 33 | `export default { |
| 34 | ` async fetch(request, env, ctx) { |
| 35 | ` return new Response(JSON.stringify(ctx.props)); |
| 36 | ` }, |
| 37 | ` async test(request, env, ctx) { |
| 38 | ` const resp = await env.SERVICE.fetch(new Request("https://placeholder/hello")); |
| 39 | ` const body = await resp.json(); |
| 40 | ` assert.deepStrictEqual(body, {foo: 123}); |
| 41 | ` }, |
| 42 | `}; |
| 43 | ) |
| 44 | ], |
| 45 | bindings = [ |
| 46 | ( name = "SERVICE", service = (name = "ctx-props-test-enabled", props = (json = "{\"foo\" : 123}"))), |
| 47 | ], |
| 48 | compatibilityFlags = ["nodejs_compat", "unique_ctx_per_invocation"], |
| 49 | )) |
| 50 | ], |
| 51 | ); |