-
Notifications
You must be signed in to change notification settings - Fork 702
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a
cf
field to the getBindingsProxy
result
- Loading branch information
1 parent
5ef5606
commit 431af33
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
"wrangler": minor | ||
--- | ||
|
||
feature: add a `cf` field to the `getBindingsProxy` result | ||
|
||
Add a new `cf` filed to the `getBindingsProxy` result that people can use to mock the production | ||
`cf` (`IncomingRequestCfProperties`) object. | ||
|
||
Example: | ||
|
||
```ts | ||
const { cf } = await getBindingsProxy(); | ||
|
||
console.log(`country = ${cf.country} ; colo = ${cf.colo}`); // logs 'country = GB ; colo = LHR' | ||
``` |
38 changes: 38 additions & 0 deletions
38
fixtures/get-bindings-proxy/tests/get-bindings-proxy.cf.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { getBindingsProxy } from "./shared"; | ||
|
||
describe("getBindingsProxy - cf", () => { | ||
it("should provide mock data", async () => { | ||
const { cf, dispose } = await getBindingsProxy(); | ||
try { | ||
expect(cf).toMatchObject({ | ||
colo: "DFW", | ||
city: "Austin", | ||
regionCode: "TX", | ||
}); | ||
} finally { | ||
await dispose(); | ||
} | ||
}); | ||
|
||
it("should match the production runtime cf object", async () => { | ||
const { cf, dispose } = await getBindingsProxy(); | ||
try { | ||
expect(cf.constructor.name).toBe("Object"); | ||
|
||
expect(() => { | ||
cf.city = "test city"; | ||
}).toThrowError( | ||
"Cannot assign to read only property 'city' of object '#<Object>'" | ||
); | ||
expect(cf.city).not.toBe("test city"); | ||
|
||
expect(() => { | ||
cf.newField = "test new field"; | ||
}).toThrowError("Cannot add property newField, object is not extensible"); | ||
expect("newField" in cf).toBe(false); | ||
} finally { | ||
await dispose(); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters