summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/test/mdx-script-style-raw.test.js
diff options
context:
space:
mode:
authorGravatar Bjorn Lu <bjornlu.dev@gmail.com> 2023-03-09 00:29:22 +0800
committerGravatar GitHub <noreply@github.com> 2023-03-09 00:29:22 +0800
commit964d55246b73410b1e09b5716914f709a97cb387 (patch)
treeb8bc6c5e767dd7f7945c1f044dc7dfa638bb21bc /packages/integrations/mdx/test/mdx-script-style-raw.test.js
parent60c7690b4c26e64a6064ec8d90740fc105b07ec7 (diff)
downloadastro-964d55246b73410b1e09b5716914f709a97cb387.tar.gz
astro-964d55246b73410b1e09b5716914f709a97cb387.tar.zst
astro-964d55246b73410b1e09b5716914f709a97cb387.zip
Prevent HTML-escape of raw strings in JSX script/style tags (#6459)
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Diffstat (limited to 'packages/integrations/mdx/test/mdx-script-style-raw.test.js')
-rw-r--r--packages/integrations/mdx/test/mdx-script-style-raw.test.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/packages/integrations/mdx/test/mdx-script-style-raw.test.js b/packages/integrations/mdx/test/mdx-script-style-raw.test.js
new file mode 100644
index 000000000..99c17ed8d
--- /dev/null
+++ b/packages/integrations/mdx/test/mdx-script-style-raw.test.js
@@ -0,0 +1,70 @@
+import mdx from '@astrojs/mdx';
+import { expect } from 'chai';
+import { parseHTML } from 'linkedom';
+import { loadFixture } from '../../../astro/test/test-utils.js';
+
+const FIXTURE_ROOT = new URL('./fixtures/mdx-script-style-raw/', import.meta.url);
+
+describe('MDX script style raw', () => {
+ describe('dev', () => {
+ let fixture;
+ let devServer;
+
+ before(async () => {
+ fixture = await loadFixture({
+ root: FIXTURE_ROOT,
+ integrations: [mdx()],
+ });
+ devServer = await fixture.startDevServer();
+ });
+
+ after(async () => {
+ await devServer.stop();
+ });
+
+ it('works with with raw script and style strings', async () => {
+ const res = await fixture.fetch('/index.html');
+ expect(res.status).to.equal(200);
+
+ const html = await res.text();
+ const { document } = parseHTML(html);
+
+ const scriptContent = document.getElementById('test-script').innerHTML;
+ expect(scriptContent).to.include(
+ "console.log('raw script')",
+ 'script should not be html-escaped'
+ );
+
+ const styleContent = document.getElementById('test-style').innerHTML;
+ expect(styleContent).to.include(
+ 'h1[id="script-style-raw"]',
+ 'style should not be html-escaped'
+ );
+ });
+ });
+
+ describe('build', () => {
+ it('works with with raw script and style strings', async () => {
+ const fixture = await loadFixture({
+ root: FIXTURE_ROOT,
+ integrations: [mdx()],
+ });
+ await fixture.build();
+
+ const html = await fixture.readFile('/index.html');
+ const { document } = parseHTML(html);
+
+ const scriptContent = document.getElementById('test-script').innerHTML;
+ expect(scriptContent).to.include(
+ "console.log('raw script')",
+ 'script should not be html-escaped'
+ );
+
+ const styleContent = document.getElementById('test-style').innerHTML;
+ expect(styleContent).to.include(
+ 'h1[id="script-style-raw"]',
+ 'style should not be html-escaped'
+ );
+ });
+ });
+});