mdx-astro-markdown-remarkRehype.test.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import mdx from '@astrojs/mdx';
  2. import { describe, it } from 'node:test';
  3. import * as assert from 'node:assert/strict';
  4. import { parseHTML } from 'linkedom';
  5. import { loadFixture } from '../../../astro/test/test-utils.js';
  6. describe('MDX with Astro Markdown remark-rehype config', () => {
  7. it('Renders footnotes with values from the default configuration', async () => {
  8. const fixture = await loadFixture({
  9. root: new URL('./fixtures/mdx-astro-markdown-remarkRehype/', import.meta.url),
  10. integrations: [mdx()],
  11. markdown: {
  12. remarkRehype: {
  13. footnoteLabel: 'Catatan kaki',
  14. footnoteBackLabel: 'Kembali ke konten',
  15. },
  16. },
  17. });
  18. await fixture.build();
  19. const html = await fixture.readFile('/index.html');
  20. const { document } = parseHTML(html);
  21. assert.equal(document.querySelector('#footnote-label').textContent, 'Catatan kaki');
  22. assert.equal(
  23. document.querySelector('.data-footnote-backref').getAttribute('aria-label'),
  24. 'Kembali ke konten'
  25. );
  26. });
  27. it('Renders footnotes with values from custom configuration extending the default', async () => {
  28. const fixture = await loadFixture({
  29. root: new URL('./fixtures/mdx-astro-markdown-remarkRehype/', import.meta.url),
  30. integrations: [
  31. mdx({
  32. remarkRehype: {
  33. footnoteLabel: 'Catatan kaki',
  34. footnoteBackLabel: 'Kembali ke konten',
  35. },
  36. }),
  37. ],
  38. markdown: {
  39. remarkRehype: {
  40. footnoteBackLabel: 'Replace me',
  41. },
  42. },
  43. });
  44. await fixture.build();
  45. const html = await fixture.readFile('/index.html');
  46. const { document } = parseHTML(html);
  47. assert.equal(document.querySelector('#footnote-label').textContent, 'Catatan kaki');
  48. assert.equal(
  49. document.querySelector('.data-footnote-backref').getAttribute('aria-label'),
  50. 'Kembali ke konten'
  51. );
  52. });
  53. it('Renders footnotes with values from custom configuration without extending the default', async () => {
  54. const fixture = await loadFixture({
  55. root: new URL('./fixtures/mdx-astro-markdown-remarkRehype/', import.meta.url),
  56. integrations: [
  57. mdx({
  58. extendPlugins: 'astroDefaults',
  59. remarkRehype: {
  60. footnoteLabel: 'Catatan kaki',
  61. },
  62. }),
  63. ],
  64. markdown: {
  65. remarkRehype: {
  66. footnoteBackLabel: 'Kembali ke konten',
  67. },
  68. },
  69. });
  70. await fixture.build();
  71. const html = await fixture.readFile('/index.html');
  72. const { document } = parseHTML(html);
  73. assert.equal(document.querySelector('#footnote-label').textContent, 'Catatan kaki');
  74. assert.equal(
  75. document.querySelector('.data-footnote-backref').getAttribute('aria-label'),
  76. 'Back to reference 1'
  77. );
  78. });
  79. });