0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00
astro/packages/astro/test/astro-partial-html.test.js
Matthew Phillips fa7ed3f3a9
Remove post-rendering head injection (#3679)
* Remove post-rendering head injection

* Adds a changeset

* Use a layout component for vue
2022-06-23 15:37:55 -04:00

49 lines
1.4 KiB
JavaScript

import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
describe('Partial HTML', async () => {
let fixture;
let devServer;
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-partial-html/',
});
devServer = await fixture.startDevServer();
});
after(async () => {
await devServer.stop();
});
it('injects Astro styles and scripts', async () => {
const html = await fixture.fetch('/astro').then((res) => res.text());
const $ = cheerio.load(html);
// test 1: Doctype first
expect(html).to.match(/^<!DOCTYPE html/);
// test 2: correct CSS present
const allInjectedStyles = $('style[data-astro-injected]').text();
expect(allInjectedStyles).to.match(/\.astro-[^{]+{color:red}/);
});
it('injects framework styles', async () => {
const html = await fixture.fetch('/jsx').then((res) => res.text());
const $ = cheerio.load(html);
// test 1: Doctype first
expect(html).to.match(/^<!DOCTYPE html/);
// test 2: link tag present
const allInjectedStyles = $('style[data-astro-injected]').text().replace(/\s*/g, '');
expect(allInjectedStyles).to.match(/h1{color:red;}/);
});
it('pages with a head, injection happens inside', async () => {
const html = await fixture.fetch('/with-head').then((res) => res.text());
const $ = cheerio.load(html);
expect($('style')).to.have.lengthOf(1);
});
});