Skip to content

Commit 7d7fe6d

Browse files
committed
Setup test environment and provide first test 🌟
1 parent fd86c72 commit 7d7fe6d

File tree

4 files changed

+279
-4
lines changed

4 files changed

+279
-4
lines changed

Diff for: package-lock.json

+148
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"dev": "run-p serve watch:*",
2828
"dev:ssr": "run-p serve:ssr watch:*",
2929
"lint": "eslint {src,packages} --fix",
30-
"test": "run-p lint",
30+
"test": "mocha",
3131
"css": "stylus src/themes/*.styl -u autoprefixer-stylus",
3232
"watch:css": "run-p 'css -- -o themes -w'",
3333
"watch:js": "node build/build.js",
@@ -51,6 +51,7 @@
5151
},
5252
"devDependencies": {
5353
"autoprefixer-stylus": "^0.14.0",
54+
"chai": "^4.2.0",
5455
"chokidar": "^2.0.2",
5556
"conventional-changelog-cli": "^1.3.5",
5657
"cross-env": "^5.1.3",
@@ -61,6 +62,7 @@
6162
"jsdom": "^13.2.0",
6263
"lerna": "^2.5.1",
6364
"live-server": "^1.2.1",
65+
"mocha": "^5.2.0",
6466
"npm-run-all": "^4.1.5",
6567
"rimraf": "^2.6.2",
6668
"rollup": "^0.53.3",
@@ -70,7 +72,8 @@
7072
"rollup-plugin-node-resolve": "^3.0.0",
7173
"rollup-plugin-replace": "^2.0.0",
7274
"rollup-plugin-uglify": "^2.0.1",
73-
"stylus": "^0.54.5"
75+
"stylus": "^0.54.5",
76+
"xhr2": "^0.1.4"
7477
},
7578
"keywords": [
7679
"doc",

Diff for: test/_loader.js

+47-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,55 @@
11
require = require('esm')(module/*, options*/)
22
const {JSDOM} = require('jsdom')
3-
const dom = new JSDOM('<!DOCTYPE html><body></body>')
3+
const XMLHttpRequest = require('xhr2')
4+
// TODO: try to fix tests when using `<div id="app"></div>` in body
5+
const dom = new JSDOM('<!DOCTYPE html><html><head></head><body></body></html>')
46

57
global.window = dom.window
68
global.document = dom.window.document
79
global.navigator = dom.window.navigator
810
global.location = dom.window.location
11+
global.XMLHttpRequest = XMLHttpRequest
912

10-
require('../src/core')
13+
const {initMixin} = require('../src/core/init')
14+
const {routerMixin} = require('../src/core//router')
15+
const {renderMixin} = require('../src/core//render')
16+
const {fetchMixin} = require('../src/core/fetch')
17+
const {eventMixin} = require('../src/core//event')
18+
19+
// mimic src/core/index.js but for Node.js
20+
21+
function Docsify() {
22+
this._init()
23+
}
24+
25+
const proto = Docsify.prototype
26+
27+
initMixin(proto)
28+
routerMixin(proto)
29+
renderMixin(proto)
30+
fetchMixin(proto)
31+
eventMixin(proto)
32+
33+
function ready(callback) {
34+
const state = document.readyState
35+
36+
if (state === 'complete' || state === 'interactive') {
37+
return setTimeout(callback, 0)
38+
}
39+
40+
document.addEventListener('DOMContentLoaded', callback)
41+
}
42+
let docsify = null
43+
module.exports = function(callback) {
44+
return new Promise((resolve, reject) => {
45+
// return cached version
46+
if (docsify != null) {
47+
return resolve(docsify)
48+
}
49+
ready(_ => {
50+
docsify = new Docsify()
51+
return resolve(docsify)
52+
})
53+
54+
})
55+
}

0 commit comments

Comments
 (0)