test: add test case for root folder with space

This commit is contained in:
lutaok 2023-10-05 22:22:51 +02:00
parent 110d0306b0
commit a763b0387e
5 changed files with 74 additions and 0 deletions

View file

@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';
import markdoc from '@astrojs/markdoc';
// https://astro.build/config
export default defineConfig({
integrations: [markdoc()],
});

View file

@ -0,0 +1,9 @@
{
"name": "@test/markdoc-render-with-space",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/markdoc": "workspace:*",
"astro": "workspace:*"
}
}

View file

@ -0,0 +1,7 @@
---
title: Simple post with root folder containing a space
---
## Simple post with root folder containing a space
This is a simple Markdoc post with root folder containing a space.

View file

@ -0,0 +1,19 @@
---
import { getEntryBySlug } from "astro:content";
const post = await getEntryBySlug('blog', 'simple');
const { Content } = await post.render();
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Content</title>
</head>
<body>
<Content />
</body>
</html>

View file

@ -57,6 +57,18 @@ describe('Markdoc - render', () => {
await server.stop();
});
it('renders content - with root folder containing space', async () => {
const fixture = await getFixture('render with-space');
const server = await fixture.startDevServer();
const res = await fixture.fetch('/');
const html = await res.text();
renderWithRootFolderContainingSpace(html);
await server.stop();
});
});
describe('build', () => {
@ -95,6 +107,15 @@ describe('Markdoc - render', () => {
renderNullChecks(html);
});
it('renders content - with root folder containing space', async () => {
const fixture = await getFixture('render with-space');
await fixture.build();
const html = await fixture.readFile('/index.html');
renderWithRootFolderContainingSpace(html);
});
});
});
@ -148,3 +169,14 @@ function renderSimpleChecks(html) {
const p = document.querySelector('p');
expect(p.textContent).to.equal('This is a simple Markdoc post.');
}
/** @param {string} html */
function renderWithRootFolderContainingSpace(html) {
const { document } = parseHTML(html);
const h2 = document.querySelector('h2');
expect(h2.textContent).to.equal('Simple post with root folder containing a space');
const p = document.querySelector('p');
expect(p.textContent).to.equal(
'This is a simple Markdoc post with root folder containing a space.'
);
}