Add test to verify Lit works in SSR (#3158)
This commit is contained in:
parent
eea9090ed5
commit
12f6b60998
2 changed files with 36 additions and 0 deletions
|
@ -24,11 +24,13 @@ export class MyElement extends LitElement {
|
||||||
this.reflectedStr = 'default reflected string';
|
this.reflectedStr = 'default reflected string';
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
|
let typeofwindow = typeof window.Window;
|
||||||
return html`
|
return html`
|
||||||
<div>Testing...</div>
|
<div>Testing...</div>
|
||||||
<div id="bool">${this.bool ? 'A' : 'B'}</div>
|
<div id="bool">${this.bool ? 'A' : 'B'}</div>
|
||||||
<div id="str">${this.str}</div>
|
<div id="str">${this.str}</div>
|
||||||
<div id="data">data: ${this.obj.data}</div>
|
<div id="data">data: ${this.obj.data}</div>
|
||||||
|
<div id="win">${typeofwindow}</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
34
packages/astro/test/ssr-lit.test.js
Normal file
34
packages/astro/test/ssr-lit.test.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import { load as cheerioLoad } from 'cheerio';
|
||||||
|
import { loadFixture } from './test-utils.js';
|
||||||
|
import testAdapter from './test-adapter.js';
|
||||||
|
|
||||||
|
describe('Lit integration in SSR', () => {
|
||||||
|
/** @type {import('./test-utils').Fixture} */
|
||||||
|
let fixture;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
fixture = await loadFixture({
|
||||||
|
root: './fixtures/lit-element/',
|
||||||
|
experimental: {
|
||||||
|
ssr: true,
|
||||||
|
},
|
||||||
|
adapter: testAdapter(),
|
||||||
|
});
|
||||||
|
await fixture.build();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function fetchHTML(path) {
|
||||||
|
const app = await fixture.loadTestAdapterApp();
|
||||||
|
const request = new Request('http://example.com' + path);
|
||||||
|
const response = await app.render(request);
|
||||||
|
const html = await response.text();
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
it('Is able to load', async () => {
|
||||||
|
const html = await fetchHTML('/');
|
||||||
|
const $ = cheerioLoad(html);
|
||||||
|
expect($('#win').text()).to.equal('function');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue