Skip to content

Commit 45023a4

Browse files
committed
add an intial test file for testing SSR
1 parent 418025f commit 45023a4

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

Diff for: packages/docsify-server-renderer/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,6 @@ export default class Renderer {
197197
}
198198
}
199199

200+
export { Renderer };
201+
200202
Renderer.version = '__VERSION__';

Diff for: test/_helper.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ function ready(callback) {
1919
document.addEventListener('DOMContentLoaded', callback);
2020
}
2121

22+
module.exports.initJSDOM = initJSDOM;
23+
function initJSDOM(markup = '') {
24+
const dom = new JSDOM(markup);
25+
26+
global.window = dom.window;
27+
global.document = dom.window.document;
28+
global.navigator = dom.window.navigator;
29+
global.location = dom.window.location;
30+
global.XMLHttpRequest = dom.window.XMLHttpRequest;
31+
32+
return dom;
33+
}
34+
2235
module.exports.init = function(
2336
fixture = 'default',
2437
config = {},
@@ -39,15 +52,9 @@ module.exports.init = function(
3952

4053
const rootPath = path.join(__dirname, 'fixtures', fixture);
4154

42-
const dom = new JSDOM(markup);
55+
const dom = initJSDOM(markup);
4356
dom.reconfigure({ url: 'file:///' + rootPath });
4457

45-
global.window = dom.window;
46-
global.document = dom.window.document;
47-
global.navigator = dom.window.navigator;
48-
global.location = dom.window.location;
49-
global.XMLHttpRequest = dom.window.XMLHttpRequest;
50-
5158
// Mimic src/core/index.js but for Node.js
5259
function Docsify() {
5360
this._init();

Diff for: test/unit/server.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @ts-check
2+
/* eslint-disable no-global-assign */
3+
require = require('esm')(
4+
module /* , options */
5+
); /* eslint-disable-line no-global-assign */
6+
const { expect } = require('chai');
7+
const { initJSDOM } = require('../_helper');
8+
9+
initJSDOM();
10+
11+
const { Renderer } = require('../../packages/docsify-server-renderer/index');
12+
13+
describe('pacakges/docsify-server-render', function() {
14+
it('toURL', function() {
15+
expect(Renderer).to.be.an.instanceof(Function);
16+
expect('foo').equal('foo');
17+
});
18+
});

0 commit comments

Comments
 (0)