diff options
Diffstat (limited to 'packages/integrations/deno/test/basics.test.ts')
-rw-r--r-- | packages/integrations/deno/test/basics.test.ts | 106 |
1 files changed, 25 insertions, 81 deletions
diff --git a/packages/integrations/deno/test/basics.test.ts b/packages/integrations/deno/test/basics.test.ts index 48a35d785..381343d06 100644 --- a/packages/integrations/deno/test/basics.test.ts +++ b/packages/integrations/deno/test/basics.test.ts @@ -1,10 +1,6 @@ -import { StartServerCallback, runBuildAndStartApp, defaultTestPermissions } from './helpers.ts'; import { DOMParser } from 'https://deno.land/x/deno_dom@v0.1.35-alpha/deno-dom-wasm.ts'; import { assert, assertEquals } from 'https://deno.land/std@0.158.0/testing/asserts.ts'; - -async function startApp(cb: StartServerCallback) { - await runBuildAndStartApp('./fixtures/basics/', cb); -} +import { runBuildAndStartApp, defaultTestPermissions } from './helpers.ts'; // this needs to be here and not in the specific test case, because // the variables are loaded in the global scope of the built server @@ -15,9 +11,13 @@ Deno.env.set('SOME_VARIABLE', varContent); Deno.test({ name: 'Basics', permissions: defaultTestPermissions, - async fn() { - await startApp(async (baseUrl: URL) => { - const resp = await fetch(baseUrl); + sanitizeResources: false, + sanitizeOps: false, + async fn(t) { + const app = await runBuildAndStartApp('./fixtures/basics/'); + + await t.step('Works', async () => { + const resp = await fetch(app.url); assertEquals(resp.status, 200); const html = await resp.text(); @@ -28,17 +28,9 @@ Deno.test({ assert(div, 'div exists'); }); - }, - sanitizeResources: false, - sanitizeOps: false, -}); -Deno.test({ - name: 'Custom 404', - permissions: defaultTestPermissions, - async fn() { - await startApp(async (baseUrl: URL) => { - const resp = await fetch(new URL('this-does-not-exist', baseUrl)); + await t.step('Custom 404', async () => { + const resp = await fetch(new URL('this-does-not-exist', app.url)); assertEquals(resp.status, 404); const html = await resp.text(); @@ -48,108 +40,60 @@ Deno.test({ const header = doc!.querySelector('#custom-404'); assert(header, 'displays custom 404'); }); - }, - sanitizeResources: false, - sanitizeOps: false, -}); -Deno.test({ - name: 'Loads style assets', - permissions: defaultTestPermissions, - async fn() { - await startApp(async (baseUrl: URL) => { - let resp = await fetch(baseUrl); + await t.step('Loads style assets', async () => { + let resp = await fetch(app.url); const html = await resp.text(); const doc = new DOMParser().parseFromString(html, `text/html`); const link = doc!.querySelector('link'); const href = link!.getAttribute('href'); - resp = await fetch(new URL(href!, baseUrl)); + resp = await fetch(new URL(href!, app.url)); assertEquals(resp.status, 200); const ct = resp.headers.get('content-type'); assertEquals(ct, 'text/css; charset=UTF-8'); await resp.body!.cancel(); }); - }, - sanitizeResources: false, - sanitizeOps: false, -}); -Deno.test({ - name: 'Correctly loads run-time env variables', - permissions: defaultTestPermissions, - async fn() { - await startApp(async (baseUrl: URL) => { - const resp = await fetch(baseUrl); + await t.step('Correctly loads run-time env variables', async () => { + const resp = await fetch(app.url); const html = await resp.text(); const doc = new DOMParser().parseFromString(html, `text/html`); const p = doc!.querySelector('p#env-value'); assertEquals(p!.innerText, varContent); }); - }, - sanitizeResources: false, - sanitizeOps: false, -}); -Deno.test({ - name: 'Works with Markdown', - permissions: defaultTestPermissions, - async fn() { - await startApp(async (baseUrl: URL) => { - const resp = await fetch(new URL('markdown', baseUrl)); + await t.step('Works with Markdown', async () => { + const resp = await fetch(new URL('markdown', app.url)); const html = await resp.text(); const doc = new DOMParser().parseFromString(html, `text/html`); const h1 = doc!.querySelector('h1'); assertEquals(h1!.innerText, 'Heading from Markdown'); }); - }, - sanitizeResources: false, - sanitizeOps: false, -}); -Deno.test({ - name: 'Works with MDX', - permissions: defaultTestPermissions, - async fn() { - await startApp(async (baseUrl: URL) => { - const resp = await fetch(new URL('mdx', baseUrl)); + await t.step('Works with MDX', async () => { + const resp = await fetch(new URL('mdx', app.url)); const html = await resp.text(); const doc = new DOMParser().parseFromString(html, `text/html`); const h1 = doc!.querySelector('h1'); assertEquals(h1!.innerText, 'Heading from MDX'); }); - }, - sanitizeResources: false, - sanitizeOps: false, -}); -Deno.test({ - name: 'Astro.cookies', - permissions: defaultTestPermissions, - async fn() { - await startApp(async (baseUrl: URL) => { - const url = new URL('/admin', baseUrl); + await t.step('Astro.cookies', async () => { + const url = new URL('/admin', app.url); const resp = await fetch(url, { redirect: 'manual' }); assertEquals(resp.status, 302); const headers = resp.headers; assertEquals(headers.get('set-cookie'), 'logged-in=false; Max-Age=77760000; Path=/'); }); - }, - sanitizeResources: false, - sanitizeOps: false, -}); -Deno.test({ - name: 'perendering', - permissions: defaultTestPermissions, - async fn() { - await startApp(async (baseUrl: URL) => { - const resp = await fetch(new URL('/prerender', baseUrl)); + await t.step('perendering', async () => { + const resp = await fetch(new URL('/prerender', app.url)); assertEquals(resp.status, 200); const html = await resp.text(); @@ -159,7 +103,7 @@ Deno.test({ const h1 = doc!.querySelector('h1'); assertEquals(h1!.innerText, 'test'); }); + + app.stop(); }, - sanitizeResources: false, - sanitizeOps: false, }); |