Brings back astro-dynamic tests (#1548)
This commit is contained in:
parent
b418ae31b8
commit
f199c69eab
7 changed files with 29 additions and 50 deletions
|
@ -40,7 +40,7 @@
|
|||
"test": "mocha --parallel --timeout 15000"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/compiler": "^0.1.12",
|
||||
"@astrojs/compiler": "^0.1.13",
|
||||
"@astrojs/language-server": "^0.7.16",
|
||||
"@astrojs/markdown-remark": "^0.3.1",
|
||||
"@astrojs/markdown-support": "0.3.1",
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
/**
|
||||
* UNCOMMENT: fix transform error and "window is not defined" Vite error
|
||||
import { expect } from 'chai';
|
||||
import cheerio from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
|
@ -12,37 +10,29 @@ before(async () => {
|
|||
});
|
||||
|
||||
describe('Dynamic components', () => {
|
||||
it('Loads client-only packages', async () => {
|
||||
const html = await fixture.fetch('/index.html');
|
||||
it('Loads packages that only run code in client', async () => {
|
||||
const html = await fixture.readFile('/index.html');
|
||||
|
||||
// Grab the react-dom import
|
||||
const exp = /import\("(.+?)"\)/g;
|
||||
let match, reactRenderer;
|
||||
while ((match = exp.exec(html))) {
|
||||
if (match[1].includes('renderers/renderer-react/client.js')) {
|
||||
reactRenderer = match[1];
|
||||
}
|
||||
}
|
||||
|
||||
// test 1: React renderer is on the page
|
||||
expect(reactRenderer).to.be.ok;
|
||||
|
||||
// test 2: Can load React renderer
|
||||
// const result = await fixture.fetch(reactRenderer);
|
||||
// expect(result.status).to.equal(200);
|
||||
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(html).to.include(`value: "(max-width: 700px)"`);
|
||||
|
||||
let js = await fixture.readFile(new URL($('script').attr('src'), root).pathname);
|
||||
expect(js).to.include(`value:"(max-width: 700px)"`);
|
||||
|
||||
// test 2: dynamic value rendered
|
||||
expect(html).to.include(`value: "(max-width: 600px)"`);
|
||||
js = await fixture.readFile(new URL($('script').eq(1).attr('src'), root).pathname);
|
||||
expect(js).to.include(`value:"(max-width: 600px)"`);
|
||||
});
|
||||
|
||||
it('Loads pages using client:only hydrator', async () => {
|
||||
it.skip('Loads pages using client:only hydrator', async () => {
|
||||
const html = await fixture.readFile('/client-only/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
|
@ -66,6 +56,3 @@ describe('Dynamic components', () => {
|
|||
// expect(result.status).to.equal(200);
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
it.skip('is skipped', () => {});
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
---
|
||||
import CounterRenamed from '../components/Counter.jsx';
|
||||
import SvelteCounterRenamed from '../components/SvelteCounter.svelte';
|
||||
---
|
||||
<html>
|
||||
<head><title>Dynamic pages</title></head>
|
||||
<body>
|
||||
<CounterRenamed client:load />
|
||||
|
||||
<SvelteCounterRenamed client:load />
|
||||
</body>
|
||||
</html>
|
|
@ -8,6 +8,6 @@ import SvelteCounter from '../components/SvelteCounter.svelte';
|
|||
<Counter client:load />
|
||||
|
||||
<!-- Including the original hydration syntax to test backwards compatibility -->
|
||||
<SvelteCounter:load />
|
||||
<SvelteCounter client:load />
|
||||
</body>
|
||||
</html>
|
|
@ -9,16 +9,20 @@ function check(Component, props, children) {
|
|||
return BaseComponent.isPrototypeOf(Component);
|
||||
}
|
||||
|
||||
const { html } = renderToStaticMarkup(Component, props, children);
|
||||
try {
|
||||
const { html } = renderToStaticMarkup(Component, props, children);
|
||||
|
||||
if (typeof html !== 'string') {
|
||||
if (typeof html !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// There are edge cases (SolidJS) where Preact *might* render a string,
|
||||
// but components would be <undefined></undefined>
|
||||
|
||||
return !/\<undefined\>/.test(html);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
||||
// There are edge cases (SolidJS) where Preact *might* render a string,
|
||||
// but components would be <undefined></undefined>
|
||||
|
||||
return !/\<undefined\>/.test(html);
|
||||
}
|
||||
|
||||
function renderToStaticMarkup(Component, props, children) {
|
||||
|
|
|
@ -106,10 +106,10 @@
|
|||
"@algolia/logger-common" "4.10.5"
|
||||
"@algolia/requester-common" "4.10.5"
|
||||
|
||||
"@astrojs/compiler@^0.1.12":
|
||||
version "0.1.12"
|
||||
resolved "https://registry.yarnpkg.com/@astrojs/compiler/-/compiler-0.1.12.tgz#e20fd240044505bea509e62c10f6e2a725e56e7a"
|
||||
integrity sha512-oBPK6Rw9K+En1rSB8/15YXF7fC4QhJKwzGaQ8a7AFMga8hJqQwY8rReiwmatAe/6lYNUKJjeLOLO3nE2lGXhzQ==
|
||||
"@astrojs/compiler@^0.1.13":
|
||||
version "0.1.13"
|
||||
resolved "https://registry.yarnpkg.com/@astrojs/compiler/-/compiler-0.1.13.tgz#06c810d71c7bcce1603ea77f9381940523544e69"
|
||||
integrity sha512-t/soXPJ34AQ67goh8EInCNVWd2HYOpgL5hE2xcZGwG74cIuczT4c+Guiqt50KYF5a7eNTdolPdy/dd7yipW8nQ==
|
||||
dependencies:
|
||||
typescript "^4.3.5"
|
||||
|
||||
|
|
Loading…
Reference in a new issue