Skip to content

Commit

Permalink
test(meta_generator): update test cases
Browse files Browse the repository at this point in the history
Apply suggestions from code review by @curbengh:

- update other test cases as the filter no longer seeks <title>
- seperate 'apply to first non-empty head tag only' from 'ignore empty head tag'
  • Loading branch information
SukkaW committed Sep 1, 2019
1 parent a71cea2 commit ce86ca9
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions test/scripts/filters/meta_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Meta Generator', () => {
const cheerio = require('cheerio');

it('default', () => {
const content = '<head><title>foo</title></head>';
const content = '<head><link></head>';
const result = metaGenerator(content);

const $ = cheerio.load(result);
Expand All @@ -16,7 +16,7 @@ describe('Meta Generator', () => {
});

it('disable meta_generator', () => {
const content = '<head><title>foo</title></head>';
const content = '<head><link></head>';
hexo.config.meta_generator = false;
const result = metaGenerator(content);

Expand All @@ -25,7 +25,7 @@ describe('Meta Generator', () => {
});

it('no duplicate generator tag', () => {
const content = '<head><title>foo</title>'
const content = '<head><link>'
+ '<meta name="generator" content="foo"></head>';
hexo.config.meta_generator = true;
const result = metaGenerator(content);
Expand All @@ -36,7 +36,6 @@ describe('Meta Generator', () => {

it('ignore empty head tag', () => {
const content = '<head></head>'
+ '<head><link></head>'
+ '<head><link></head>'
+ '<head></head>';
hexo.config.meta_generator = true;
Expand All @@ -47,8 +46,23 @@ describe('Meta Generator', () => {

const expected = '<head></head>'
+ '<head><link><meta name="generator" content="Hexo ' + hexo.version + '"></head>'
+ '<head><link></head>'
+ '<head></head>';
result.should.eql(expected);
});

it('apply to first non-empty head tag only', () => {
const content = '<head></head>'
+ '<head><link></head>'
+ '<head><link></head>';
hexo.config.meta_generator = true;
const result = metaGenerator(content);

const $ = cheerio.load(result);
$('meta[name="generator"]').length.should.eql(1);

const expected = '<head></head>'
+ '<head><link><meta name="generator" content="Hexo ' + hexo.version + '"></head>'
+ '<head><link></head>';
result.should.eql(expected);
});
});

0 comments on commit ce86ca9

Please sign in to comment.