diff options
author | 2023-05-31 19:18:07 -0400 | |
---|---|---|
committer | 2023-05-31 19:18:07 -0400 | |
commit | 339529fc820bac2d514b63198ecf54a1d88c0917 (patch) | |
tree | 8b553c0df30c1aa60a037fb915bcf7fdfaea945f /packages/integrations/markdoc/test/propagated-assets.test.js | |
parent | c4c086e5e70bdd347e1c7601212a04b4f523578e (diff) | |
download | astro-339529fc820bac2d514b63198ecf54a1d88c0917.tar.gz astro-339529fc820bac2d514b63198ecf54a1d88c0917.tar.zst astro-339529fc820bac2d514b63198ecf54a1d88c0917.zip |
Markdoc asset bleed, second try (#7185)
* Revert "revert: markdoc asset bleed (#7178)"
This reverts commit 57e65d247f67de61bcc3a585c2254feb61ed2e74.
* fix: missing result param on `renderUniqueStylesheet`
* test: bundled styles (fails!)
* fix: use `type: 'external'` for links
* fix: split Astro components from markdoc config
* test: style bleed (it fails...)
* chore: remove unused util
* fix: revert entry change
* Stop traversing the graph when you encounter a propagated asset
* chore: cleanup unused `entry` prop
* refactor: add isPropagatedAssetsMod check
* chore: remove unused import
* chore: changeset
* Normalize path using vite
* Update packages/integrations/markdoc/src/index.ts
Co-authored-by: Ben Holmes <hey@bholmes.dev>
---------
Co-authored-by: Matthew Phillips <matthew@skypack.dev>
Co-authored-by: bholmesdev <bholmesdev@gmail.com>
Co-authored-by: Matthew Phillips <matthew@matthewphillips.info>
Diffstat (limited to 'packages/integrations/markdoc/test/propagated-assets.test.js')
-rw-r--r-- | packages/integrations/markdoc/test/propagated-assets.test.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/packages/integrations/markdoc/test/propagated-assets.test.js b/packages/integrations/markdoc/test/propagated-assets.test.js new file mode 100644 index 000000000..429e07141 --- /dev/null +++ b/packages/integrations/markdoc/test/propagated-assets.test.js @@ -0,0 +1,66 @@ +import { parseHTML } from 'linkedom'; +import { expect } from 'chai'; +import { loadFixture } from '../../../astro/test/test-utils.js'; + +describe('Markdoc - propagated assets', () => { + let fixture; + let devServer; + before(async () => { + fixture = await loadFixture({ + root: new URL('./fixtures/propagated-assets/', import.meta.url), + }); + }); + + const modes = ['dev', 'prod']; + + for (const mode of modes) { + describe(mode, () => { + /** @type {Document} */ + let stylesDocument; + /** @type {Document} */ + let scriptsDocument; + + before(async () => { + if (mode === 'prod') { + await fixture.build(); + stylesDocument = parseHTML(await fixture.readFile('/styles/index.html')).document; + scriptsDocument = parseHTML(await fixture.readFile('/scripts/index.html')).document; + } else if (mode === 'dev') { + devServer = await fixture.startDevServer(); + const styleRes = await fixture.fetch('/styles'); + const scriptRes = await fixture.fetch('/scripts'); + stylesDocument = parseHTML(await styleRes.text()).document; + scriptsDocument = parseHTML(await scriptRes.text()).document; + } + }); + + after(async () => { + if (mode === 'dev') devServer?.stop(); + }); + + it('Bundles styles', async () => { + let styleContents; + if (mode === 'dev') { + const styles = stylesDocument.querySelectorAll('style'); + expect(styles).to.have.lengthOf(1); + styleContents = styles[0].textContent; + } else { + const links = stylesDocument.querySelectorAll('link[rel="stylesheet"]'); + expect(links).to.have.lengthOf(1); + styleContents = await fixture.readFile(links[0].href); + } + expect(styleContents).to.include('--color-base-purple: 269, 79%;'); + }); + + it('[fails] Does not bleed styles to other page', async () => { + if (mode === 'dev') { + const styles = scriptsDocument.querySelectorAll('style'); + expect(styles).to.have.lengthOf(0); + } else { + const links = scriptsDocument.querySelectorAll('link[rel="stylesheet"]'); + expect(links).to.have.lengthOf(0); + } + }); + }); + } +}); |