0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-13 22:11:20 -05:00
astro/packages/integrations/mdx/test/mdx-math.test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
2 KiB
JavaScript
Raw Normal View History

2024-01-31 21:37:34 +13:00
import * as assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import mdx from '@astrojs/mdx';
import { parseHTML } from 'linkedom';
import rehypeMathjaxSvg from 'rehype-mathjax';
import rehypeMathjaxChtml from 'rehype-mathjax/chtml';
import remarkMath from 'remark-math';
import { loadFixture } from '../../../astro/test/test-utils.js';
const FIXTURE_ROOT = new URL('./fixtures/mdx-math/', import.meta.url);
describe('MDX math', () => {
describe('mathjax', () => {
it('works with svg', async () => {
const fixture = await loadFixture({
root: FIXTURE_ROOT,
markdown: {
remarkPlugins: [remarkMath],
rehypePlugins: [rehypeMathjaxSvg],
},
integrations: [mdx()],
});
await fixture.build();
const html = await fixture.readFile('/mathjax/index.html');
const { document } = parseHTML(html);
const mjxContainer = document.querySelector('mjx-container[jax="SVG"]');
2024-01-31 21:37:34 +13:00
assert.notEqual(mjxContainer, null);
feat: experimental responsive images (#12377) * chore: changeset * feat: add experimental responsive images config option (#12378) * feat: add experimental responsive images config option * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update config types * Move config into `images` * Move jsdocs --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * feat: add responsive image component (#12381) * feat: add experimental responsive images config option * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update config types * Move config into `images` * Move jsdocs * wip: responsive image component * Improve srcset logic * Improve fixture * Lock * Update styling * Fix style prop handling * Update test (there's an extra style for images now) * Safely access the src props * Remove unused export * Handle priority images * Consolidate styles * Update tests * Comment * Refactor srcset * Avoid dupes of original image * Calculate missing dimensions * Bugfixes * Add tests * Fix test * Correct order * Lint * Fix fspath * Update test * Fix test * Conditional component per flag * Fix class concatenation * Remove logger * Rename helper * Add comments * Format * Fix markdoc tests * Add test for style tag --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * feat: add crop support to image services (#12414) * wip: add crop support to image services * Add tests * Strip crop attributes * Don't upscale * Format * Get build working properly * Changes from review * Fix jsdoc * feat: add responsive support to picture component (#12423) * feat: add responsive support to picture component * Add picture tests * Fix test * Implement own define vars * Share logic * Prevent extra astro-* class * Use dataset scoping * Revert unit test * Revert "Fix test" This reverts commit f9ec6e2938ff291037234d56f8eec76a93be0c0d. * Changes from review * docs: add docs for responsive images (#12429) * docs: add responsive images flag docs * docs: adds jsdoc for image components * chore: updates from review * Fix jsdoc * Changes from review * Add breakpoints option * typo --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2024-11-15 13:29:52 +00:00
const mjxStyle = document.querySelectorAll('style')[1].innerHTML;
2024-01-31 21:37:34 +13:00
assert.equal(
mjxStyle.includes('mjx-container[jax="SVG"]'),
true,
'style should not be html-escaped',
);
});
it('works with chtml', async () => {
const fixture = await loadFixture({
root: FIXTURE_ROOT,
markdown: {
remarkPlugins: [remarkMath],
rehypePlugins: [
[
rehypeMathjaxChtml,
{
chtml: {
fontURL: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/output/chtml/fonts/woff-v2',
},
},
],
],
},
integrations: [mdx()],
});
await fixture.build();
const html = await fixture.readFile('/mathjax/index.html');
const { document } = parseHTML(html);
const mjxContainer = document.querySelector('mjx-container[jax="CHTML"]');
2024-01-31 21:37:34 +13:00
assert.notEqual(mjxContainer, null);
feat: experimental responsive images (#12377) * chore: changeset * feat: add experimental responsive images config option (#12378) * feat: add experimental responsive images config option * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update config types * Move config into `images` * Move jsdocs --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * feat: add responsive image component (#12381) * feat: add experimental responsive images config option * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update config types * Move config into `images` * Move jsdocs * wip: responsive image component * Improve srcset logic * Improve fixture * Lock * Update styling * Fix style prop handling * Update test (there's an extra style for images now) * Safely access the src props * Remove unused export * Handle priority images * Consolidate styles * Update tests * Comment * Refactor srcset * Avoid dupes of original image * Calculate missing dimensions * Bugfixes * Add tests * Fix test * Correct order * Lint * Fix fspath * Update test * Fix test * Conditional component per flag * Fix class concatenation * Remove logger * Rename helper * Add comments * Format * Fix markdoc tests * Add test for style tag --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * feat: add crop support to image services (#12414) * wip: add crop support to image services * Add tests * Strip crop attributes * Don't upscale * Format * Get build working properly * Changes from review * Fix jsdoc * feat: add responsive support to picture component (#12423) * feat: add responsive support to picture component * Add picture tests * Fix test * Implement own define vars * Share logic * Prevent extra astro-* class * Use dataset scoping * Revert unit test * Revert "Fix test" This reverts commit f9ec6e2938ff291037234d56f8eec76a93be0c0d. * Changes from review * docs: add docs for responsive images (#12429) * docs: add responsive images flag docs * docs: adds jsdoc for image components * chore: updates from review * Fix jsdoc * Changes from review * Add breakpoints option * typo --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2024-11-15 13:29:52 +00:00
const mjxStyle = document.querySelectorAll('style')[1].innerHTML;
2024-01-31 21:37:34 +13:00
assert.equal(
mjxStyle.includes('mjx-container[jax="CHTML"]'),
true,
'style should not be html-escaped',
);
});
});
});