astro/packages/astro/test/astro-client-only.test.js
Nate Moore 824c1f2024
Implement client:only handling (#1716)
* WIP: improve `client:only` handling

* feat: implement `client:only` in renderer

* test: reenable client:only tests

* feat: improve SSR error messages

* fix: add `resolvePath` method to Metadata

* test: fix client-only test

* chore: fix custom-elements handling

* test: revert `custom-elements` test change

* fix: do not assign a default renderer even if there's only one configured

* chore: bump compiler

* chore: add changeset
2021-11-16 10:01:14 -06:00

34 lines
1 KiB
JavaScript

import { expect } from 'chai';
import cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
let fixture;
before(async () => {
fixture = await loadFixture({ projectRoot: './fixtures/astro-client-only/' });
await fixture.build();
});
describe('Client only components', () => {
it('Loads pages using client:only hydrator', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
// test 1: <astro-root> is empty
expect($('astro-root').html()).to.equal('');
const src = $('script').attr('src');
const script = await fixture.readFile(src);
// test 2: svelte renderer is on the page
const exp = /import\("(.\/client.*)"\)/g;
let match, svelteRenderer;
while ((match = exp.exec(script))) {
svelteRenderer = match[1].replace(/^\./, '/assets/');
}
expect(svelteRenderer).to.be.ok;
// test 3: can load svelte renderer
const svelteClient = await fixture.readFile(svelteRenderer);
expect(svelteClient).to.be.ok;
});
});