diff --git a/test/index.js b/test/index.js index 316788f..93fc288 100644 --- a/test/index.js +++ b/test/index.js @@ -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}); @@ -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/'; + }); +});