Skip to content

Commit

Permalink
test: Add meta_generator
Browse files Browse the repository at this point in the history
  • Loading branch information
weyusi committed Oct 28, 2018
1 parent 0853115 commit 96595e4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/plugins/filter/meta_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ function hexoMetaGeneratorInject(data) {

if (!($('meta[name="generator"]').length > 0) && $('head').contents().length > 0) {
$('head').prepend(hexoGeneratorTag.replace('%s', this.version));

return $.html();
}

return $.html();
}

module.exports = hexoMetaGeneratorInject;
1 change: 1 addition & 0 deletions test/scripts/filters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('Filters', () => {
require('./excerpt');
require('./external_link');
require('./i18n_locals');
require('./meta_generator');
require('./new_post_path');
require('./post_permalink');
require('./render_post');
Expand Down
28 changes: 28 additions & 0 deletions test/scripts/filters/meta_generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const should = require('chai').should(); // eslint-disable-line

describe('Meta Generator', function() {
const Hexo = require('../../../lib/hexo');
const hexo = new Hexo();
const metaGenerator = require('../../../lib/plugins/filter/meta_generator').bind(hexo);
const cheerio = require('cheerio');

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

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

it('empty <head>', function() {
const content = '<head></head>';
const result = metaGenerator(content);

const $ = cheerio.load(result);
// meta generator should not be prepended if <head> tag is empty
// see https://github.com/hexojs/hexo/pull/3315
$('meta[name="generator"]').length.should.eql(0);
});
});

0 comments on commit 96595e4

Please sign in to comment.