Skip to content

Commit

Permalink
test(idn): should encode url except domain
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Sep 24, 2019
1 parent 237cb63 commit 0a3d41d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require('chai').should();
const Hexo = require('hexo');
const cheerio = require('cheerio');
const { encodeURL } = require('hexo-util');

describe('Sitemap generator', () => {
const hexo = new Hexo(__dirname, {silent: true});
Expand Down Expand Up @@ -68,3 +69,38 @@ describe('Sitemap generator', () => {
});
});
});

describe('IDN', () => {
const hexo = new Hexo(__dirname, {silent: true});
hexo.config.sitemap = {
path: 'sitemap.xml'
};
const Post = hexo.model('Post');
const generator = require('../lib/generator').bind(hexo);
let locals = {};

before(() => {
return hexo.init().then(() => {
return Post.insert([
{source: 'foo', slug: 'foo', updated: 1e8},
{source: 'bar', slug: 'bar', updated: 1e8 + 1},
{source: 'baz', slug: 'baz', updated: 1e8 - 1}
]).then(data => {
locals = hexo.locals.toObject();
});
});
});

it('Default', () => {
hexo.config.url = 'http://fôo.com/bár';
const parsedUrl = encodeURL(hexo.config.url);

const result = generator(locals);
const $ = cheerio.load(result.data);

$('url').each((index, element) => {
$(element).children('loc').text().startsWith(parsedUrl).should.be.true;
});
hexo.config.url = 'http://yoursite.com/';
});
});

0 comments on commit 0a3d41d

Please sign in to comment.