diff options
author | 2022-04-20 14:16:04 -0400 | |
---|---|---|
committer | 2022-04-20 14:16:04 -0400 | |
commit | 12f6b6099810f3f56e5ca956c84216725a6d777c (patch) | |
tree | 6c8cdae67acb0957054f2d1bcad832beb784d356 | |
parent | eea9090ed5637730411456e2c8970fc2f841da9e (diff) | |
download | astro-12f6b6099810f3f56e5ca956c84216725a6d777c.tar.gz astro-12f6b6099810f3f56e5ca956c84216725a6d777c.tar.zst astro-12f6b6099810f3f56e5ca956c84216725a6d777c.zip |
Add test to verify Lit works in SSR (#3158)
-rw-r--r-- | packages/astro/test/fixtures/lit-element/src/components/my-element.js | 2 | ||||
-rw-r--r-- | packages/astro/test/ssr-lit.test.js | 34 |
2 files changed, 36 insertions, 0 deletions
diff --git a/packages/astro/test/fixtures/lit-element/src/components/my-element.js b/packages/astro/test/fixtures/lit-element/src/components/my-element.js index b4a780377..d3137c0ba 100644 --- a/packages/astro/test/fixtures/lit-element/src/components/my-element.js +++ b/packages/astro/test/fixtures/lit-element/src/components/my-element.js @@ -24,11 +24,13 @@ export class MyElement extends LitElement { this.reflectedStr = 'default reflected string'; } render() { + let typeofwindow = typeof window.Window; return html` <div>Testing...</div> <div id="bool">${this.bool ? 'A' : 'B'}</div> <div id="str">${this.str}</div> <div id="data">data: ${this.obj.data}</div> + <div id="win">${typeofwindow}</div> `; } } diff --git a/packages/astro/test/ssr-lit.test.js b/packages/astro/test/ssr-lit.test.js new file mode 100644 index 000000000..c989e3559 --- /dev/null +++ b/packages/astro/test/ssr-lit.test.js @@ -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'); + }); +}); |