mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
9b78c99275
* Add option to prefix sitemap * Fix call resolve twice * let to const * Apply suggestions from code review Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> * change changeset patch to minor * use node:test * Update changeset * Add regex validation for prefix * Update .changeset/eighty-falcons-tease.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update prefix regex in SitemapOptionsSchema --------- Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
72 lines
2.2 KiB
JavaScript
72 lines
2.2 KiB
JavaScript
import { loadFixture, readXML } from './test-utils.js';
|
|
import { sitemap } from './fixtures/static/deps.mjs';
|
|
import assert from 'node:assert/strict';
|
|
import { before, describe, it } from 'node:test';
|
|
|
|
describe('Prefix support', () => {
|
|
/** @type {import('./test-utils.js').Fixture} */
|
|
let fixture;
|
|
const prefix = 'test-';
|
|
|
|
describe('Static', () => {
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
root: './fixtures/static/',
|
|
integrations: [
|
|
sitemap(),
|
|
sitemap({
|
|
prefix,
|
|
}),
|
|
],
|
|
});
|
|
await fixture.build();
|
|
});
|
|
|
|
it('Content is same', async () => {
|
|
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
|
|
const prefixData = await readXML(fixture.readFile(`/${prefix}0.xml`));
|
|
assert.deepEqual(prefixData, data);
|
|
});
|
|
|
|
it('Index file load correct sitemap', async () => {
|
|
const data = await readXML(fixture.readFile('/sitemap-index.xml'));
|
|
const sitemapUrl = data.sitemapindex.sitemap[0].loc[0];
|
|
assert.strictEqual(sitemapUrl, 'http://example.com/sitemap-0.xml');
|
|
|
|
const prefixData = await readXML(fixture.readFile(`/${prefix}index.xml`));
|
|
const prefixSitemapUrl = prefixData.sitemapindex.sitemap[0].loc[0];
|
|
assert.strictEqual(prefixSitemapUrl, `http://example.com/${prefix}0.xml`);
|
|
});
|
|
});
|
|
|
|
describe('SSR', () => {
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
root: './fixtures/ssr/',
|
|
integrations: [
|
|
sitemap(),
|
|
sitemap({
|
|
prefix,
|
|
}),
|
|
],
|
|
});
|
|
await fixture.build();
|
|
});
|
|
|
|
it('Content is same', async () => {
|
|
const data = await readXML(fixture.readFile('/client/sitemap-0.xml'));
|
|
const prefixData = await readXML(fixture.readFile(`/client/${prefix}0.xml`));
|
|
assert.deepEqual(prefixData, data);
|
|
});
|
|
|
|
it('Index file load correct sitemap', async () => {
|
|
const data = await readXML(fixture.readFile('/client/sitemap-index.xml'));
|
|
const sitemapUrl = data.sitemapindex.sitemap[0].loc[0];
|
|
assert.strictEqual(sitemapUrl, 'http://example.com/sitemap-0.xml');
|
|
|
|
const prefixData = await readXML(fixture.readFile(`/client/${prefix}index.xml`));
|
|
const prefixSitemapUrl = prefixData.sitemapindex.sitemap[0].loc[0];
|
|
assert.strictEqual(prefixSitemapUrl, `http://example.com/${prefix}0.xml`);
|
|
});
|
|
});
|
|
});
|