forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsiteFeeds.test.mjs
More file actions
49 lines (42 loc) · 1.39 KB
/
websiteFeeds.test.mjs
File metadata and controls
49 lines (42 loc) · 1.39 KB
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
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import generateWebsiteFeeds from '#site/next-data/generators/websiteFeeds.mjs';
import { BASE_URL, BASE_PATH } from '../../../next.constants.mjs';
import { siteConfig } from '../../../next.json.mjs';
const base = `${BASE_URL}${BASE_PATH}/en`;
describe('generateWebsiteFeeds', () => {
it('generates website feeds with correct data', () => {
const blogData = {
posts: [
{
slug: '/post-1',
title: 'Post 1',
author: 'Author 1',
date: '2025-04-18',
categories: ['all'],
},
],
};
const result = generateWebsiteFeeds(blogData);
assert.equal(result.size, 3);
const blogFeed = result.get('blog.xml');
assert.deepEqual(blogFeed.options, {
id: siteConfig.rssFeeds[0].file,
title: siteConfig.rssFeeds[0].title,
language: 'en',
link: `${base}/feed/${siteConfig.rssFeeds[0].file}`,
description: siteConfig.rssFeeds[0].description,
});
const date = new Date(blogData.posts[0].date);
assert.deepEqual(blogFeed.items, [
{
author: blogData.posts[0].author,
id: blogData.posts[0].slug,
title: blogData.posts[0].title,
guid: `${blogData.posts[0].slug}?${date.getTime()}`,
date: date,
link: `${base}${blogData.posts[0].slug}`,
},
]);
});
});