Skip to content

Commit

Permalink
Setup test environment and provide first test 🌟
Browse files Browse the repository at this point in the history
  • Loading branch information
devtonhere committed Jan 30, 2019
1 parent fd86c72 commit 96a6c5b
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 3 deletions.
142 changes: 142 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
44 changes: 42 additions & 2 deletions test/_loader.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,50 @@
require = require('esm')(module/*, options*/)
const {JSDOM} = require('jsdom')
const dom = new JSDOM('<!DOCTYPE html><body></body>')
const dom = new JSDOM('<!DOCTYPE html><html><head></head><body></body></html>') // minimal DOM

global.window = dom.window
global.document = dom.window.document
global.navigator = dom.window.navigator
global.location = dom.window.location

require('../src/core')
const {initMixin} = require('../src/core/init')
const {routerMixin} = require('../src/core//router')
const {renderMixin} = require('../src/core//render')
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)
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 = function(callback) {
return new Promise((resolve, reject) => {
// return cached version
if (docsify != null) {
return resolve(docsify)
}
ready(_ => {
docsify = new Docsify()
return resolve(docsify)
})

})
}
11 changes: 11 additions & 0 deletions test/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const {expect} = require('chai')

const loader = require('./_loader')

describe('render', function() {
it('important content (tips)', async function() {
docsify = await loader()
const output = docsify.compiler.compile('!> **Time** is money, my friend!')
expect(output).equal('<p class="tip"><strong>Time</strong> is money, my friend!</p>')
})
})

0 comments on commit 96a6c5b

Please sign in to comment.