2024-01-31 17:47:33 +08:00
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { before, describe, it } from 'node:test';
|
2023-06-02 05:07:44 -03:00
|
|
|
import { sitemap } from './fixtures/static/deps.mjs';
|
|
|
|
import { loadFixture, readXML } from './test-utils.js';
|
2024-01-31 10:31:12 +02:00
|
|
|
|
2024-10-03 10:01:42 +02:00
|
|
|
describe('Config', () => {
|
2023-06-02 05:07:44 -03:00
|
|
|
/** @type {import('./test-utils.js').Fixture} */
|
|
|
|
let fixture;
|
|
|
|
|
|
|
|
describe('Static', () => {
|
|
|
|
before(async () => {
|
|
|
|
fixture = await loadFixture({
|
|
|
|
root: './fixtures/static/',
|
2023-06-02 08:10:03 +00:00
|
|
|
integrations: [
|
|
|
|
sitemap({
|
2023-07-14 14:30:33 -05:00
|
|
|
filter: (page) => page === 'http://example.com/one/',
|
2024-10-03 10:01:42 +02:00
|
|
|
xslURL: '/sitemap.xsl',
|
2023-06-02 08:10:03 +00:00
|
|
|
}),
|
|
|
|
],
|
2023-06-02 05:07:44 -03:00
|
|
|
});
|
|
|
|
await fixture.build();
|
|
|
|
});
|
|
|
|
|
2024-10-03 10:01:42 +02:00
|
|
|
it('filter: Just one page is added', async () => {
|
2023-06-02 05:07:44 -03:00
|
|
|
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
|
|
|
|
const urls = data.urlset.url;
|
2024-01-31 17:47:33 +08:00
|
|
|
assert.equal(urls.length, 1);
|
2023-06-02 05:07:44 -03:00
|
|
|
});
|
2024-10-03 10:01:42 +02:00
|
|
|
|
|
|
|
it('xslURL: Includes xml-stylsheet', async () => {
|
|
|
|
const xml = await fixture.readFile('/sitemap-0.xml');
|
|
|
|
assert.ok(
|
|
|
|
xml.includes('<?xml-stylesheet type="text/xsl" href="http://example.com/sitemap.xsl"?>'),
|
|
|
|
xml,
|
|
|
|
);
|
|
|
|
});
|
2023-06-02 05:07:44 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('SSR', () => {
|
|
|
|
before(async () => {
|
|
|
|
fixture = await loadFixture({
|
|
|
|
root: './fixtures/ssr/',
|
2023-06-02 08:10:03 +00:00
|
|
|
integrations: [
|
|
|
|
sitemap({
|
2023-07-14 14:30:33 -05:00
|
|
|
filter: (page) => page === 'http://example.com/one/',
|
2024-10-03 10:01:42 +02:00
|
|
|
xslURL: '/sitemap.xsl',
|
2023-06-02 08:10:03 +00:00
|
|
|
}),
|
|
|
|
],
|
2023-06-02 05:07:44 -03:00
|
|
|
});
|
|
|
|
await fixture.build();
|
|
|
|
});
|
|
|
|
|
2024-10-03 10:01:42 +02:00
|
|
|
it('filter: Just one page is added', async () => {
|
2023-06-02 05:07:44 -03:00
|
|
|
const data = await readXML(fixture.readFile('/client/sitemap-0.xml'));
|
|
|
|
const urls = data.urlset.url;
|
2024-01-31 17:47:33 +08:00
|
|
|
assert.equal(urls.length, 1);
|
2023-06-02 05:07:44 -03:00
|
|
|
});
|
2024-10-03 10:01:42 +02:00
|
|
|
|
|
|
|
it('xslURL: Includes xml-stylsheet', async () => {
|
|
|
|
const xml = await fixture.readFile('/client/sitemap-0.xml');
|
|
|
|
assert.ok(
|
|
|
|
xml.includes('<?xml-stylesheet type="text/xsl" href="http://example.com/sitemap.xsl"?>'),
|
|
|
|
xml,
|
|
|
|
);
|
|
|
|
});
|
2023-06-02 05:07:44 -03:00
|
|
|
});
|
|
|
|
});
|