Skip to content

Commit

Permalink
🧪 Heading export test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
fwkoch committed Jan 17, 2025
1 parent f36b65b commit 8ef3478
Show file tree
Hide file tree
Showing 68 changed files with 1,394 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/mystmd/tests/endToEnd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ function resolve(relative: string) {
return path.resolve(__dirname, relative);
}

function cleanHashes(text: string) {
return text
.replace(/-[a-f0-9]{32}\./g, '.')
.replace(/"key":\s*"[a-zA-Z0-9]{10}"/g, '"key": "keyABC0123"');
}

const only = '';

describe.concurrent('End-to-end cli export tests', { timeout: 15000 }, () => {
Expand All @@ -48,13 +54,13 @@ describe.concurrent('End-to-end cli export tests', { timeout: 15000 }, () => {
expect(fs.existsSync(resolve(output.path))).toBeTruthy();
if (path.extname(output.content) === '.json') {
expect(
JSON.parse(fs.readFileSync(resolve(output.path), { encoding: 'utf-8' })),
JSON.parse(cleanHashes(fs.readFileSync(resolve(output.path), { encoding: 'utf-8' }))),
).toMatchObject(
JSON.parse(fs.readFileSync(resolve(output.content), { encoding: 'utf-8' })),
JSON.parse(cleanHashes(fs.readFileSync(resolve(output.content), { encoding: 'utf-8' }))),
);
} else {
expect(fs.readFileSync(resolve(output.path), { encoding: 'utf-8' })).toEqual(
fs.readFileSync(resolve(output.content), { encoding: 'utf-8' }),
expect(cleanHashes(fs.readFileSync(resolve(output.path), { encoding: 'utf-8' }))).toEqual(
cleanHashes(fs.readFileSync(resolve(output.content), { encoding: 'utf-8' })),
);
}
});
Expand Down
98 changes: 98 additions & 0 deletions packages/mystmd/tests/exports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,101 @@ cases:
content: url-folders/outputs/myst.xref.json
- path: url-folders/_build/site/content/my-proj/readme.json
content: url-folders/outputs/readme.json
- title: Multi page project with no numbering specified
cwd: multi-page-typ-site
command: myst build --all
outputs:
- path: multi-page-typ-site/_build/site/config.json
content: multi-page-typ-site/outputs/config.json
- path: multi-page-typ-site/_build/site/content/index.json
content: multi-page-typ-site/outputs/index.json
- path: multi-page-typ-site/_build/site/content/a.json
content: multi-page-typ-site/outputs/a.json
- path: multi-page-typ-site/_build/site/content/b.json
content: multi-page-typ-site/outputs/b.json
- path: multi-page-typ-site/_build/site/content/c.json
content: multi-page-typ-site/outputs/c.json
- path: multi-page-typ-site/_build/site/content/d.json
content: multi-page-typ-site/outputs/d.json
- path: multi-page-typ-site/_build/out.typ
content: multi-page-typ-site/outputs/out.typ
- path: multi-page-typ-site/_build/out-a.typ
content: multi-page-typ-site/outputs/out-a.typ
- path: multi-page-typ-site/_build/out-b.typ
content: multi-page-typ-site/outputs/out-b.typ
- path: multi-page-typ-site/_build/out-c.typ
content: multi-page-typ-site/outputs/out-c.typ
- path: multi-page-typ-site/_build/out-d.typ
content: multi-page-typ-site/outputs/out-d.typ
- title: Multi page project with default heading numbering
cwd: multi-page-headings-typ-site
command: myst build --all
outputs:
- path: multi-page-headings-typ-site/_build/site/config.json
content: multi-page-headings-typ-site/outputs/config.json
- path: multi-page-headings-typ-site/_build/site/content/index.json
content: multi-page-headings-typ-site/outputs/index.json
- path: multi-page-headings-typ-site/_build/site/content/a.json
content: multi-page-headings-typ-site/outputs/a.json
- path: multi-page-headings-typ-site/_build/site/content/b.json
content: multi-page-headings-typ-site/outputs/b.json
- path: multi-page-headings-typ-site/_build/site/content/c.json
content: multi-page-headings-typ-site/outputs/c.json
- path: multi-page-headings-typ-site/_build/site/content/d.json
content: multi-page-headings-typ-site/outputs/d.json
- path: multi-page-headings-typ-site/_build/out.typ
content: multi-page-headings-typ-site/outputs/out.typ
- path: multi-page-headings-typ-site/_build/out-a.typ
content: multi-page-headings-typ-site/outputs/out-a.typ
- path: multi-page-headings-typ-site/_build/out-b.typ
content: multi-page-headings-typ-site/outputs/out-b.typ
- path: multi-page-headings-typ-site/_build/out-c.typ
content: multi-page-headings-typ-site/outputs/out-c.typ
- path: multi-page-headings-typ-site/_build/out-d.typ
content: multi-page-headings-typ-site/outputs/out-d.typ
- title: Multi page project with headings numbered except 2
cwd: multi-page-heading-2-false-typ-site
command: myst build --all
outputs:
- path: multi-page-heading-2-false-typ-site/_build/site/config.json
content: multi-page-heading-2-false-typ-site/outputs/config.json
- path: multi-page-heading-2-false-typ-site/_build/site/content/index.json
content: multi-page-heading-2-false-typ-site/outputs/index.json
- path: multi-page-heading-2-false-typ-site/_build/site/content/a.json
content: multi-page-heading-2-false-typ-site/outputs/a.json
- path: multi-page-heading-2-false-typ-site/_build/site/content/b.json
content: multi-page-heading-2-false-typ-site/outputs/b.json
- path: multi-page-heading-2-false-typ-site/_build/site/content/c.json
content: multi-page-heading-2-false-typ-site/outputs/c.json
- path: multi-page-heading-2-false-typ-site/_build/site/content/d.json
content: multi-page-heading-2-false-typ-site/outputs/d.json
- path: multi-page-heading-2-false-typ-site/_build/out.typ
content: multi-page-heading-2-false-typ-site/outputs/out.typ
- path: multi-page-heading-2-false-typ-site/_build/out-a.typ
content: multi-page-heading-2-false-typ-site/outputs/out-a.typ
- path: multi-page-heading-2-false-typ-site/_build/out-b.typ
content: multi-page-heading-2-false-typ-site/outputs/out-b.typ
- path: multi-page-heading-2-false-typ-site/_build/out-c.typ
content: multi-page-heading-2-false-typ-site/outputs/out-c.typ
- path: multi-page-heading-2-false-typ-site/_build/out-d.typ
content: multi-page-heading-2-false-typ-site/outputs/out-d.typ
- title: Single page project with no numbering specified
cwd: single-page-typ-site
command: myst build --all
outputs:
- path: single-page-typ-site/_build/site/config.json
content: single-page-typ-site/outputs/config.json
- path: single-page-typ-site/_build/site/content/index.json
content: single-page-typ-site/outputs/index.json
- path: single-page-typ-site/_build/out.typ
content: single-page-typ-site/outputs/out.typ
- title: Single page project with default heading numbering
cwd: single-page-headings-typ-site
command: myst build --all
outputs:
- path: single-page-headings-typ-site/_build/site/config.json
content: single-page-headings-typ-site/outputs/config.json
- path: single-page-headings-typ-site/_build/site/content/index.json
content: single-page-headings-typ-site/outputs/index.json
- path: single-page-headings-typ-site/_build/out.typ
content: single-page-headings-typ-site/outputs/out.typ
17 changes: 17 additions & 0 deletions packages/mystmd/tests/multi-page-heading-2-false-typ-site/a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: This is page A
---

# Heading one on page A

Some text

## Heading two on page A

More text

```{figure} image.png
:label: fig-a
I would like this to be figure 1
```
15 changes: 15 additions & 0 deletions packages/mystmd/tests/multi-page-heading-2-false-typ-site/b.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This is page B - title in markdown

## Heading one on page B

Some text

### Heading two on page B

More text

```{figure} image.png
:label: fig-b
I would like this to be figure 1
```
17 changes: 17 additions & 0 deletions packages/mystmd/tests/multi-page-heading-2-false-typ-site/c.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: This is page C
---

# Heading one on page C

Some text

## Heading two on page C

More text

```{figure} image.png
:label: fig-c
I would like this to be figure 1
```
17 changes: 17 additions & 0 deletions packages/mystmd/tests/multi-page-heading-2-false-typ-site/d.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: This is page D
---

# Heading one on page D

Some text

## Heading two on page D

More text

```{figure} image.png
:label: fig-d
I would like this to be figure 1
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
24 changes: 24 additions & 0 deletions packages/mystmd/tests/multi-page-heading-2-false-typ-site/myst.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See docs at: https://mystmd.org/guide/frontmatter
version: 1
project:
id: 3a045569-08b0-4ce0-a917-4c18b22a45f3
author: Franklin Koch
date: 9 Jan 2025
title: My ABC Project
abstract: My ABC project is used for testing title and continuous enumeration.
toc:
- file: index.md
- file: a.md
children:
- file: b.md
- file: c.md
- file: d.md
exports:
- format: typst
output: _build/out.typ
template: null
numbering:
headings: true
heading_2: false
site:
template: ../templates/site/myst/book-theme
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"kind":"Article","sha256":"a34c854e58ff3e7820339b87014bc5c96cda37aed1da875a110248e615bdd669","slug":"a","location":"/a.md","dependencies":[],"frontmatter":{"title":"This is page A","authors":[{"id":"Franklin Koch","name":"Franklin Koch"}],"date":"2025-01-09","numbering":{"heading_2":{"enabled":false},"heading_1":{"enabled":true},"heading_3":{"enabled":true},"heading_4":{"enabled":true},"heading_5":{"enabled":true},"heading_6":{"enabled":true}},"thumbnail":"/image-2eb81ec114b2b08e10c612194184a457.png","thumbnailOptimized":"/image-2eb81ec114b2b08e10c612194184a457.webp","exports":[{"format":"md","filename":"a.md","url":"/a-c4bc29e370e82843ec69fb622ee3fd87.md"}]},"mdast":{"type":"root","children":[{"type":"block","children":[{"type":"heading","depth":2,"position":{"start":{"line":5,"column":1},"end":{"line":5,"column":1}},"children":[{"type":"text","value":"Heading one on page A","position":{"start":{"line":5,"column":1},"end":{"line":5,"column":1}},"key":"cafqpsWw9T"}],"identifier":"heading-one-on-page-a","label":"Heading one on page A","html_id":"heading-one-on-page-a","implicit":true,"key":"Fx1Pg9nvVc"},{"type":"paragraph","position":{"start":{"line":7,"column":1},"end":{"line":7,"column":1}},"children":[{"type":"text","value":"Some text","position":{"start":{"line":7,"column":1},"end":{"line":7,"column":1}},"key":"pWgq1eg956"}],"key":"s6sIUYqu4w"},{"type":"heading","depth":3,"position":{"start":{"line":9,"column":1},"end":{"line":9,"column":1}},"children":[{"type":"text","value":"Heading two on page A","position":{"start":{"line":9,"column":1},"end":{"line":9,"column":1}},"key":"Yh5TZXNXGk"}],"identifier":"heading-two-on-page-a","label":"Heading two on page A","html_id":"heading-two-on-page-a","implicit":true,"enumerator":"1","key":"PkZxdNaCH5"},{"type":"paragraph","position":{"start":{"line":11,"column":1},"end":{"line":11,"column":1}},"children":[{"type":"text","value":"More text","position":{"start":{"line":11,"column":1},"end":{"line":11,"column":1}},"key":"M4PZwkmUuR"}],"key":"Y5zMUCzg1F"},{"type":"container","kind":"figure","children":[{"type":"image","url":"/image-2eb81ec114b2b08e10c612194184a457.png","alt":"I would like this to be figure 1","data":{"altTextIsAutoGenerated":true},"key":"kN2Uoz0C09","urlSource":"image.png","urlOptimized":"/image-2eb81ec114b2b08e10c612194184a457.webp"},{"type":"caption","children":[{"type":"paragraph","position":{"start":{"line":16,"column":1},"end":{"line":16,"column":1}},"children":[{"type":"captionNumber","kind":"figure","label":"fig-a","identifier":"fig-a","html_id":"fig-a","enumerator":"1","children":[{"type":"text","value":"Figure ","key":"SdN09vpjfE"},{"type":"text","value":"1","key":"OqyY90ltvx"},{"type":"text","value":":","key":"Cjs7yY8KVp"}],"template":"Figure %s:","key":"AVEnBTsu95"},{"type":"text","value":"I would like this to be figure 1","position":{"start":{"line":16,"column":1},"end":{"line":16,"column":1}},"key":"JsLheb8hMD"}],"key":"kYwum0W1vk"}],"key":"fJrcCi42QA"}],"label":"fig-a","identifier":"fig-a","enumerator":"1","html_id":"fig-a","key":"UeXbP6trpQ"}],"key":"mu3fsUofuh"}],"key":"J2Q7jPIvhP"},"references":{"cite":{"order":[],"data":{}}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"kind":"Article","sha256":"9f758b8b800fc8188259664c164d45fbae935f305012a644f0ddc6df5d534a6f","slug":"b","location":"/b.md","dependencies":[],"frontmatter":{"title":"This is page B - title in markdown","content_includes_title":false,"authors":[{"id":"Franklin Koch","name":"Franklin Koch"}],"date":"2025-01-09","numbering":{"heading_2":{"enabled":false},"heading_1":{"enabled":true},"heading_3":{"enabled":true},"heading_4":{"enabled":true},"heading_5":{"enabled":true},"heading_6":{"enabled":true}},"thumbnail":"/image-2eb81ec114b2b08e10c612194184a457.png","thumbnailOptimized":"/image-2eb81ec114b2b08e10c612194184a457.webp","exports":[{"format":"md","filename":"b.md","url":"/b-cadd6822a5046e185905f452b04fad05.md"}]},"mdast":{"type":"root","children":[{"type":"block","children":[{"type":"heading","depth":2,"position":{"start":{"line":3,"column":1},"end":{"line":3,"column":1}},"children":[{"type":"text","value":"Heading one on page B","position":{"start":{"line":3,"column":1},"end":{"line":3,"column":1}},"key":"v6eF3aAeDu"}],"identifier":"heading-one-on-page-b","label":"Heading one on page B","html_id":"heading-one-on-page-b","implicit":true,"key":"m2T9J1affT"},{"type":"paragraph","position":{"start":{"line":5,"column":1},"end":{"line":5,"column":1}},"children":[{"type":"text","value":"Some text","position":{"start":{"line":5,"column":1},"end":{"line":5,"column":1}},"key":"ywQ4OLneaZ"}],"key":"U8ygfioPpJ"},{"type":"heading","depth":3,"position":{"start":{"line":7,"column":1},"end":{"line":7,"column":1}},"children":[{"type":"text","value":"Heading two on page B","position":{"start":{"line":7,"column":1},"end":{"line":7,"column":1}},"key":"lWuLIdJSSw"}],"identifier":"heading-two-on-page-b","label":"Heading two on page B","html_id":"heading-two-on-page-b","implicit":true,"enumerator":"1","key":"kwRhML4AzZ"},{"type":"paragraph","position":{"start":{"line":9,"column":1},"end":{"line":9,"column":1}},"children":[{"type":"text","value":"More text","position":{"start":{"line":9,"column":1},"end":{"line":9,"column":1}},"key":"KYD0IkrjEO"}],"key":"LGxQBMNS4x"},{"type":"container","kind":"figure","children":[{"type":"image","url":"/image-2eb81ec114b2b08e10c612194184a457.png","alt":"I would like this to be figure 1","data":{"altTextIsAutoGenerated":true},"key":"vz6Cxoe6an","urlSource":"image.png","urlOptimized":"/image-2eb81ec114b2b08e10c612194184a457.webp"},{"type":"caption","children":[{"type":"paragraph","position":{"start":{"line":14,"column":1},"end":{"line":14,"column":1}},"children":[{"type":"captionNumber","kind":"figure","label":"fig-b","identifier":"fig-b","html_id":"fig-b","enumerator":"1","children":[{"type":"text","value":"Figure ","key":"z8ymVpEtIK"},{"type":"text","value":"1","key":"F6WJLNwu57"},{"type":"text","value":":","key":"itIper67Hu"}],"template":"Figure %s:","key":"RJWCtG0Y5R"},{"type":"text","value":"I would like this to be figure 1","position":{"start":{"line":14,"column":1},"end":{"line":14,"column":1}},"key":"bLdZyTxiAK"}],"key":"UXnCJk2ARF"}],"key":"RwjOuAaxos"}],"label":"fig-b","identifier":"fig-b","enumerator":"1","html_id":"fig-b","key":"CXUCT6I29R"}],"key":"qgBUT4UKBN"}],"key":"PMRP1pn2En"},"references":{"cite":{"order":[],"data":{}}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"kind":"Article","sha256":"aaa3c247d843e735f6660a1b650e82354912de1d1da606257ec88cc0430c8761","slug":"c","location":"/c.md","dependencies":[],"frontmatter":{"title":"This is page C","authors":[{"id":"Franklin Koch","name":"Franklin Koch"}],"date":"2025-01-09","numbering":{"heading_2":{"enabled":false},"heading_1":{"enabled":true},"heading_3":{"enabled":true},"heading_4":{"enabled":true},"heading_5":{"enabled":true},"heading_6":{"enabled":true}},"thumbnail":"/image-2eb81ec114b2b08e10c612194184a457.png","thumbnailOptimized":"/image-2eb81ec114b2b08e10c612194184a457.webp","exports":[{"format":"md","filename":"c.md","url":"/c-b792186c6e8d1d5744cbadaa8dbcd176.md"}]},"mdast":{"type":"root","children":[{"type":"block","children":[{"type":"heading","depth":2,"position":{"start":{"line":5,"column":1},"end":{"line":5,"column":1}},"children":[{"type":"text","value":"Heading one on page C","position":{"start":{"line":5,"column":1},"end":{"line":5,"column":1}},"key":"OX7t2v4HPB"}],"identifier":"heading-one-on-page-c","label":"Heading one on page C","html_id":"heading-one-on-page-c","implicit":true,"key":"YkhkFdoGwD"},{"type":"paragraph","position":{"start":{"line":7,"column":1},"end":{"line":7,"column":1}},"children":[{"type":"text","value":"Some text","position":{"start":{"line":7,"column":1},"end":{"line":7,"column":1}},"key":"JmEO9BRcp2"}],"key":"d8wC7Sfz1j"},{"type":"heading","depth":3,"position":{"start":{"line":9,"column":1},"end":{"line":9,"column":1}},"children":[{"type":"text","value":"Heading two on page C","position":{"start":{"line":9,"column":1},"end":{"line":9,"column":1}},"key":"RTMGxK6PLo"}],"identifier":"heading-two-on-page-c","label":"Heading two on page C","html_id":"heading-two-on-page-c","implicit":true,"enumerator":"1","key":"tbwDvzYRtd"},{"type":"paragraph","position":{"start":{"line":11,"column":1},"end":{"line":11,"column":1}},"children":[{"type":"text","value":"More text","position":{"start":{"line":11,"column":1},"end":{"line":11,"column":1}},"key":"WbqD9KamrI"}],"key":"ylrVm3YZcf"},{"type":"container","kind":"figure","children":[{"type":"image","url":"/image-2eb81ec114b2b08e10c612194184a457.png","alt":"I would like this to be figure 1","data":{"altTextIsAutoGenerated":true},"key":"X47ws1IJjy","urlSource":"image.png","urlOptimized":"/image-2eb81ec114b2b08e10c612194184a457.webp"},{"type":"caption","children":[{"type":"paragraph","position":{"start":{"line":16,"column":1},"end":{"line":16,"column":1}},"children":[{"type":"captionNumber","kind":"figure","label":"fig-c","identifier":"fig-c","html_id":"fig-c","enumerator":"1","children":[{"type":"text","value":"Figure ","key":"gbxk9GDGeX"},{"type":"text","value":"1","key":"xPAL7D1KBU"},{"type":"text","value":":","key":"Fgw2jsFisP"}],"template":"Figure %s:","key":"WVRajXr654"},{"type":"text","value":"I would like this to be figure 1","position":{"start":{"line":16,"column":1},"end":{"line":16,"column":1}},"key":"VHzTaz7PwK"}],"key":"yA3oDW87C4"}],"key":"gtiwnlW7w3"}],"label":"fig-c","identifier":"fig-c","enumerator":"1","html_id":"fig-c","key":"SecJ5A3Yl8"}],"key":"SGUEuEGQOg"}],"key":"RBrQPFHNWa"},"references":{"cite":{"order":[],"data":{}}}}
Loading

0 comments on commit 8ef3478

Please sign in to comment.