Skip to content

Commit f455c95

Browse files
test: increase coverage
t#
1 parent a7d26fa commit f455c95

File tree

1 file changed

+82
-4
lines changed

1 file changed

+82
-4
lines changed

test/index.js

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,24 @@ describe('Feed generator', () => {
3535
{source: 'bar', slug: 'bar', date: 1e8 + 1},
3636
{source: 'baz', slug: 'baz', title: 'With Image', image: 'test.png', date: 1e8 - 1},
3737
{source: 'date', slug: 'date', title: 'date', date: 1e8 - 2, updated: undefined},
38-
{source: 'updated', slug: 'updated', title: 'updated', date: 1e8 - 2, updated: 1e8 + 10}
38+
{source: 'updated', slug: 'updated', title: 'updated', date: 1e8 - 2, updated: 1e8 + 10},
39+
{source: 'description', slug: 'description', title: 'description', description: '<h6>description</h6>', date: 1e8},
40+
{source: 'intro', slug: 'intro', title: 'intro', intro: '<h6>intro</h6>', date: 1e8},
41+
{source: 'excerpt', slug: 'excerpt', title: 'excerpt', excerpt: '<h6>excerpt</h6>', date: 1e8},
42+
{
43+
source: 'delim-test',
44+
slug: 'delim-test',
45+
title: 'Delimiter Test',
46+
content: 'This is the beginning.<!-- more -->This is after delimiter.',
47+
date: 1e8
48+
},
49+
{
50+
source: 'no-delim-test',
51+
slug: 'no-delim-test',
52+
title: 'No Delimiter Test',
53+
content: 'This content has no delimiter and should be truncated at content_limit.',
54+
date: 1e8
55+
}
3956
]);
4057
locals = hexo.locals.toObject();
4158
});
@@ -123,7 +140,7 @@ describe('Feed generator', () => {
123140

124141
// Verify all articles are shown when no limit is set
125142
const atom = await p(result.data);
126-
atom.items.should.have.length(5); // All articles
143+
atom.items.should.have.length(Post.length); // All articles
127144
});
128145

129146
it('Preserves HTML in the content field - atom', async () => {
@@ -276,8 +293,7 @@ describe('Feed generator', () => {
276293
it('Image should have full link', async () => {
277294
hexo.config.feed = {
278295
type: 'atom',
279-
path: 'atom.xml',
280-
limit: 3
296+
path: 'atom.xml'
281297
};
282298
hexo.config = Object.assign(hexo.config, urlConfig);
283299
const feedCfg = hexo.config.feed;
@@ -419,6 +435,68 @@ describe('Feed generator', () => {
419435
updated.should.eql(expected);
420436
date.should.not.eql(updated);
421437
});
438+
439+
it('Support description, intro and excerpt', async () => {
440+
hexo.config.feed = {
441+
type: 'atom',
442+
path: 'atom.xml'
443+
};
444+
hexo.config = Object.assign(hexo.config, urlConfig);
445+
const feedCfg = hexo.config.feed;
446+
const result = generator(locals, feedCfg.type, feedCfg.path);
447+
448+
const { items } = await p(result.data);
449+
for (const key of ['description', 'intro', 'excerpt']) {
450+
const post = items.filter(({ title }) => title === key);
451+
post.length.should.eql(1, `Post with title "${key}" should exist`);
452+
const { description } = post[0];
453+
const expected = `<h6>${key}</h6>`;
454+
455+
description.should.eql(expected);
456+
}
457+
});
458+
459+
it('content_limit_delim - delimiter found', async () => {
460+
hexo.config.feed = {
461+
type: 'atom',
462+
path: 'atom.xml',
463+
content_limit: 100,
464+
content_limit_delim: '<!-- more -->'
465+
};
466+
hexo.config = Object.assign(hexo.config, urlConfig);
467+
const feedCfg = hexo.config.feed;
468+
const updatedLocals = hexo.locals.toObject();
469+
const result = generator(updatedLocals, feedCfg.type, feedCfg.path);
470+
471+
const { items } = await p(result.data);
472+
const post = items.filter(({ title }) => title === 'Delimiter Test');
473+
post.length.should.eql(1);
474+
const { description } = post[0];
475+
476+
// Should only include content before the delimiter
477+
description.should.eql('This is the beginning.');
478+
});
479+
480+
it('content_limit_delim - delimiter not found', async () => {
481+
hexo.config.feed = {
482+
type: 'atom',
483+
path: 'atom.xml',
484+
content_limit: 29,
485+
content_limit_delim: '<!-- more -->'
486+
};
487+
hexo.config = Object.assign(hexo.config, urlConfig);
488+
const feedCfg = hexo.config.feed;
489+
const updatedLocals = hexo.locals.toObject();
490+
const result = generator(updatedLocals, feedCfg.type, feedCfg.path);
491+
492+
const { items } = await p(result.data);
493+
const post = items.filter(({ title }) => title === 'No Delimiter Test');
494+
post.length.should.eql(1);
495+
const { description } = post[0];
496+
497+
// Should be truncated at content_limit since delimiter not found
498+
description.should.eql('This content has no delimiter');
499+
});
422500
});
423501

424502
it('No posts', () => {

0 commit comments

Comments
 (0)