-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid stripping query params from entries
Fixes #92
- Loading branch information
Showing
3 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { createResolver } from '@nuxt/kit' | ||
import { $fetch, setup } from '@nuxt/test-utils' | ||
|
||
const { resolve } = createResolver(import.meta.url) | ||
|
||
await setup({ | ||
rootDir: resolve('../.playground'), | ||
build: true, | ||
server: true, | ||
nuxtConfig: { | ||
sitemap: { | ||
urls: [ | ||
'/', | ||
'/query-no-slash?foo=bar', | ||
'/query-slash/?foo=bar', | ||
'/query-slash-hash/?foo=bar#hash', | ||
], | ||
autoLastmod: false, | ||
sitemaps: false, | ||
}, | ||
}, | ||
}) | ||
describe('query routes', () => { | ||
it('basic', async () => { | ||
const sitemap = await $fetch('/sitemap.xml') | ||
|
||
expect(sitemap).toContain('<loc>https://nuxtseo.com/query-no-slash?foo=bar</loc>') | ||
expect(sitemap).toContain('<loc>https://nuxtseo.com/query-slash?foo=bar</loc>') | ||
expect(sitemap).toContain('<loc>https://nuxtseo.com/query-slash-hash?foo=bar#hash</loc>') | ||
}, 60000) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { fixSlashes } from 'site-config-stack' | ||
import { normaliseSitemapData } from '../../src/runtime/sitemap/entries' | ||
import type { BuildSitemapInput } from '../../src/runtime/types' | ||
|
||
const normaliseOptions: BuildSitemapInput = { | ||
// @ts-expect-error test hack | ||
moduleConfig: {}, | ||
// @ts-expect-error test hack | ||
buildTimeMeta: {}, | ||
getRouteRulesForPath: () => ({}), | ||
canonicalUrlResolver: (path: string) => fixSlashes(true, path), | ||
nitroUrlResolver: (path: string) => path, | ||
relativeBaseUrlResolver: (path: string) => path, | ||
pages: [], | ||
urls: [], | ||
} | ||
describe('normalise', () => { | ||
it('query', async () => { | ||
const normalisedWithoutSlash = await normaliseSitemapData([ | ||
{ loc: '/query?foo=bar' }, | ||
], normaliseOptions) | ||
expect(normalisedWithoutSlash).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"loc": "/query/?foo=bar", | ||
}, | ||
] | ||
`) | ||
const normalisedWithSlash = await normaliseSitemapData([ | ||
{ loc: '/query/?foo=bar' }, | ||
], normaliseOptions) | ||
expect(normalisedWithSlash).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"loc": "/query/?foo=bar", | ||
}, | ||
] | ||
`) | ||
}) | ||
}) |