diff --git a/test/index.js b/test/index.js index 8df1f5d..363f25d 100644 --- a/test/index.js +++ b/test/index.js @@ -215,10 +215,11 @@ it('No posts', async () => { describe('Rel-Sitemap', () => { const hexo = new Hexo(); hexo.config.sitemap = { - path: 'sitemap.xml', + path: ['sitemap.xml', 'sitemap.txt'], rel: true }; const relSitemap = require('../lib/rel').bind(hexo); + const relPath = hexo.config.sitemap.path.filter(p => { return extname(p) === '.xml'; })[0]; it('default', () => { const content = ''; @@ -226,7 +227,7 @@ describe('Rel-Sitemap', () => { const $ = cheerio.load(result); $('link[rel="sitemap"]').length.should.eql(1); - $('link[rel="sitemap"]').attr('href').should.eql(hexo.config.root + hexo.config.sitemap.path); + $('link[rel="sitemap"]').attr('href').should.eql(hexo.config.root + relPath); result.should.eql(''); }); @@ -237,7 +238,7 @@ describe('Rel-Sitemap', () => { const result = relSitemap(content); const $ = cheerio.load(result); - $('link[rel="sitemap"]').attr('href').should.eql(hexo.config.root + hexo.config.sitemap.path); + $('link[rel="sitemap"]').attr('href').should.eql(hexo.config.root + relPath); result.should.eql(''); hexo.config.root = '/'; @@ -291,6 +292,42 @@ describe('Rel-Sitemap', () => { + ''; result.should.eql(expected); }); + + it('specify relPath', () => { + hexo.config.sitemap.relPath = 'sitemap_specify.xml'; + const content = ''; + const result = relSitemap(content); + + const $ = cheerio.load(result); + $('link[rel="sitemap"]').length.should.eql(1); + $('link[rel="sitemap"]').attr('href').should.eql(hexo.config.root + hexo.config.sitemap.relPath); + + result.should.eql(''); + hexo.config.sitemap.relPath = null; + }); + + it('multiple xml', () => { + hexo.config.sitemap.path = ['sitemap2.xml', 'sitemap.xml', 'sitemap.txt']; + const relPath = hexo.config.sitemap.path.filter(p => { return extname(p) === '.xml'; })[0]; + + const content = ''; + const result = relSitemap(content); + + const $ = cheerio.load(result); + $('link[rel="sitemap"]').length.should.eql(1); + $('link[rel="sitemap"]').attr('href').should.eql(hexo.config.root + relPath); + + result.should.eql(``); + }); + + it('no xml', () => { + hexo.config.sitemap.path = ['sitemap2.txt', 'sitemap.txt']; + const content = ''; + const result = relSitemap(content); + + const resultType = typeof result; + resultType.should.eql('undefined'); + }); }); describe('IDN', () => {