diff --git a/test/fixtures/ssr-partytown/astro.config.mjs b/test/fixtures/ssr-partytown/astro.config.mjs new file mode 100644 index 000000000000..ea1fb12db89c --- /dev/null +++ b/test/fixtures/ssr-partytown/astro.config.mjs @@ -0,0 +1,7 @@ +import { defineConfig } from 'astro/config'; +import partytown from '@astrojs/partytown'; + +// https://astro.build/config +export default defineConfig({ + integrations: [partytown()], +}); diff --git a/test/fixtures/ssr-partytown/package.json b/test/fixtures/ssr-partytown/package.json new file mode 100644 index 000000000000..5713e2d1bc46 --- /dev/null +++ b/test/fixtures/ssr-partytown/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/ssr-partytown", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*", + "@astrojs/partytown": "workspace:*" + } +} diff --git a/test/fixtures/ssr-partytown/src/pages/index.astro b/test/fixtures/ssr-partytown/src/pages/index.astro new file mode 100644 index 000000000000..743a9d35afbe --- /dev/null +++ b/test/fixtures/ssr-partytown/src/pages/index.astro @@ -0,0 +1,6 @@ + + testing + +

testing

+ + diff --git a/test/ssr-partytown.test.js b/test/ssr-partytown.test.js new file mode 100644 index 000000000000..5ea2bcde59e9 --- /dev/null +++ b/test/ssr-partytown.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('Using the Partytown integration in SSR', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/ssr-partytown/', + adapter: testAdapter(), + experimental: { + ssr: true, + }, + }); + await fixture.build(); + }); + + it('Has the scripts in the page', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/'); + const response = await app.render(request); + const html = await response.text(); + const $ = cheerioLoad(html); + expect($('script')).to.have.a.lengthOf(1); + }); + + it('The partytown scripts are in the manifest', async () => { + const app = await fixture.loadTestAdapterApp(); + expect(app.manifest.assets).to.contain('/~partytown/partytown-sw.js'); + }); +});