0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00
astro/packages/integrations/markdoc/test/propagated-assets.test.js
Emanuele Stoppa 062623438b
chore: use biome to sort imports - only test files (#10180)
* chore: use biome to sort imports

* do the sorting

* Update package.json

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>

---------

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
2024-02-21 14:08:19 +00:00

69 lines
2.2 KiB
JavaScript

import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { parseHTML } from 'linkedom';
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),
// test suite was authored when inlineStylesheets defaulted to never
build: { inlineStylesheets: 'never' },
});
});
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');
assert.equal(styles.length, 1);
styleContents = styles[0].textContent;
} else {
const links = stylesDocument.querySelectorAll('link[rel="stylesheet"]');
assert.equal(links.length, 1);
styleContents = await fixture.readFile(links[0].href);
}
assert.equal(styleContents.includes('--color-base-purple: 269, 79%;'), true);
});
it('[fails] Does not bleed styles to other page', async () => {
if (mode === 'dev') {
const styles = scriptsDocument.querySelectorAll('style');
assert.equal(styles.length, 0);
} else {
const links = scriptsDocument.querySelectorAll('link[rel="stylesheet"]');
assert.equal(links.length, 0);
}
});
});
}
});