aboutsummaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/test/mdx-script-style-raw.test.js
diff options
context:
space:
mode:
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.js75
1 files changed, 75 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..dc4f337bf
--- /dev/null
+++ b/packages/integrations/mdx/test/mdx-script-style-raw.test.js
@@ -0,0 +1,75 @@
+import * as assert from 'node:assert/strict';
+import { after, before, describe, it } from 'node:test';
+import mdx from '@astrojs/mdx';
+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');
+ assert.equal(res.status, 200);
+
+ const html = await res.text();
+ const { document } = parseHTML(html);
+
+ const scriptContent = document.getElementById('test-script').innerHTML;
+ assert.equal(
+ scriptContent.includes("console.log('raw script')"),
+ true,
+ 'script should not be html-escaped',
+ );
+
+ const styleContent = document.getElementById('test-style').innerHTML;
+ assert.equal(
+ styleContent.includes('h1[id="script-style-raw"]'),
+ true,
+ '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;
+ assert.equal(
+ scriptContent.includes("console.log('raw script')"),
+ true,
+ 'script should not be html-escaped',
+ );
+
+ const styleContent = document.getElementById('test-style').innerHTML;
+ assert.equal(
+ styleContent.includes('h1[id="script-style-raw"]'),
+ true,
+ 'style should not be html-escaped',
+ );
+ });
+ });
+});