From c99c8bedbd4db665355e5a63aa19be56a65caf73 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 23 Jun 2022 09:03:43 -0400 Subject: [PATCH] Include partytown scripts in SSR manifest (#3686) * Include partytown scripts in SSR manifst * Adds a changeset --- test/fixtures/ssr-partytown/astro.config.mjs | 7 ++++ test/fixtures/ssr-partytown/package.json | 9 +++++ .../ssr-partytown/src/pages/index.astro | 6 ++++ test/ssr-partytown.test.js | 34 +++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 test/fixtures/ssr-partytown/astro.config.mjs create mode 100644 test/fixtures/ssr-partytown/package.json create mode 100644 test/fixtures/ssr-partytown/src/pages/index.astro create mode 100644 test/ssr-partytown.test.js 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'); + }); +});