aboutsummaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/test
diff options
context:
space:
mode:
authorGravatar Ben Holmes <hey@bholmes.dev> 2023-05-19 14:12:45 -0400
committerGravatar GitHub <noreply@github.com> 2023-05-19 14:12:45 -0400
commita9e1cd7e58794fe220539c2ed935c9eb96bab55a (patch)
tree07c298f7a21d61726f515dcae762fd0cbe277540 /packages/integrations/markdoc/test
parent147373722b37126af949bb054a1cdfb0aed6c2ff (diff)
downloadastro-a9e1cd7e58794fe220539c2ed935c9eb96bab55a.tar.gz
astro-a9e1cd7e58794fe220539c2ed935c9eb96bab55a.tar.zst
astro-a9e1cd7e58794fe220539c2ed935c9eb96bab55a.zip
Fix: Heading ID CI flakiness (#7141)
* feat: use `ctx` object instead of leaky global * test: heading IDs stale caches * chore: changeset
Diffstat (limited to 'packages/integrations/markdoc/test')
-rw-r--r--packages/integrations/markdoc/test/fixtures/headings-custom/src/content/docs/headings-stale-cache-check.mdoc13
-rw-r--r--packages/integrations/markdoc/test/fixtures/headings-custom/src/pages/[slug].astro (renamed from packages/integrations/markdoc/test/fixtures/headings-custom/src/pages/index.astro)12
-rw-r--r--packages/integrations/markdoc/test/fixtures/headings/src/content/docs/headings-stale-cache-check.mdoc13
-rw-r--r--packages/integrations/markdoc/test/fixtures/headings/src/pages/[slug].astro (renamed from packages/integrations/markdoc/test/fixtures/headings/src/pages/index.astro)12
-rw-r--r--packages/integrations/markdoc/test/headings.test.js50
5 files changed, 84 insertions, 16 deletions
diff --git a/packages/integrations/markdoc/test/fixtures/headings-custom/src/content/docs/headings-stale-cache-check.mdoc b/packages/integrations/markdoc/test/fixtures/headings-custom/src/content/docs/headings-stale-cache-check.mdoc
new file mode 100644
index 000000000..75cd52884
--- /dev/null
+++ b/packages/integrations/markdoc/test/fixtures/headings-custom/src/content/docs/headings-stale-cache-check.mdoc
@@ -0,0 +1,13 @@
+Our heading ID generator can have a stale cache for duplicates. Let's check for those!
+
+# Level 1 heading
+
+## Level **2 heading**
+
+### Level _3 heading_
+
+#### Level [4 heading](/with-a-link)
+
+##### Level 5 heading with override {% #id-override %}
+
+###### Level 6 heading
diff --git a/packages/integrations/markdoc/test/fixtures/headings-custom/src/pages/index.astro b/packages/integrations/markdoc/test/fixtures/headings-custom/src/pages/[slug].astro
index 5880be0e3..2baef9d69 100644
--- a/packages/integrations/markdoc/test/fixtures/headings-custom/src/pages/index.astro
+++ b/packages/integrations/markdoc/test/fixtures/headings-custom/src/pages/[slug].astro
@@ -1,8 +1,14 @@
---
-import { getEntryBySlug } from "astro:content";
+import { getCollection, CollectionEntry } from "astro:content";
-const post = await getEntryBySlug('docs', 'headings');
-const { Content, headings } = await post.render();
+export async function getStaticPaths() {
+ const docs = await getCollection('docs');
+ return docs.map(doc => ({ params: { slug: doc.slug }, props: doc }));
+}
+
+type Props = CollectionEntry<'docs'>;
+
+const { Content, headings } = await Astro.props.render();
---
<!DOCTYPE html>
diff --git a/packages/integrations/markdoc/test/fixtures/headings/src/content/docs/headings-stale-cache-check.mdoc b/packages/integrations/markdoc/test/fixtures/headings/src/content/docs/headings-stale-cache-check.mdoc
new file mode 100644
index 000000000..75cd52884
--- /dev/null
+++ b/packages/integrations/markdoc/test/fixtures/headings/src/content/docs/headings-stale-cache-check.mdoc
@@ -0,0 +1,13 @@
+Our heading ID generator can have a stale cache for duplicates. Let's check for those!
+
+# Level 1 heading
+
+## Level **2 heading**
+
+### Level _3 heading_
+
+#### Level [4 heading](/with-a-link)
+
+##### Level 5 heading with override {% #id-override %}
+
+###### Level 6 heading
diff --git a/packages/integrations/markdoc/test/fixtures/headings/src/pages/index.astro b/packages/integrations/markdoc/test/fixtures/headings/src/pages/[slug].astro
index 5880be0e3..2baef9d69 100644
--- a/packages/integrations/markdoc/test/fixtures/headings/src/pages/index.astro
+++ b/packages/integrations/markdoc/test/fixtures/headings/src/pages/[slug].astro
@@ -1,8 +1,14 @@
---
-import { getEntryBySlug } from "astro:content";
+import { getCollection, CollectionEntry } from "astro:content";
-const post = await getEntryBySlug('docs', 'headings');
-const { Content, headings } = await post.render();
+export async function getStaticPaths() {
+ const docs = await getCollection('docs');
+ return docs.map(doc => ({ params: { slug: doc.slug }, props: doc }));
+}
+
+type Props = CollectionEntry<'docs'>;
+
+const { Content, headings } = await Astro.props.render();
---
<!DOCTYPE html>
diff --git a/packages/integrations/markdoc/test/headings.test.js b/packages/integrations/markdoc/test/headings.test.js
index 5db50065c..5468e8c6b 100644
--- a/packages/integrations/markdoc/test/headings.test.js
+++ b/packages/integrations/markdoc/test/headings.test.js
@@ -27,7 +27,15 @@ describe('Markdoc - Headings', () => {
});
it('applies IDs to headings', async () => {
- const res = await fixture.fetch('/');
+ const res = await fixture.fetch('/headings');
+ const html = await res.text();
+ const { document } = parseHTML(html);
+
+ idTest(document);
+ });
+
+ it('generates the same IDs for other documents with the same headings', async () => {
+ const res = await fixture.fetch('/headings-stale-cache-check');
const html = await res.text();
const { document } = parseHTML(html);
@@ -35,7 +43,7 @@ describe('Markdoc - Headings', () => {
});
it('generates a TOC with correct info', async () => {
- const res = await fixture.fetch('/');
+ const res = await fixture.fetch('/headings');
const html = await res.text();
const { document } = parseHTML(html);
@@ -49,14 +57,21 @@ describe('Markdoc - Headings', () => {
});
it('applies IDs to headings', async () => {
- const html = await fixture.readFile('/index.html');
+ const html = await fixture.readFile('/headings/index.html');
+ const { document } = parseHTML(html);
+
+ idTest(document);
+ });
+
+ it('generates the same IDs for other documents with the same headings', async () => {
+ const html = await fixture.readFile('/headings-stale-cache-check/index.html');
const { document } = parseHTML(html);
idTest(document);
});
it('generates a TOC with correct info', async () => {
- const html = await fixture.readFile('/index.html');
+ const html = await fixture.readFile('/headings/index.html');
const { document } = parseHTML(html);
tocTest(document);
@@ -83,7 +98,15 @@ describe('Markdoc - Headings with custom Astro renderer', () => {
});
it('applies IDs to headings', async () => {
- const res = await fixture.fetch('/');
+ const res = await fixture.fetch('/headings');
+ const html = await res.text();
+ const { document } = parseHTML(html);
+
+ idTest(document);
+ });
+
+ it('generates the same IDs for other documents with the same headings', async () => {
+ const res = await fixture.fetch('/headings-stale-cache-check');
const html = await res.text();
const { document } = parseHTML(html);
@@ -91,7 +114,7 @@ describe('Markdoc - Headings with custom Astro renderer', () => {
});
it('generates a TOC with correct info', async () => {
- const res = await fixture.fetch('/');
+ const res = await fixture.fetch('/headings');
const html = await res.text();
const { document } = parseHTML(html);
@@ -99,7 +122,7 @@ describe('Markdoc - Headings with custom Astro renderer', () => {
});
it('renders Astro component for each heading', async () => {
- const res = await fixture.fetch('/');
+ const res = await fixture.fetch('/headings');
const html = await res.text();
const { document } = parseHTML(html);
@@ -113,21 +136,28 @@ describe('Markdoc - Headings with custom Astro renderer', () => {
});
it('applies IDs to headings', async () => {
- const html = await fixture.readFile('/index.html');
+ const html = await fixture.readFile('/headings/index.html');
+ const { document } = parseHTML(html);
+
+ idTest(document);
+ });
+
+ it('generates the same IDs for other documents with the same headings', async () => {
+ const html = await fixture.readFile('/headings-stale-cache-check/index.html');
const { document } = parseHTML(html);
idTest(document);
});
it('generates a TOC with correct info', async () => {
- const html = await fixture.readFile('/index.html');
+ const html = await fixture.readFile('/headings/index.html');
const { document } = parseHTML(html);
tocTest(document);
});
it('renders Astro component for each heading', async () => {
- const html = await fixture.readFile('/index.html');
+ const html = await fixture.readFile('/headings/index.html');
const { document } = parseHTML(html);
astroComponentTest(document);