From 107cb6a76cba00508d0f25125424074ec999cc39 Mon Sep 17 00:00:00 2001 From: latenighthackathon Date: Fri, 3 Apr 2026 00:57:00 -0500 Subject: [PATCH 1/3] test[faustwp-core]: (#1940) add test coverage for sitemapIndexPath option Add three tests to createSitemaps.test.ts verifying sitemapIndexPath behavior in createRootSitemapIndex(): - Fetches from custom sitemapIndexPath when provided - Falls back to default /sitemap.xml when not provided - Trims leading/trailing slashes from sitemapIndexPath Closes #1940 --- .../server/sitemaps/createSitemaps.test.ts | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/packages/faustwp-core/tests/server/sitemaps/createSitemaps.test.ts b/packages/faustwp-core/tests/server/sitemaps/createSitemaps.test.ts index 73b6066b2..9bfa93351 100644 --- a/packages/faustwp-core/tests/server/sitemaps/createSitemaps.test.ts +++ b/packages/faustwp-core/tests/server/sitemaps/createSitemaps.test.ts @@ -242,6 +242,83 @@ describe('createRootSitemapIndex', () => { expect(createSitemapIndexSpy).toHaveBeenCalledWith(expectedSitemaps); }); + + it('fetches from custom sitemapIndexPath when provided', async () => { + const fetchSpy = jest.spyOn(global, 'fetch').mockImplementationOnce((url) => { + // Verify the custom path was used in the fetch URL + expect(url).toBe('http://headless.local/custom-sitemap-index.xml'); + return Promise.resolve({ + ok: true, + status: 200, + text: () => Promise.resolve(validSitemapIndex1RecordXML), + }) as Promise; + }); + + const req = { + url: 'http://localhost:3000/sitemap.xml', + } as NextRequest; + + const config: GetSitemapPropsConfig = { + frontendUrl: 'http://localhost:3000', + sitemapIndexPath: '/custom-sitemap-index.xml', + }; + + await createSitemaps.createRootSitemapIndex(req, config); + + expect(fetchSpy).toHaveBeenCalledWith( + 'http://headless.local/custom-sitemap-index.xml', + ); + }); + + it('fetches from default /sitemap.xml when sitemapIndexPath is not provided', async () => { + const fetchSpy = jest.spyOn(global, 'fetch').mockImplementationOnce(() => { + return Promise.resolve({ + ok: true, + status: 200, + text: () => Promise.resolve(validSitemapIndex1RecordXML), + }) as Promise; + }); + + const req = { + url: 'http://localhost:3000/sitemap.xml', + } as NextRequest; + + const config: GetSitemapPropsConfig = { + frontendUrl: 'http://localhost:3000', + }; + + await createSitemaps.createRootSitemapIndex(req, config); + + expect(fetchSpy).toHaveBeenCalledWith( + 'http://headless.local/sitemap.xml', + ); + }); + + it('trims slashes from sitemapIndexPath', async () => { + const fetchSpy = jest.spyOn(global, 'fetch').mockImplementationOnce(() => { + return Promise.resolve({ + ok: true, + status: 200, + text: () => Promise.resolve(validSitemapIndex1RecordXML), + }) as Promise; + }); + + const req = { + url: 'http://localhost:3000/sitemap.xml', + } as NextRequest; + + const config: GetSitemapPropsConfig = { + frontendUrl: 'http://localhost:3000', + sitemapIndexPath: '/yoast-sitemap.xml/', + }; + + await createSitemaps.createRootSitemapIndex(req, config); + + expect(fetchSpy).toHaveBeenCalledWith( + 'http://headless.local/yoast-sitemap.xml', + ); + }); + }); describe('createPagesSitemap()', () => { From cb09f51c872e7d63e21e28fa34424125d486ea2e Mon Sep 17 00:00:00 2001 From: latenighthackathon Date: Fri, 3 Apr 2026 01:01:13 -0500 Subject: [PATCH 2/3] chore: add changeset for sitemapIndexPath test coverage --- .changeset/sitemap-index-path-tests.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/sitemap-index-path-tests.md diff --git a/.changeset/sitemap-index-path-tests.md b/.changeset/sitemap-index-path-tests.md new file mode 100644 index 000000000..18a4d7d39 --- /dev/null +++ b/.changeset/sitemap-index-path-tests.md @@ -0,0 +1,5 @@ +--- +"@faustwp/core": patch +--- + +test[faustwp-core]: add test coverage for sitemapIndexPath option in createRootSitemapIndex From 33b9148cc5d71ff85f59f62cd5b3b57a078c7f40 Mon Sep 17 00:00:00 2001 From: latenighthackathon Date: Tue, 7 Apr 2026 09:46:56 -0500 Subject: [PATCH 3/3] test[faustwp-core]: prettier formatting --- .../server/sitemaps/createSitemaps.test.ts | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/faustwp-core/tests/server/sitemaps/createSitemaps.test.ts b/packages/faustwp-core/tests/server/sitemaps/createSitemaps.test.ts index 9bfa93351..361e5c4fe 100644 --- a/packages/faustwp-core/tests/server/sitemaps/createSitemaps.test.ts +++ b/packages/faustwp-core/tests/server/sitemaps/createSitemaps.test.ts @@ -244,15 +244,17 @@ describe('createRootSitemapIndex', () => { }); it('fetches from custom sitemapIndexPath when provided', async () => { - const fetchSpy = jest.spyOn(global, 'fetch').mockImplementationOnce((url) => { - // Verify the custom path was used in the fetch URL - expect(url).toBe('http://headless.local/custom-sitemap-index.xml'); - return Promise.resolve({ - ok: true, - status: 200, - text: () => Promise.resolve(validSitemapIndex1RecordXML), - }) as Promise; - }); + const fetchSpy = jest + .spyOn(global, 'fetch') + .mockImplementationOnce((url) => { + // Verify the custom path was used in the fetch URL + expect(url).toBe('http://headless.local/custom-sitemap-index.xml'); + return Promise.resolve({ + ok: true, + status: 200, + text: () => Promise.resolve(validSitemapIndex1RecordXML), + }) as Promise; + }); const req = { url: 'http://localhost:3000/sitemap.xml', @@ -289,9 +291,7 @@ describe('createRootSitemapIndex', () => { await createSitemaps.createRootSitemapIndex(req, config); - expect(fetchSpy).toHaveBeenCalledWith( - 'http://headless.local/sitemap.xml', - ); + expect(fetchSpy).toHaveBeenCalledWith('http://headless.local/sitemap.xml'); }); it('trims slashes from sitemapIndexPath', async () => { @@ -318,7 +318,6 @@ describe('createRootSitemapIndex', () => { 'http://headless.local/yoast-sitemap.xml', ); }); - }); describe('createPagesSitemap()', () => {