-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup test environment and provide first test 🌟
- Loading branch information
1 parent
fd86c72
commit 96a6c5b
Showing
4 changed files
with
198 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
|
||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>') | ||
}) | ||
}) |