astro/packages/integrations/netlify/test/edge-functions/edge-basic.test.ts
Bjorn Lu a79a37cad5
Support environment variables in Cloudflare and Netlify Edge functions (#5301)
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2022-11-08 21:54:49 +08:00

34 lines
940 B
TypeScript

// @ts-ignore
import { runBuild } from './test-utils.ts';
// @ts-ignore
import { assertEquals, assert, DOMParser } from './deps.ts';
// @ts-ignore
Deno.env.set('SECRET_STUFF', 'secret');
// @ts-ignore
Deno.test({
// TODO: debug why build cannot be found in "await import"
ignore: true,
name: 'Edge Basics',
skip: true,
async fn() {
let close = await runBuild('./fixtures/edge-basic/');
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();
assert(html, 'got some html');
const doc = new DOMParser().parseFromString(html, `text/html`)!;
const div = doc.querySelector('#react');
assert(div, 'div exists');
const envDiv = doc.querySelector('#env');
assertEquals(envDiv?.innerText, 'secret');
await close();
},
});