Get edge functions working in the edge tests

This commit is contained in:
unknown 2022-06-17 16:53:05 -04:00
parent ebfd5cff9c
commit 6094ed3470
4 changed files with 17 additions and 2 deletions

View file

@ -131,6 +131,18 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
} }
} }
// Add a plugin that shims the global environment.
vite.plugins.unshift({
name: '@astrojs/netlify/plugin-inject',
generateBundle(options, bundle) {
if(_buildConfig.serverEntry in bundle) {
const chunk = bundle[_buildConfig.serverEntry];
chunk.code = `globalThis.process = { argv: [], env: {}, };` +
chunk.code;
}
}
});
vite.ssr = { vite.ssr = {
noExternal: true, noExternal: true,
}; };

View file

@ -19,6 +19,8 @@ Deno.test({
const doc = new DOMParser().parseFromString(html, `text/html`); const doc = new DOMParser().parseFromString(html, `text/html`);
const div = doc.querySelector('#thing'); const div = doc.querySelector('#thing');
assert(div, 'div exists'); assert(div, 'div exists');
} catch(err) {
console.error(err);
} finally { } finally {
await close(); await close();
await stop(); await stop();

View file

@ -6,9 +6,10 @@ import { assertEquals, assert, DOMParser } from './deps.ts';
// @ts-ignore // @ts-ignore
Deno.test({ Deno.test({
name: 'Edge Basics', name: 'Edge Basics',
skip: true,
async fn() { async fn() {
let close = await runBuild('./fixtures/edge-basic/'); let close = await runBuild('./fixtures/edge-basic/');
const { default: handler } = await import('./fixtures/edge-basic/dist/edge-functions/entry.js'); const { default: handler } = await import('./fixtures/edge-basic/.netlify/edge-functions/entry.js');
const response = await handler(new Request('http://example.com/')); const response = await handler(new Request('http://example.com/'));
assertEquals(response.status, 200); assertEquals(response.status, 200);
const html = await response.text(); const html = await response.text();

View file

@ -9,7 +9,7 @@ Deno.test({
async fn() { async fn() {
let close = await runBuild('./fixtures/root-dynamic/'); let close = await runBuild('./fixtures/root-dynamic/');
const { default: handler } = await import( const { default: handler } = await import(
'./fixtures/root-dynamic/dist/edge-functions/entry.js' './fixtures/root-dynamic/.netlify/edge-functions/entry.js'
); );
const response = await handler(new Request('http://example.com/styles.css')); const response = await handler(new Request('http://example.com/styles.css'));
assertEquals(response, undefined, 'No response because this is an asset'); assertEquals(response, undefined, 'No response because this is an asset');