* update examples * add initial integrations * update tests * update astro * update ci * get final tests working * update injectelement todo * update ben code review * respond to final code review feedback
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
import { expect } from 'chai';
|
|
import cheerio from 'cheerio';
|
|
import { loadFixture } from './test-utils.js';
|
|
|
|
describe('Dynamic components', () => {
|
|
let fixture;
|
|
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
projectRoot: './fixtures/astro-dynamic/',
|
|
});
|
|
await fixture.build();
|
|
});
|
|
|
|
it('Loads packages that only run code in client', async () => {
|
|
const html = await fixture.readFile('/index.html');
|
|
|
|
const $ = cheerio.load(html);
|
|
expect($('script').length).to.eq(2);
|
|
});
|
|
|
|
it('Loads pages using client:media hydrator', async () => {
|
|
const root = new URL('http://example.com/media/index.html');
|
|
const html = await fixture.readFile('/media/index.html');
|
|
const $ = cheerio.load(html);
|
|
|
|
// test 1: static value rendered
|
|
expect($('script').length).to.equal(2); // One for each
|
|
});
|
|
|
|
it('Loads pages using client:only hydrator', async () => {
|
|
const html = await fixture.readFile('/client-only/index.html');
|
|
const $ = cheerio.load(html);
|
|
|
|
// test 1: <astro-root> is empty.
|
|
expect($('<astro-root>').html()).to.equal('');
|
|
// test 2: correct script is being loaded.
|
|
// because of bundling, we don't have access to the source import,
|
|
// only the bundled import.
|
|
expect($('script').html()).to.include(`import setup from '../only`);
|
|
});
|
|
});
|