0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00
astro/packages/integrations/sitemap/test/config.test.js

68 lines
1.7 KiB
JavaScript
Raw Normal View History

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';
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({
filter: (page) => page === 'http://example.com/one/',
xslURL: '/sitemap.xsl',
2023-06-02 08:10:03 +00:00
}),
],
2023-06-02 05:07:44 -03:00
});
await fixture.build();
});
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;
assert.equal(urls.length, 1);
2023-06-02 05:07:44 -03: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({
filter: (page) => page === 'http://example.com/one/',
xslURL: '/sitemap.xsl',
2023-06-02 08:10:03 +00:00
}),
],
2023-06-02 05:07:44 -03:00
});
await fixture.build();
});
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;
assert.equal(urls.length, 1);
2023-06-02 05:07:44 -03: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
});
});