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

fix: prevent vitest from hanging #12830

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/six-goats-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-cloudflare': patch
---

fix: prevent vitest from hanging
42 changes: 23 additions & 19 deletions packages/adapter-cloudflare-workers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,33 @@ export default function ({ config = 'wrangler.toml', platformProxy = {} } = {})
builder.writePrerendered(bucket_dir);
},

async emulate() {
const proxy = await getPlatformProxy(platformProxy);
const platform = /** @type {App.Platform} */ ({
env: proxy.env,
context: proxy.ctx,
caches: proxy.caches,
cf: proxy.cf
});
emulate() {
const getting_platform = (async () => {
const proxy = await getPlatformProxy(platformProxy);
const platform = /** @type {App.Platform} */ ({
env: proxy.env,
context: proxy.ctx,
caches: proxy.caches,
cf: proxy.cf
});

/** @type {Record<string, any>} */
const env = {};
const prerender_platform = /** @type {App.Platform} */ (/** @type {unknown} */ ({ env }));
/** @type {Record<string, any>} */
const env = {};
const prerender_platform = /** @type {App.Platform} */ (/** @type {unknown} */ ({ env }));

for (const key in proxy.env) {
Object.defineProperty(env, key, {
get: () => {
throw new Error(`Cannot access platform.env.${key} in a prerenderable route`);
}
});
}
for (const key in proxy.env) {
Object.defineProperty(env, key, {
get: () => {
throw new Error(`Cannot access platform.env.${key} in a prerenderable route`);
}
});
}
return { platform, prerender_platform };
})();

return {
platform: ({ prerender }) => {
platform: async ({ prerender }) => {
const { platform, prerender_platform } = await getting_platform;
return prerender ? prerender_platform : platform;
}
};
Expand Down
42 changes: 23 additions & 19 deletions packages/adapter-cloudflare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,29 +144,33 @@ export default function (options = {}) {
);
}
},
async emulate() {
const proxy = await getPlatformProxy(options.platformProxy);
const platform = /** @type {App.Platform} */ ({
env: proxy.env,
context: proxy.ctx,
caches: proxy.caches,
cf: proxy.cf
});
emulate() {
const getting_platform = (async () => {
const proxy = await getPlatformProxy(options.platformProxy);
const platform = /** @type {App.Platform} */ ({
env: proxy.env,
context: proxy.ctx,
caches: proxy.caches,
cf: proxy.cf
});

/** @type {Record<string, any>} */
const env = {};
const prerender_platform = /** @type {App.Platform} */ (/** @type {unknown} */ ({ env }));
/** @type {Record<string, any>} */
const env = {};
const prerender_platform = /** @type {App.Platform} */ (/** @type {unknown} */ ({ env }));

for (const key in proxy.env) {
Object.defineProperty(env, key, {
get: () => {
throw new Error(`Cannot access platform.env.${key} in a prerenderable route`);
}
});
}
for (const key in proxy.env) {
Object.defineProperty(env, key, {
get: () => {
throw new Error(`Cannot access platform.env.${key} in a prerenderable route`);
}
});
}
return { platform, prerender_platform };
})();

return {
platform: ({ prerender }) => {
platform: async ({ prerender }) => {
const { platform, prerender_platform } = await getting_platform;
return prerender ? prerender_platform : platform;
}
};
Expand Down
Loading