2021-04-23 16:44:41 +00:00
|
|
|
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);
|
|
|
|
|
2021-04-26 21:54:20 +00:00
|
|
|
const clear = () => del(path.join(fileURLToPath(cwd), 'dist')); // clear dist output
|
2021-04-23 16:44:41 +00:00
|
|
|
|
|
|
|
Sitemap.before(() => clear());
|
|
|
|
Sitemap.after(() => clear());
|
|
|
|
|
|
|
|
Sitemap('Generates Sitemap correctly', async () => {
|
|
|
|
execSync('node ../../../astro.mjs build', { cwd: fileURLToPath(cwd) });
|
2021-04-26 21:54:20 +00:00
|
|
|
const rss = await fs.promises.readFile(path.join(fileURLToPath(cwd), 'dist', 'sitemap.xml'), 'utf8');
|
2021-04-23 16:44:41 +00:00
|
|
|
assert.match(rss, snapshot);
|
|
|
|
});
|
|
|
|
|
|
|
|
Sitemap.run();
|