Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Miniflare 3] Return copy of entry URL from Miniflare#ready #671

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/miniflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,8 @@ export class Miniflare {
// called by `#init()`, and `#initPromise` doesn't resolve until `#init()`
// returns.
assert(this.#runtimeEntryURL !== undefined);
return this.#runtimeEntryURL;
// Return a copy so external mutations don't propagate to `#runtimeEntryURL`
return new URL(this.#runtimeEntryURL.toString());
}
get ready(): Promise<URL> {
return this.#waitForReady();
Expand Down
15 changes: 15 additions & 0 deletions packages/miniflare/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ test("Miniflare: validates options", async (t) => {
);
});

test("Miniflare: ready returns copy of entry URL", async (t) => {
const mf = new Miniflare({
port: 0,
modules: true,
script: "",
});
t.teardown(() => mf.dispose());

const url1 = await mf.ready;
url1.protocol = "ws:";
const url2 = await mf.ready;
t.not(url1, url2);
t.is(url2.protocol, "http:");
});

test("Miniflare: keeps port between updates", async (t) => {
const opts: MiniflareOptions = {
port: 0,
Expand Down