Skip to content

Commit

Permalink
Merge pull request #3829 from curbengh/hexo-util_1.5
Browse files Browse the repository at this point in the history
test: compatibility with [email protected]
  • Loading branch information
curbengh authored Nov 5, 2019
2 parents 878cf1b + ef0a966 commit 77f3e21
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"hexo-fs": "^2.0.0",
"hexo-i18n": "^1.0.0",
"hexo-log": "^1.0.0",
"hexo-util": "^1.4.0",
"hexo-util": "^1.5.0",
"js-yaml": "^3.12.0",
"lodash": "^4.17.11",
"micromatch": "^4.0.2",
Expand Down
3 changes: 2 additions & 1 deletion test/scripts/helpers/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const moment = require('moment');
const cheerio = require('cheerio');
const { encodeURL } = require('hexo-util');

describe('open_graph', () => {
const Hexo = require('../../../lib/hexo');
Expand Down Expand Up @@ -141,7 +142,7 @@ describe('open_graph', () => {

const result = openGraph.call(ctx);

result.should.contain(meta({property: 'og:url', content: 'https://xn--fo-9ja.com/b%C3%A1r'}));
result.should.contain(meta({property: 'og:url', content: encodeURL(ctx.url)}));
});

it('images - content', () => {
Expand Down
8 changes: 5 additions & 3 deletions test/scripts/hexo/hexo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Promise = require('bluebird');
const sinon = require('sinon');
const sep = pathFn.sep;
const testUtil = require('../../util');
const { full_url_for } = require('hexo-util');

describe('Hexo', () => {
const base_dir = pathFn.join(__dirname, 'hexo_test');
Expand Down Expand Up @@ -427,17 +428,18 @@ describe('Hexo', () => {
});

it('_generate() - should encode url', () => {
const path = 'bár';
hexo.config.url = 'http://fôo.com';

hexo.theme.setView('test.swig', '{{ url }}');

hexo.extend.generator.register('test', () => ({
path: 'bár',
path,
layout: 'test'
}));

return hexo._generate().then(() => checkStream(route.get('bár'),
'http://xn--fo-8ja.com/b%C3%A1r'));
return hexo._generate().then(() => checkStream(route.get(path),
full_url_for.call(hexo, path)));
});

it('_generate() - do nothing if it\'s generating', () => {
Expand Down
5 changes: 3 additions & 2 deletions test/scripts/models/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const sinon = require('sinon');
const Promise = require('bluebird');
const { full_url_for } = require('hexo-util');

describe('Category', () => {
const Hexo = require('../../../lib/hexo');
Expand Down Expand Up @@ -118,9 +119,9 @@ describe('Category', () => {
it('permalink - should be encoded', () => {
hexo.config.url = 'http://fôo.com';
return Category.insert({
name: 'bár'
name: ''
}).then(data => {
data.permalink.should.eql('http://xn--fo-8ja.com/' + data.path);
data.permalink.should.eql(full_url_for.call(hexo, data.path));
hexo.config.url = 'http://yoursite.com';
return Category.removeById(data._id);
});
Expand Down
6 changes: 4 additions & 2 deletions test/scripts/models/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const sinon = require('sinon');
const pathFn = require('path');
const { full_url_for } = require('hexo-util');

describe('Page', () => {
const Hexo = require('../../../lib/hexo');
Expand Down Expand Up @@ -74,11 +75,12 @@ describe('Page', () => {

it('permalink - should be encoded', () => {
hexo.config.url = 'http://fôo.com';
const path = 'bár';
return Page.insert({
source: 'foo',
path: 'bár'
path
}).then(data => {
data.permalink.should.eql('http://xn--fo-8ja.com/b%C3%A1r');
data.permalink.should.eql(full_url_for.call(hexo, data.path));
hexo.config.url = 'http://yoursite.com';
return Page.removeById(data._id);
});
Expand Down
6 changes: 4 additions & 2 deletions test/scripts/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const sinon = require('sinon');
const pathFn = require('path');
const Promise = require('bluebird');
const { full_url_for } = require('hexo-util');

describe('Post', () => {
const Hexo = require('../../../lib/hexo');
Expand Down Expand Up @@ -85,12 +86,13 @@ describe('Post', () => {
});

it('permalink - should be encoded', () => {
const slug = 'bár';
hexo.config.url = 'http://fôo.com';
return Post.insert({
source: 'foo.md',
slug: 'bár'
slug
}).then(data => {
data.permalink.should.eql('http://xn--fo-8ja.com/b%C3%A1r');
data.permalink.should.eql(full_url_for.call(hexo, slug));
hexo.config.url = 'http://yoursite.com';
return Post.removeById(data._id);
});
Expand Down
5 changes: 3 additions & 2 deletions test/scripts/models/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const sinon = require('sinon');
const Promise = require('bluebird');
const { full_url_for } = require('hexo-util');

describe('Tag', () => {
const Hexo = require('../../../lib/hexo');
Expand Down Expand Up @@ -103,9 +104,9 @@ describe('Tag', () => {
it('permalink - should be encoded', () => {
hexo.config.url = 'http://fôo.com';
return Tag.insert({
name: 'bár'
name: ''
}).then(data => {
data.permalink.should.eql('http://xn--fo-8ja.com/' + data.path);
data.permalink.should.eql(full_url_for.call(hexo, data.path));
hexo.config.url = 'http://yoursite.com';
return Tag.removeById(data._id);
});
Expand Down

0 comments on commit 77f3e21

Please sign in to comment.