Don’t use Buffer.byteLength() as Deno can’t use it (#4324)
* Don’t use Buffer.byteLength() as Deno can’t use it * Add changeset * Add tests for Markdown & MDX with Deno Co-authored-by: Matthew Phillips <matthew@skypack.dev>
This commit is contained in:
parent
166b3b8a54
commit
45fdbc4650
8 changed files with 53 additions and 3 deletions
5
.changeset/green-schools-pump.md
Normal file
5
.changeset/green-schools-pump.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Use TextEncoder instead of Buffer.byteLength() for Deno compatibility
|
|
@ -49,10 +49,11 @@ export async function renderPage(
|
|||
}
|
||||
html += rest;
|
||||
}
|
||||
return new Response(html, {
|
||||
const bytes = encoder.encode(html);
|
||||
return new Response(bytes, {
|
||||
headers: new Headers([
|
||||
['Content-Type', 'text/html; charset=utf-8'],
|
||||
['Content-Length', Buffer.byteLength(html, 'utf-8').toString()],
|
||||
['Content-Length', bytes.byteLength.toString()],
|
||||
]),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -59,3 +59,31 @@ Deno.test({
|
|||
});
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: 'Works with Markdown',
|
||||
async fn() {
|
||||
await startApp(async () => {
|
||||
const resp = await fetch('http://127.0.0.1:8085/markdown');
|
||||
const html = await resp.text();
|
||||
|
||||
const doc = new DOMParser().parseFromString(html, `text/html`);
|
||||
const h1 = doc.querySelector('h1');
|
||||
assertEquals(h1.innerText, 'Heading from Markdown');
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: 'Works with MDX',
|
||||
async fn() {
|
||||
await startApp(async () => {
|
||||
const resp = await fetch('http://127.0.0.1:8085/mdx');
|
||||
const html = await resp.text();
|
||||
|
||||
const doc = new DOMParser().parseFromString(html, `text/html`);
|
||||
const h1 = doc.querySelector('h1');
|
||||
assertEquals(h1.innerText, 'Heading from MDX');
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { defineConfig } from 'astro/config';
|
||||
import deno from '@astrojs/deno';
|
||||
import react from '@astrojs/react';
|
||||
import mdx from '@astrojs/mdx';
|
||||
|
||||
export default defineConfig({
|
||||
adapter: deno(),
|
||||
integrations: [react()],
|
||||
integrations: [react(), mdx()],
|
||||
output: 'server',
|
||||
})
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"astro": "workspace:*",
|
||||
"@astrojs/deno": "workspace:*",
|
||||
"@astrojs/react": "workspace:*",
|
||||
"@astrojs/mdx": "workspace:*",
|
||||
"react": "^18.1.0",
|
||||
"react-dom": "^18.1.0"
|
||||
}
|
||||
|
|
6
packages/integrations/deno/test/fixtures/basics/src/pages/markdown.md
vendored
Normal file
6
packages/integrations/deno/test/fixtures/basics/src/pages/markdown.md
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
title: Title
|
||||
description: Description
|
||||
---
|
||||
|
||||
# Heading from Markdown
|
6
packages/integrations/deno/test/fixtures/basics/src/pages/mdx.mdx
vendored
Normal file
6
packages/integrations/deno/test/fixtures/basics/src/pages/mdx.mdx
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
title: Title
|
||||
description: Description
|
||||
---
|
||||
|
||||
# Heading from MDX
|
|
@ -2146,12 +2146,14 @@ importers:
|
|||
packages/integrations/deno/test/fixtures/basics:
|
||||
specifiers:
|
||||
'@astrojs/deno': workspace:*
|
||||
'@astrojs/mdx': workspace:*
|
||||
'@astrojs/react': workspace:*
|
||||
astro: workspace:*
|
||||
react: ^18.1.0
|
||||
react-dom: ^18.1.0
|
||||
dependencies:
|
||||
'@astrojs/deno': link:../../..
|
||||
'@astrojs/mdx': link:../../../../mdx
|
||||
'@astrojs/react': link:../../../../react
|
||||
astro: link:../../../../../astro
|
||||
react: 18.2.0
|
||||
|
|
Loading…
Reference in a new issue