0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00
astro/test/astro-sitemap.test.js
2021-04-23 10:44:41 -06:00

26 lines
1.1 KiB
JavaScript

import { suite } from 'uvu';
import * as assert from 'uvu/assert';
import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
import del from 'del';
import { fileURLToPath } from 'url';
const Sitemap = suite('Sitemap Generation');
const snapshot = `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://mysite.dev/episode/fazers/</loc></url><url><loc>https://mysite.dev/episode/rap-snitch-knishes/</loc></url><url><loc>https://mysite.dev/episode/rhymes-like-dimes/</loc></url><url><loc>https://mysite.dev/episodes/</loc></url></urlset>`;
const cwd = new URL('./fixtures/astro-rss', import.meta.url);
const clear = () => del(path.join(fileURLToPath(cwd), '_site')); // clear _site output
Sitemap.before(() => clear());
Sitemap.after(() => clear());
Sitemap('Generates Sitemap correctly', async () => {
execSync('node ../../../astro.mjs build', { cwd: fileURLToPath(cwd) });
const rss = await fs.promises.readFile(path.join(fileURLToPath(cwd), '_site', 'sitemap.xml'), 'utf8');
assert.match(rss, snapshot);
});
Sitemap.run();