summaryrefslogtreecommitdiff
path: root/packages/integrations/sitemap/test/config.test.js
blob: e4b7c38826e805c5925a5aa1a22646b458def313 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { sitemap } from './fixtures/static/deps.mjs';
import { loadFixture, readXML } from './test-utils.js';

describe('Config', () => {
	/** @type {import('./test-utils.js').Fixture} */
	let fixture;

	describe('Static', () => {
		before(async () => {
			fixture = await loadFixture({
				root: './fixtures/static/',
				integrations: [
					sitemap({
						filter: (page) => page === 'http://example.com/one/',
						xslURL: '/sitemap.xsl',
					}),
				],
			});
			await fixture.build();
		});

		it('filter: Just one page is added', async () => {
			const data = await readXML(fixture.readFile('/sitemap-0.xml'));
			const urls = data.urlset.url;
			assert.equal(urls.length, 1);
		});

		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,
			);
		});
	});

	describe('SSR', () => {
		before(async () => {
			fixture = await loadFixture({
				root: './fixtures/ssr/',
				integrations: [
					sitemap({
						filter: (page) => page === 'http://example.com/one/',
						xslURL: '/sitemap.xsl',
					}),
				],
			});
			await fixture.build();
		});

		it('filter: Just one page is added', async () => {
			const data = await readXML(fixture.readFile('/client/sitemap-0.xml'));
			const urls = data.urlset.url;
			assert.equal(urls.length, 1);
		});

		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,
			);
		});
	});
});