astro/packages/astro/test/hydration-race.test.js
Fred K. Schott 1d3a0a16f3
Revert "Ensure hydration scripts inside of slots render ASAP (#4288)" (#4302)
* Revert "Ensure hydration scripts inside of slots render ASAP (#4288)"

This reverts commit c218100684.

* Create khaki-dots-press.md
2022-08-13 10:00:12 -07:00

29 lines
1 KiB
JavaScript

import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
describe('Hydration script ordering', async () => {
let fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/hydration-race' });
await fixture.build();
});
it('Places the hydration script before the first island', async () => {
let html = await fixture.readFile('/index.html');
let $ = cheerio.load(html);
// First, let's make sure all islands rendered (or test is bad)
expect($('astro-island')).to.have.a.lengthOf(3);
// Now let's make sure the hydration script is placed before the first component
let firstIsland = $($('astro-island').get(0));
let prevSibling = firstIsland.prev();
expect(prevSibling.prop('tagName')).to.equal('SCRIPT');
// Sanity check that we're only rendering them once.
expect($('style')).to.have.a.lengthOf(1, 'hydration style added once');
expect($('script')).to.have.a.lengthOf(1, 'only one hydration script needed');
});
});