Skip to content

Commit 461fa1c

Browse files
committed
import from upstream/master
1 parent 10a8086 commit 461fa1c

File tree

10 files changed

+46
-42
lines changed

10 files changed

+46
-42
lines changed

test/fixtures/.eslintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "hexo/ts",
3+
"rules": {
4+
"node/no-unsupported-features/es-syntax": 0
5+
}
6+
}

test/fixtures/post_render.js renamed to test/fixtures/post_render.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
'use strict';
2-
3-
const { highlight } = require('hexo-util');
1+
import { highlight } from 'hexo-util';
42

53
const code = [
64
'if tired && night:',
75
' sleep()'
86
].join('\n');
97

10-
exports.content = [
8+
export const content = [
119
'# Title',
1210
'``` python',
1311
code,
@@ -24,7 +22,7 @@ exports.content = [
2422
'{% endquote %}'
2523
].join('\n');
2624

27-
exports.expected = [
25+
export const expected = [
2826
'<h1 id="Title"><a href="#Title" class="headerlink" title="Title"></a>Title</h1>',
2927
highlight(code, {lang: 'python'}),
3028
'\n<p>some content</p>\n',
@@ -36,7 +34,7 @@ exports.expected = [
3634
'<footer><strong>Hello World</strong></footer></blockquote>'
3735
].join('');
3836

39-
exports.expected_disable_nunjucks = [
37+
export const expected_disable_nunjucks = [
4038
'<h1 id="Title"><a href="#Title" class="headerlink" title="Title"></a>Title</h1>',
4139
highlight(code, {lang: 'python'}),
4240
'\n<p>some content</p>\n',
@@ -49,7 +47,7 @@ exports.expected_disable_nunjucks = [
4947
'{% endquote %}</p>'
5048
].join('');
5149

52-
exports.content_for_issue_3346 = [
50+
export const content_for_issue_3346 = [
5351
'# Title',
5452
'```',
5553
'{% test1 %}',
@@ -63,7 +61,7 @@ exports.content_for_issue_3346 = [
6361
'{% endblockquote %}'
6462
].join('\n');
6563

66-
exports.expected_for_issue_3346 = [
64+
export const expected_for_issue_3346 = [
6765
'<h1 id="Title"><a href="#Title" class="headerlink" title="Title"></a>Title</h1>',
6866
highlight('{% test1 %}\n{{ test2 }}').replace(/{/g, '&#123;').replace(/}/g, '&#125;'), // Escaped by backtick_code_block
6967
'\n<p>some content</p>\n',
@@ -73,7 +71,7 @@ exports.expected_for_issue_3346 = [
7371
'</blockquote>'
7472
].join('');
7573

76-
exports.content_for_issue_4460 = [
74+
export const content_for_issue_4460 = [
7775
'```html',
7876
'<body>',
7977
'<!-- here goes the rest of the page -->',

test/scripts/generators/asset.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join } from 'path';
22
import { mkdirs, rmdir, unlink, writeFile } from 'hexo-fs';
3-
import testUtil from '../../util';
3+
import { readStream } from '../../util';
44
import Hexo from '../../../lib/hexo';
55
import assetGenerator from '../../../lib/plugins/generator/asset';
66
import { spy } from 'sinon';
@@ -15,7 +15,7 @@ describe('asset', () => {
1515
const Asset = hexo.model('Asset');
1616

1717
const checkStream = async (stream, expected) => {
18-
const data = await testUtil.stream.read(stream);
18+
const data = await readStream(stream);
1919
data.should.eql(expected);
2020
};
2121

test/scripts/hexo/hexo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { mkdirs, rmdir, unlink, writeFile } from 'hexo-fs';
33
// @ts-ignore
44
import Promise from 'bluebird';
55
import { spy } from 'sinon';
6-
import testUtil from '../../util';
6+
import { readStream } from '../../util';
77
import { full_url_for } from 'hexo-util';
88
import Hexo from '../../../lib/hexo';
99
import chai from 'chai';
@@ -20,7 +20,7 @@ describe('Hexo', () => {
2020
const { route } = hexo;
2121

2222
async function checkStream(stream, expected) {
23-
const data = await testUtil.stream.read(stream);
23+
const data = await readStream(stream);
2424
data.should.eql(expected);
2525
}
2626

test/scripts/hexo/post.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import moment from 'moment';
33
import { readFile, mkdirs, unlink, rmdir, writeFile, exists, stat, listDir } from 'hexo-fs';
44
import { spy, useFakeTimers } from 'sinon';
55
import { parse as yfm } from 'hexo-front-matter';
6-
import fixture from '../../fixtures/post_render';
6+
import { expected, content, expected_disable_nunjucks, content_for_issue_3346, expected_for_issue_3346, content_for_issue_4460 } from '../../fixtures/post_render';
77
import { highlight } from 'hexo-util';
88
import Hexo from '../../../lib/hexo';
99
import chai from 'chai';
@@ -659,17 +659,17 @@ describe('Post', () => {
659659
hexo.extend.filter.register('after_post_render', afterHook);
660660

661661
const data = await post.render('', {
662-
content: fixture.content,
662+
content,
663663
engine: 'markdown'
664664
});
665-
data.content.trim().should.eql(fixture.expected);
665+
data.content.trim().should.eql(expected);
666666
beforeHook.calledOnce.should.be.true;
667667
afterHook.calledOnce.should.be.true;
668668
});
669669

670670
it('render() - callback', done => {
671671
post.render('', {
672-
content: fixture.content,
672+
content,
673673
engine: 'markdown'
674674
}, err => {
675675
done(err);
@@ -795,10 +795,10 @@ describe('Post', () => {
795795

796796
try {
797797
const data = await post.render('', {
798-
content: fixture.content,
798+
content,
799799
engine: 'markdown'
800800
});
801-
data.content.trim().should.eql(fixture.expected_disable_nunjucks);
801+
data.content.trim().should.eql(expected_disable_nunjucks);
802802
} finally {
803803
renderer.disableNunjucks = false;
804804
}
@@ -811,10 +811,10 @@ describe('Post', () => {
811811

812812
try {
813813
const data = await post.render('', {
814-
content: fixture.content,
814+
content,
815815
engine: 'markdown'
816816
});
817-
data.content.trim().should.eql(fixture.expected);
817+
data.content.trim().should.eql(expected);
818818
} finally {
819819
renderer.disableNunjucks = false;
820820
}
@@ -848,11 +848,11 @@ describe('Post', () => {
848848

849849
try {
850850
const data = await post.render('', {
851-
content: fixture.content,
851+
content,
852852
engine: 'markdown',
853853
disableNunjucks: false
854854
});
855-
data.content.trim().should.eql(fixture.expected);
855+
data.content.trim().should.eql(expected);
856856
} finally {
857857
renderer.disableNunjucks = false;
858858
}
@@ -864,11 +864,11 @@ describe('Post', () => {
864864

865865
try {
866866
const data = await post.render('', {
867-
content: fixture.content,
867+
content,
868868
engine: 'markdown',
869869
disableNunjucks: true
870870
});
871-
data.content.trim().should.eql(fixture.expected_disable_nunjucks);
871+
data.content.trim().should.eql(expected_disable_nunjucks);
872872
} finally {
873873
renderer.disableNunjucks = false;
874874
}
@@ -881,12 +881,12 @@ describe('Post', () => {
881881

882882
try {
883883
const data = await post.render('', {
884-
content: fixture.content,
884+
content,
885885
engine: 'markdown',
886886
// @ts-ignore
887887
disableNunjucks: null
888888
});
889-
data.content.trim().should.eql(fixture.expected_disable_nunjucks);
889+
data.content.trim().should.eql(expected_disable_nunjucks);
890890
} finally {
891891
renderer.disableNunjucks = false;
892892
}
@@ -1155,14 +1155,14 @@ describe('Post', () => {
11551155

11561156
// #3346
11571157
it('render() - swig tag inside backtick code block', async () => {
1158-
const content = fixture.content_for_issue_3346;
1158+
const content = content_for_issue_3346;
11591159

11601160
const data = await post.render('', {
11611161
content,
11621162
engine: 'markdown'
11631163
});
11641164

1165-
data.content.trim().should.eql(fixture.expected_for_issue_3346);
1165+
data.content.trim().should.eql(expected_for_issue_3346);
11661166
});
11671167

11681168
// test for https://github.com/hexojs/hexo/pull/4171#issuecomment-594412367
@@ -1343,7 +1343,7 @@ describe('Post', () => {
13431343
it('render() - issue #4460', async () => {
13441344
hexo.config.syntax_highlighter = 'prismjs';
13451345

1346-
const content = fixture.content_for_issue_4460;
1346+
const content = content_for_issue_4460;
13471347

13481348
const data = await post.render('', {
13491349
content,

test/scripts/hexo/router.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { join } from 'path';
55
import crypto from 'crypto';
66
import { createReadStream } from 'hexo-fs';
77
import { spy, assert as sinonAssert } from 'sinon';
8-
import testUtil from '../../util';
8+
import { readStream } from '../../util';
99
import Router from '../../../lib/hexo/router';
1010
import chai from 'chai';
1111
const should = chai.should();
@@ -14,7 +14,7 @@ describe('Router', () => {
1414
const router = new Router();
1515

1616
function checkStream(stream, expected) {
17-
return testUtil.stream.read(stream).then(data => {
17+
return readStream(stream).then(data => {
1818
data.should.eql(expected);
1919
});
2020
}
@@ -125,7 +125,7 @@ describe('Router', () => {
125125
throw new Error('error test');
126126
});
127127

128-
return testUtil.stream.read(router.get('test')).then(() => {
128+
return readStream(router.get('test')).then(() => {
129129
should.fail('Return value must be rejected');
130130
}, err => {
131131
err.should.have.property('message', 'error test');

test/util/.eslintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "hexo/ts",
3+
"rules": {
4+
"node/no-unsupported-features/es-syntax": 0
5+
}
6+
}

test/util/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/util/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { readStream } from './stream';
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict';
1+
import Promise from 'bluebird';
22

3-
const Promise = require('bluebird');
4-
5-
function readStream(stream) {
3+
export function readStream(stream): Promise<string> {
64
return new Promise((resolve, reject) => {
75
let data = '';
86

@@ -13,5 +11,3 @@ function readStream(stream) {
1311
}).on('error', reject);
1412
});
1513
}
16-
17-
exports.read = readStream;

0 commit comments

Comments
 (0)