-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix SW and Durable Object request URLs made over the service registry (…
…#1665) * Fix SW and Durable Object request URLs made over the service registry * Add service binding tests
- Loading branch information
1 parent
f650a0b
commit c40fca4
Showing
7 changed files
with
104 additions
and
21 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,5 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
fix: Fix SW and Durable Object request URLs made over the service registry |
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 |
---|---|---|
@@ -1,13 +1,26 @@ | ||
{ | ||
"name": "service-bindings-app", | ||
"version": "0.0.0", | ||
"private": true, | ||
"description": "A test for service bindings", | ||
"keywords": [], | ||
"license": "ISC", | ||
"author": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"dev": "npx concurrently 'wrangler dev a/index.ts --local' 'sleep 1 && wrangler dev b/index.ts --local'" | ||
"dev": "npx concurrently -s first -k \"wrangler dev a/index.ts --local --port 8300\" \"wrangler dev b/index.ts --local --port 8301\"", | ||
"test": "npx jest --forceExit", | ||
"test:ci": "npx jest --forceExit" | ||
}, | ||
"jest": { | ||
"restoreMocks": true, | ||
"testRegex": ".*.(test|spec)\\.[jt]sx?$", | ||
"testTimeout": 30000, | ||
"transform": { | ||
"^.+\\.c?(t|j)sx?$": [ | ||
"esbuild-jest", | ||
{ | ||
"sourcemap": true | ||
} | ||
] | ||
}, | ||
"transformIgnorePatterns": [ | ||
"node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream)" | ||
] | ||
} | ||
} |
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,62 @@ | ||
import { spawn } from "child_process"; | ||
import * as path from "path"; | ||
import { fetch } from "undici"; | ||
import type { ChildProcess } from "child_process"; | ||
import type { Response } from "undici"; | ||
|
||
const waitUntilReady = async (url: string): Promise<Response> => { | ||
let response: Response | undefined = undefined; | ||
|
||
while (response === undefined) { | ||
await new Promise((resolvePromise) => setTimeout(resolvePromise, 500)); | ||
|
||
try { | ||
response = await fetch(url); | ||
} catch {} | ||
} | ||
|
||
return response as Response; | ||
}; | ||
|
||
const isWindows = process.platform === "win32"; | ||
|
||
describe("Pages Functions", () => { | ||
let wranglerProcess: ChildProcess; | ||
|
||
beforeEach(() => { | ||
wranglerProcess = spawn("npm", ["run", "dev"], { | ||
shell: isWindows, | ||
cwd: path.resolve(__dirname, "../"), | ||
env: { BROWSER: "none", ...process.env }, | ||
}); | ||
wranglerProcess.stdout?.on("data", (chunk) => { | ||
console.log(chunk.toString()); | ||
}); | ||
wranglerProcess.stderr?.on("data", (chunk) => { | ||
console.log(chunk.toString()); | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
await new Promise((resolve, reject) => { | ||
wranglerProcess.once("exit", (code) => { | ||
if (!code) { | ||
resolve(code); | ||
} else { | ||
reject(code); | ||
} | ||
}); | ||
wranglerProcess.kill("SIGTERM"); | ||
}); | ||
}); | ||
|
||
it("connects up Durable Objects and keeps state across wrangler instances", async () => { | ||
const responseA = await waitUntilReady("http://localhost:8300/"); | ||
const textA = await responseA.text(); | ||
expect(textA).toEqual("hello world"); | ||
|
||
const responseB = await waitUntilReady("http://localhost:8301/"); | ||
const textB = (await responseB.text()) as { count: number; id: string }; | ||
expect(textB).toEqual("hello world"); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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