Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee committed Apr 18, 2024
1 parent 38229e0 commit 429cf20
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion test/scripts/hexo/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { readFile, mkdirs, unlink, rmdir, writeFile, exists, stat, listDir } fro
import { spy, useFakeTimers } from 'sinon';
import { parse as yfm } from 'hexo-front-matter';
import { expected, content, expected_disable_nunjucks, content_for_issue_3346, expected_for_issue_3346, content_for_issue_4460 } from '../../fixtures/post_render';
import { highlight } from 'hexo-util';
import { highlight, deepMerge } from 'hexo-util';
import Hexo from '../../../lib/hexo';
import chai from 'chai';
const should = chai.should();
Expand Down Expand Up @@ -650,6 +650,43 @@ describe('Post', () => {
await unlink(data.path);
});

// https:// github.com/hexojs/hexo/issues/5155
it('publish() - merge front-matter', async () => {
const prefixTags = ['prefixTag1', 'fooo'];
const customTags = ['customTag', 'fooo'];

await hexo.scaffold.set('customscaff', [
'---',
'title: {{ title }}',
'date: {{ date }}',
`tags: ${JSON.stringify(prefixTags)}`,
'qwe: 123',
'zxc: zxc',
'---'
].join('\n'));

const path = join(hexo.source_dir, '_posts', 'fooo.md');
const data = await post.create({
title: 'fooo',
layout: 'draft',
tags: customTags,
qwe: 456,
asd: 'asd'
});
const result = await post.publish({
slug: 'fooo',
layout: 'customscaff'
});

const fmt = yfm(result.content);
fmt.tags.sort().should.eql(deepMerge(prefixTags, customTags).sort());
fmt.qwe.should.eql(456);
fmt.asd.should.eql('asd');
fmt.zxc.should.eql('zxc');

await unlink(path);
});

it('render()', async () => {
// TODO: validate data
const beforeHook = spy();
Expand Down

0 comments on commit 429cf20

Please sign in to comment.