mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-11-29 18:48:14 +08:00
Setup test environment and provide first tests 🌟
This commit is contained in:
parent
fd86c727af
commit
b53571810b
148
package-lock.json
generated
148
package-lock.json
generated
@ -283,6 +283,12 @@
|
||||
"integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=",
|
||||
"dev": true
|
||||
},
|
||||
"assertion-error": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz",
|
||||
"integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==",
|
||||
"dev": true
|
||||
},
|
||||
"assign-symbols": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/assign-symbols/-/assign-symbols-1.0.0.tgz",
|
||||
@ -563,6 +569,12 @@
|
||||
"integrity": "sha512-bRFnI4NnjO6cnyLmOV/7PVoDEMJChlcfN0z4s1YMBY989/SvlfMI1lgCnkFUs53e9gQF+w7qu7XdllSTiSl8Aw==",
|
||||
"dev": true
|
||||
},
|
||||
"browser-stdout": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz",
|
||||
"integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==",
|
||||
"dev": true
|
||||
},
|
||||
"browserslist": {
|
||||
"version": "2.11.3",
|
||||
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-2.11.3.tgz",
|
||||
@ -741,6 +753,20 @@
|
||||
"integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=",
|
||||
"dev": true
|
||||
},
|
||||
"chai": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz",
|
||||
"integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"assertion-error": "^1.1.0",
|
||||
"check-error": "^1.0.2",
|
||||
"deep-eql": "^3.0.1",
|
||||
"get-func-name": "^2.0.0",
|
||||
"pathval": "^1.1.0",
|
||||
"type-detect": "^4.0.5"
|
||||
}
|
||||
},
|
||||
"chalk": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
|
||||
@ -758,6 +784,12 @@
|
||||
"resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz",
|
||||
"integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I="
|
||||
},
|
||||
"check-error": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz",
|
||||
"integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=",
|
||||
"dev": true
|
||||
},
|
||||
"chokidar": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.0.4.tgz",
|
||||
@ -1610,6 +1642,15 @@
|
||||
"integrity": "sha1-JJXduvbrh0q7Dhvp3yLS5aVEMmw=",
|
||||
"dev": true
|
||||
},
|
||||
"deep-eql": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz",
|
||||
"integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"type-detect": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"deep-extend": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
|
||||
@ -1746,6 +1787,12 @@
|
||||
"integrity": "sha1-OHHMCmoALow+Wzz38zYmRnXwa50=",
|
||||
"dev": true
|
||||
},
|
||||
"diff": {
|
||||
"version": "3.5.0",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
|
||||
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
|
||||
"dev": true
|
||||
},
|
||||
"doctrine": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz",
|
||||
@ -3162,6 +3209,12 @@
|
||||
"integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==",
|
||||
"dev": true
|
||||
},
|
||||
"get-func-name": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz",
|
||||
"integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=",
|
||||
"dev": true
|
||||
},
|
||||
"get-pkg-repo": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/get-pkg-repo/-/get-pkg-repo-1.4.0.tgz",
|
||||
@ -3467,6 +3520,12 @@
|
||||
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=",
|
||||
"dev": true
|
||||
},
|
||||
"growl": {
|
||||
"version": "1.10.5",
|
||||
"resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz",
|
||||
"integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==",
|
||||
"dev": true
|
||||
},
|
||||
"handlebars": {
|
||||
"version": "4.0.12",
|
||||
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.12.tgz",
|
||||
@ -3596,6 +3655,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"he": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz",
|
||||
"integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=",
|
||||
"dev": true
|
||||
},
|
||||
"hosted-git-info": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.7.1.tgz",
|
||||
@ -4819,6 +4884,71 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"mocha": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz",
|
||||
"integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"browser-stdout": "1.3.1",
|
||||
"commander": "2.15.1",
|
||||
"debug": "3.1.0",
|
||||
"diff": "3.5.0",
|
||||
"escape-string-regexp": "1.0.5",
|
||||
"glob": "7.1.2",
|
||||
"growl": "1.10.5",
|
||||
"he": "1.1.1",
|
||||
"minimatch": "3.0.4",
|
||||
"mkdirp": "0.5.1",
|
||||
"supports-color": "5.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": {
|
||||
"version": "2.15.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz",
|
||||
"integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==",
|
||||
"dev": true
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"glob": {
|
||||
"version": "7.1.2",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
|
||||
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fs.realpath": "^1.0.0",
|
||||
"inflight": "^1.0.4",
|
||||
"inherits": "2",
|
||||
"minimatch": "^3.0.4",
|
||||
"once": "^1.3.0",
|
||||
"path-is-absolute": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"has-flag": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
||||
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
|
||||
"dev": true
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "5.4.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz",
|
||||
"integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"has-flag": "^3.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"modify-values": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/modify-values/-/modify-values-1.0.1.tgz",
|
||||
@ -5441,6 +5571,12 @@
|
||||
"pify": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"pathval": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz",
|
||||
"integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=",
|
||||
"dev": true
|
||||
},
|
||||
"pause-stream": {
|
||||
"version": "0.0.11",
|
||||
"resolved": "https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz",
|
||||
@ -8195,6 +8331,12 @@
|
||||
"prelude-ls": "~1.1.2"
|
||||
}
|
||||
},
|
||||
"type-detect": {
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
|
||||
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
|
||||
"dev": true
|
||||
},
|
||||
"typedarray": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
||||
@ -8649,6 +8791,12 @@
|
||||
"async-limiter": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"xhr2": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/xhr2/-/xhr2-0.1.4.tgz",
|
||||
"integrity": "sha1-f4dliEdxbbUCYyOBL4GMras4el8=",
|
||||
"dev": true
|
||||
},
|
||||
"xml-name-validator": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz",
|
||||
|
@ -27,7 +27,7 @@
|
||||
"dev": "run-p serve watch:*",
|
||||
"dev:ssr": "run-p serve:ssr watch:*",
|
||||
"lint": "eslint {src,packages} --fix",
|
||||
"test": "run-p lint",
|
||||
"test": "mocha",
|
||||
"css": "stylus src/themes/*.styl -u autoprefixer-stylus",
|
||||
"watch:css": "run-p 'css -- -o themes -w'",
|
||||
"watch:js": "node build/build.js",
|
||||
@ -51,6 +51,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"autoprefixer-stylus": "^0.14.0",
|
||||
"chai": "^4.2.0",
|
||||
"chokidar": "^2.0.2",
|
||||
"conventional-changelog-cli": "^1.3.5",
|
||||
"cross-env": "^5.1.3",
|
||||
@ -61,6 +62,7 @@
|
||||
"jsdom": "^13.2.0",
|
||||
"lerna": "^2.5.1",
|
||||
"live-server": "^1.2.1",
|
||||
"mocha": "^5.2.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"rimraf": "^2.6.2",
|
||||
"rollup": "^0.53.3",
|
||||
@ -70,7 +72,8 @@
|
||||
"rollup-plugin-node-resolve": "^3.0.0",
|
||||
"rollup-plugin-replace": "^2.0.0",
|
||||
"rollup-plugin-uglify": "^2.0.1",
|
||||
"stylus": "^0.54.5"
|
||||
"stylus": "^0.54.5",
|
||||
"xhr2": "^0.1.4"
|
||||
},
|
||||
"keywords": [
|
||||
"doc",
|
||||
|
74
test/_helper.js
Normal file
74
test/_helper.js
Normal file
@ -0,0 +1,74 @@
|
||||
// load ES6 modules in Node.js on the fly
|
||||
require = require('esm')(module/*, options*/)
|
||||
|
||||
const {expect} = require('chai')
|
||||
|
||||
const {JSDOM} = require('jsdom')
|
||||
const XMLHttpRequest = require('xhr2') // JSDOM doesn't support XMLHttpRequest
|
||||
// TODO: try to fix tests when using `<div id="app"></div>` in body
|
||||
const markup = `<!DOCTYPE html>
|
||||
<html>
|
||||
<head></head>
|
||||
<body></body>
|
||||
</html>`
|
||||
// TODO: this may not work if tests are mutate the DOM, instead a new instance needs to be created
|
||||
// for every test case but that will slow down the tests
|
||||
const dom = new JSDOM(markup)
|
||||
|
||||
global.window = dom.window
|
||||
global.document = dom.window.document
|
||||
global.navigator = dom.window.navigator
|
||||
global.location = dom.window.location
|
||||
global.XMLHttpRequest = XMLHttpRequest
|
||||
|
||||
const {initMixin} = require('../src/core/init')
|
||||
const {routerMixin} = require('../src/core//router')
|
||||
const {renderMixin} = require('../src/core//render')
|
||||
const {fetchMixin} = require('../src/core/fetch')
|
||||
const {eventMixin} = require('../src/core//event')
|
||||
|
||||
// mimic src/core/index.js but for Node.js
|
||||
|
||||
function Docsify() {
|
||||
this._init()
|
||||
}
|
||||
|
||||
const proto = Docsify.prototype
|
||||
|
||||
initMixin(proto)
|
||||
routerMixin(proto)
|
||||
renderMixin(proto)
|
||||
fetchMixin(proto)
|
||||
eventMixin(proto)
|
||||
|
||||
function ready(callback) {
|
||||
const state = document.readyState
|
||||
|
||||
if (state === 'complete' || state === 'interactive') {
|
||||
return setTimeout(callback, 0)
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', callback)
|
||||
}
|
||||
let docsify = null
|
||||
module.exports.init = function(callback) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// return cached version / TODO: see above: this might not scale, new instance of JSDOM is reqiured
|
||||
if (docsify != null) {
|
||||
return resolve(docsify)
|
||||
}
|
||||
ready(_ => {
|
||||
docsify = new Docsify()
|
||||
return resolve(docsify)
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
module.exports.expectSameDom = function(actual, expected) {
|
||||
const WHITESPACES_BETWEEN_TAGS = />(\s\s+)</g
|
||||
function replacer(match, group1) {
|
||||
return match.replace(group1, '')
|
||||
}
|
||||
expect(actual.replace(WHITESPACES_BETWEEN_TAGS, replacer).trim())
|
||||
.equal(expected.replace(WHITESPACES_BETWEEN_TAGS, replacer).trim())
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
require = require('esm')(module/*, options*/)
|
||||
const {JSDOM} = require('jsdom')
|
||||
const dom = new JSDOM('<!DOCTYPE html><body></body>')
|
||||
|
||||
global.window = dom.window
|
||||
global.document = dom.window.document
|
||||
global.navigator = dom.window.navigator
|
||||
global.location = dom.window.location
|
||||
|
||||
require('../src/core')
|
89
test/render.js
Normal file
89
test/render.js
Normal file
@ -0,0 +1,89 @@
|
||||
const path = require('path')
|
||||
|
||||
const {expect} = require('chai')
|
||||
|
||||
const {init, expectSameDom} = require('./_helper')
|
||||
|
||||
describe('render', function() {
|
||||
it('important content (tips)', async function() {
|
||||
docsify = await init()
|
||||
const output = docsify.compiler.compile('!> **Time** is money, my friend!')
|
||||
expect(output).equal('<p class="tip"><strong>Time</strong> is money, my friend!</p>')
|
||||
})
|
||||
|
||||
describe('lists', function() {
|
||||
it('as unordered task list', async function() {
|
||||
docsify = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
- [x] Task 1
|
||||
- [ ] Task 2
|
||||
- [ ] Task 3`)
|
||||
expect(output, `<ul class="task-list">
|
||||
<li class="task-list-item"><label><input checked="" disabled="" type="checkbox"> Task 1</label></li>
|
||||
<li class="task-list-item"><label><input disabled="" type="checkbox"> Task 2</label></li>
|
||||
<li class="task-list-item"><label><input disabled="" type="checkbox"> Task 3</label></li>
|
||||
</ul>`)
|
||||
})
|
||||
|
||||
it('as ordered task list', async function() {
|
||||
docsify = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
1. [ ] Task 1
|
||||
2. [x] Task 2`)
|
||||
expectSameDom(output, `<ol class="task-list">
|
||||
<li class="task-list-item"><label><input disabled="" type="checkbox"> Task 1</label></li>
|
||||
<li class="task-list-item"><label><input checked="" disabled="" type="checkbox"> Task 2</label></li>
|
||||
</ol>`)
|
||||
})
|
||||
|
||||
it('normal unordered', async function() {
|
||||
docsify = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
- [linktext](link)
|
||||
- just text`)
|
||||
expectSameDom(output, `<ul >
|
||||
<li><a href="#/link">linktext</a></li>
|
||||
<li>just text</li>
|
||||
</ul>`)
|
||||
})
|
||||
|
||||
it('unordered with custom start', async function() {
|
||||
docsify = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
1. first
|
||||
2. second
|
||||
|
||||
text
|
||||
|
||||
3. third`)
|
||||
expectSameDom(output, `<ol >
|
||||
<li>first</li>
|
||||
<li>second</li>
|
||||
</ol>
|
||||
<p>text</p>
|
||||
<ol start="3">
|
||||
<li>third</li>
|
||||
</ol>`)
|
||||
})
|
||||
|
||||
it('nested', async function() {
|
||||
docsify = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
- 1
|
||||
- 2
|
||||
- 2 a
|
||||
- 2 b
|
||||
- 3`)
|
||||
expectSameDom(output, `<ul >
|
||||
<li>1</li>
|
||||
<li>2<ul >
|
||||
<li>2 a</li>
|
||||
<li>2 b</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>3</li>
|
||||
</ul>`)
|
||||
})
|
||||
})
|
||||
|
||||
})
|
Loading…
Reference in New Issue
Block a user