Skip to content
File

Blob: src/workerd/api/tests/js-rpc-flag.js

javascript33 lines
1// Copyright (c) 2023 Cloudflare, Inc.
2// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3// https://opensource.org/licenses/Apache-2.0
4 
5import assert from 'node:assert';
6 
7// This class does not extend `DurableObject`, but because we have the `js_rpc` compat flag on,
8// it'll still accept RPC.
9export class DurableObjectExample {
10 // eslint-disable-next-line @typescript-eslint/no-useless-constructor
11 constructor() {}
12 
13 foo() {
14 return 123;
15 }
16 
17 fetch(req) {
18 return new Response(req.method + ' ' + req.url);
19 }
20}
21 
22export default {
23 async test(ctrl, env, ctx) {
24 let id = env.ns.idFromName('foo');
25 let obj = env.ns.get(id);
26 assert.strictEqual(await obj.foo(), 123);
27 
28 // Test that the object has the old helper get() method that wraps fetch(). This is deprecated,
29 // but enabled because this test's compat date is before the date when these went away.
30 assert.strictEqual(await obj.get('http://foo'), 'GET http://foo');
31 },
32};