Get edge functions working in the edge tests
This commit is contained in:
parent
ebfd5cff9c
commit
6094ed3470
4 changed files with 17 additions and 2 deletions
|
@ -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 = {
|
||||
noExternal: true,
|
||||
};
|
||||
|
|
|
@ -19,6 +19,8 @@ Deno.test({
|
|||
const doc = new DOMParser().parseFromString(html, `text/html`);
|
||||
const div = doc.querySelector('#thing');
|
||||
assert(div, 'div exists');
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
await close();
|
||||
await stop();
|
||||
|
|
|
@ -6,9 +6,10 @@ import { assertEquals, assert, DOMParser } from './deps.ts';
|
|||
// @ts-ignore
|
||||
Deno.test({
|
||||
name: 'Edge Basics',
|
||||
skip: true,
|
||||
async fn() {
|
||||
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/'));
|
||||
assertEquals(response.status, 200);
|
||||
const html = await response.text();
|
||||
|
|
|
@ -9,7 +9,7 @@ Deno.test({
|
|||
async fn() {
|
||||
let close = await runBuild('./fixtures/root-dynamic/');
|
||||
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'));
|
||||
assertEquals(response, undefined, 'No response because this is an asset');
|
||||
|
|
Loading…
Reference in a new issue