Skip to content

Commit 77f3e21

Browse files
authored
Merge pull request #3829 from curbengh/hexo-util_1.5
test: compatibility with [email protected]
2 parents 878cf1b + ef0a966 commit 77f3e21

File tree

7 files changed

+22
-13
lines changed

7 files changed

+22
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"hexo-fs": "^2.0.0",
4646
"hexo-i18n": "^1.0.0",
4747
"hexo-log": "^1.0.0",
48-
"hexo-util": "^1.4.0",
48+
"hexo-util": "^1.5.0",
4949
"js-yaml": "^3.12.0",
5050
"lodash": "^4.17.11",
5151
"micromatch": "^4.0.2",

test/scripts/helpers/open_graph.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const moment = require('moment');
44
const cheerio = require('cheerio');
5+
const { encodeURL } = require('hexo-util');
56

67
describe('open_graph', () => {
78
const Hexo = require('../../../lib/hexo');
@@ -141,7 +142,7 @@ describe('open_graph', () => {
141142

142143
const result = openGraph.call(ctx);
143144

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

147148
it('images - content', () => {

test/scripts/hexo/hexo.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const Promise = require('bluebird');
66
const sinon = require('sinon');
77
const sep = pathFn.sep;
88
const testUtil = require('../../util');
9+
const { full_url_for } = require('hexo-util');
910

1011
describe('Hexo', () => {
1112
const base_dir = pathFn.join(__dirname, 'hexo_test');
@@ -427,17 +428,18 @@ describe('Hexo', () => {
427428
});
428429

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

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

434436
hexo.extend.generator.register('test', () => ({
435-
path: 'bár',
437+
path,
436438
layout: 'test'
437439
}));
438440

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

443445
it('_generate() - do nothing if it\'s generating', () => {

test/scripts/models/category.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const sinon = require('sinon');
44
const Promise = require('bluebird');
5+
const { full_url_for } = require('hexo-util');
56

67
describe('Category', () => {
78
const Hexo = require('../../../lib/hexo');
@@ -118,9 +119,9 @@ describe('Category', () => {
118119
it('permalink - should be encoded', () => {
119120
hexo.config.url = 'http://fôo.com';
120121
return Category.insert({
121-
name: 'bár'
122+
name: ''
122123
}).then(data => {
123-
data.permalink.should.eql('http://xn--fo-8ja.com/' + data.path);
124+
data.permalink.should.eql(full_url_for.call(hexo, data.path));
124125
hexo.config.url = 'http://yoursite.com';
125126
return Category.removeById(data._id);
126127
});

test/scripts/models/page.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const sinon = require('sinon');
44
const pathFn = require('path');
5+
const { full_url_for } = require('hexo-util');
56

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

7576
it('permalink - should be encoded', () => {
7677
hexo.config.url = 'http://fôo.com';
78+
const path = 'bár';
7779
return Page.insert({
7880
source: 'foo',
79-
path: 'bár'
81+
path
8082
}).then(data => {
81-
data.permalink.should.eql('http://xn--fo-8ja.com/b%C3%A1r');
83+
data.permalink.should.eql(full_url_for.call(hexo, data.path));
8284
hexo.config.url = 'http://yoursite.com';
8385
return Page.removeById(data._id);
8486
});

test/scripts/models/post.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const sinon = require('sinon');
44
const pathFn = require('path');
55
const Promise = require('bluebird');
6+
const { full_url_for } = require('hexo-util');
67

78
describe('Post', () => {
89
const Hexo = require('../../../lib/hexo');
@@ -85,12 +86,13 @@ describe('Post', () => {
8586
});
8687

8788
it('permalink - should be encoded', () => {
89+
const slug = 'bár';
8890
hexo.config.url = 'http://fôo.com';
8991
return Post.insert({
9092
source: 'foo.md',
91-
slug: 'bár'
93+
slug
9294
}).then(data => {
93-
data.permalink.should.eql('http://xn--fo-8ja.com/b%C3%A1r');
95+
data.permalink.should.eql(full_url_for.call(hexo, slug));
9496
hexo.config.url = 'http://yoursite.com';
9597
return Post.removeById(data._id);
9698
});

test/scripts/models/tag.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const sinon = require('sinon');
44
const Promise = require('bluebird');
5+
const { full_url_for } = require('hexo-util');
56

67
describe('Tag', () => {
78
const Hexo = require('../../../lib/hexo');
@@ -103,9 +104,9 @@ describe('Tag', () => {
103104
it('permalink - should be encoded', () => {
104105
hexo.config.url = 'http://fôo.com';
105106
return Tag.insert({
106-
name: 'bár'
107+
name: ''
107108
}).then(data => {
108-
data.permalink.should.eql('http://xn--fo-8ja.com/' + data.path);
109+
data.permalink.should.eql(full_url_for.call(hexo, data.path));
109110
hexo.config.url = 'http://yoursite.com';
110111
return Tag.removeById(data._id);
111112
});

0 commit comments

Comments
 (0)