diff --git a/packages/integrations/sitemap/package.json b/packages/integrations/sitemap/package.json index afd959a62c92e..7c465494ee399 100644 --- a/packages/integrations/sitemap/package.json +++ b/packages/integrations/sitemap/package.json @@ -37,6 +37,7 @@ "zod": "^3.17.3" }, "devDependencies": { + "@astrojs/node": "workspace:*", "astro": "workspace:*", "astro-scripts": "workspace:*", "chai": "^4.3.6", diff --git a/packages/integrations/sitemap/test/fixtures/ssr/astro.config.mjs b/packages/integrations/sitemap/test/fixtures/ssr/astro.config.mjs new file mode 100644 index 0000000000000..d914d4357e9f1 --- /dev/null +++ b/packages/integrations/sitemap/test/fixtures/ssr/astro.config.mjs @@ -0,0 +1,12 @@ +import { defineConfig } from 'astro/config'; +import sitemap from '@astrojs/sitemap'; +import nodeServer from '@astrojs/node' + +export default defineConfig({ + integrations: [sitemap()], + site: 'http://example.com', + output: 'server', + adapter: nodeServer({ + mode: "standalone" + }) +}) diff --git a/packages/integrations/sitemap/test/fixtures/ssr/package.json b/packages/integrations/sitemap/test/fixtures/ssr/package.json new file mode 100644 index 0000000000000..980e02e738989 --- /dev/null +++ b/packages/integrations/sitemap/test/fixtures/ssr/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/sitemap-trailing-slash", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*", + "@astrojs/sitemap": "workspace:*" + } +} diff --git a/packages/integrations/sitemap/test/fixtures/ssr/src/pages/one.astro b/packages/integrations/sitemap/test/fixtures/ssr/src/pages/one.astro new file mode 100644 index 0000000000000..0c7fb90a735e6 --- /dev/null +++ b/packages/integrations/sitemap/test/fixtures/ssr/src/pages/one.astro @@ -0,0 +1,8 @@ + + + One + + +

One

+ + diff --git a/packages/integrations/sitemap/test/fixtures/ssr/src/pages/two.astro b/packages/integrations/sitemap/test/fixtures/ssr/src/pages/two.astro new file mode 100644 index 0000000000000..e7ba9910e2a62 --- /dev/null +++ b/packages/integrations/sitemap/test/fixtures/ssr/src/pages/two.astro @@ -0,0 +1,8 @@ + + + Two + + +

Two

+ + diff --git a/packages/integrations/sitemap/test/ssr.test.js b/packages/integrations/sitemap/test/ssr.test.js new file mode 100644 index 0000000000000..e6f8412d56fcc --- /dev/null +++ b/packages/integrations/sitemap/test/ssr.test.js @@ -0,0 +1,22 @@ +import { loadFixture, readXML } from './test-utils.js'; +import { expect } from 'chai'; + +describe('SSR support', () => { + /** @type {import('./test-utils.js').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/ssr/', + }); + await fixture.build(); + }); + + it('SSR pages require zero config', async () => { + const data = await readXML(fixture.readFile('/client/sitemap-0.xml')); + const urls = data.urlset.url; + + expect(urls[0].loc[0]).to.equal('http://example.com/one/'); + expect(urls[1].loc[0]).to.equal('http://example.com/two/'); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b9e26faca0177..c36f7bf9f69ac 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4490,6 +4490,9 @@ importers: specifier: ^3.17.3 version: 3.20.6 devDependencies: + '@astrojs/node': + specifier: workspace:* + version: link:../node astro: specifier: workspace:* version: link:../../astro @@ -4506,6 +4509,15 @@ importers: specifier: 0.5.0 version: 0.5.0 + packages/integrations/sitemap/test/fixtures/ssr: + dependencies: + '@astrojs/sitemap': + specifier: workspace:* + version: link:../../.. + astro: + specifier: workspace:* + version: link:../../../../../astro + packages/integrations/sitemap/test/fixtures/trailing-slash: dependencies: '@astrojs/sitemap':