mirror of
https://github.com/wahyd4/docsify.git
synced 2026-08-09 05:16:06 +10:00
Eslint fixes for v4x (#989)
* UPDATE .eslintrc * UPDATE lint task * FIX lint errors * CLEANUP * FIX no-eq-null warning * FIX many jsdoc warnings * FIX jsdoc issues * FIX jsdoc warnings * FIX jsdoc * FIX eqeq and no-eq-null * ADD lint to travis * UPDATE test env for eslint
This commit is contained in:
+59
-56
@@ -1,10 +1,10 @@
|
||||
// load ES6 modules in Node.js on the fly
|
||||
require = require('esm')(module/*, options*/)
|
||||
// Load ES6 modules in Node.js on the fly
|
||||
require = require('esm')(module/* , options */) /* eslint-disable-line no-global-assign */
|
||||
|
||||
const path = require('path')
|
||||
const {expect} = require('chai')
|
||||
const { expect } = require('chai')
|
||||
|
||||
const {JSDOM} = require('jsdom')
|
||||
const { JSDOM } = require('jsdom')
|
||||
|
||||
function ready(callback) {
|
||||
const state = document.readyState
|
||||
@@ -15,9 +15,10 @@ function ready(callback) {
|
||||
|
||||
document.addEventListener('DOMContentLoaded', callback)
|
||||
}
|
||||
module.exports.init = function(fixture = 'default', config = {}, markup) {
|
||||
if (markup == null) {
|
||||
markup = `<!DOCTYPE html>
|
||||
|
||||
module.exports.init = function (fixture = 'default', config = {}, markup = null) {
|
||||
if (markup === null || markup === undefined) {
|
||||
markup = `<!DOCTYPE html>
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
@@ -27,61 +28,63 @@ module.exports.init = function(fixture = 'default', config = {}, markup) {
|
||||
</script>
|
||||
</body>
|
||||
</html>`
|
||||
}
|
||||
const rootPath = path.join(__dirname, 'fixtures', fixture)
|
||||
|
||||
const dom = new JSDOM(markup)
|
||||
dom.reconfigure({ url: 'file:///' + rootPath })
|
||||
}
|
||||
|
||||
global.window = dom.window
|
||||
global.document = dom.window.document
|
||||
global.navigator = dom.window.navigator
|
||||
global.location = dom.window.location
|
||||
global.XMLHttpRequest = dom.window.XMLHttpRequest
|
||||
const rootPath = path.join(__dirname, 'fixtures', fixture)
|
||||
|
||||
// mimic src/core/index.js but for Node.js
|
||||
function Docsify() {
|
||||
this._init()
|
||||
}
|
||||
const dom = new JSDOM(markup)
|
||||
dom.reconfigure({ url: 'file:///' + rootPath })
|
||||
|
||||
const proto = Docsify.prototype
|
||||
global.window = dom.window
|
||||
global.document = dom.window.document
|
||||
global.navigator = dom.window.navigator
|
||||
global.location = dom.window.location
|
||||
global.XMLHttpRequest = dom.window.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()
|
||||
}
|
||||
|
||||
initMixin(proto)
|
||||
routerMixin(proto)
|
||||
renderMixin(proto)
|
||||
fetchMixin(proto)
|
||||
eventMixin(proto)
|
||||
const proto = Docsify.prototype
|
||||
|
||||
const NOT_INIT_PATTERN = '<!--main-->'
|
||||
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')
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
ready(() => {
|
||||
const docsify = new Docsify()
|
||||
// NOTE: I was not able to get it working with a callback, but polling works usually at the first time
|
||||
const id = setInterval(() => {
|
||||
if (dom.window.document.body.innerHTML.indexOf(NOT_INIT_PATTERN) == -1) {
|
||||
clearInterval(id)
|
||||
return resolve({
|
||||
docsify: docsify,
|
||||
dom: dom
|
||||
})
|
||||
}
|
||||
}, 10)
|
||||
})
|
||||
|
||||
})
|
||||
initMixin(proto)
|
||||
routerMixin(proto)
|
||||
renderMixin(proto)
|
||||
fetchMixin(proto)
|
||||
eventMixin(proto)
|
||||
|
||||
const NOT_INIT_PATTERN = '<!--main-->'
|
||||
|
||||
return new Promise(resolve => {
|
||||
ready(() => {
|
||||
const docsify = new Docsify()
|
||||
// NOTE: I was not able to get it working with a callback, but polling works usually at the first time
|
||||
const id = setInterval(() => {
|
||||
if (dom.window.document.body.innerHTML.indexOf(NOT_INIT_PATTERN) === -1) {
|
||||
clearInterval(id)
|
||||
return resolve({
|
||||
docsify: docsify,
|
||||
dom: dom
|
||||
})
|
||||
}
|
||||
}, 10)
|
||||
})
|
||||
})
|
||||
}
|
||||
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())
|
||||
|
||||
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,14 +1,9 @@
|
||||
const path = require('path')
|
||||
|
||||
const {expect} = require('chai')
|
||||
|
||||
const {init, expectSameDom} = require('../_helper')
|
||||
|
||||
describe('full docsify initialization', function() {
|
||||
it('TODO: check generated markup', async function() {
|
||||
const {docsify, dom} = await init('simple', {loadSidebar: true})
|
||||
console.log(dom.window.document.body.innerHTML)
|
||||
// TODO: add some expectations
|
||||
})
|
||||
const { init } = require('../_helper')
|
||||
|
||||
describe('full docsify initialization', function () {
|
||||
it('TODO: check generated markup', async function () {
|
||||
const { dom } = await init('simple', { loadSidebar: true })
|
||||
console.log(dom.window.document.body.innerHTML)
|
||||
// TODO: add some expectations
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
const path = require('path')
|
||||
|
||||
const {expect} = require('chai')
|
||||
|
||||
const {init, expectSameDom} = require('../_helper')
|
||||
|
||||
describe('router', function() {
|
||||
it('TODO: trigger to load another page', async function() {
|
||||
const {docsify} = await init()
|
||||
window.location = '/?foo=bar'
|
||||
// TODO: add some expectations
|
||||
})
|
||||
const { init } = require('../_helper')
|
||||
|
||||
describe('router', function () {
|
||||
it('TODO: trigger to load another page', async function () {
|
||||
await init()
|
||||
window.location = '/?foo=bar'
|
||||
// TODO: add some expectations
|
||||
})
|
||||
})
|
||||
|
||||
+61
-62
@@ -1,62 +1,61 @@
|
||||
/* eslint-env node, chai, mocha */
|
||||
require = require('esm')(module/*, options*/)
|
||||
const {expect} = require('chai')
|
||||
const {History} = require('../../src/core/router/history/base')
|
||||
|
||||
class MockHistory extends History {
|
||||
parse(path) {
|
||||
return {path}
|
||||
}
|
||||
}
|
||||
|
||||
describe('router/history/base', function () {
|
||||
describe('relativePath true', function () {
|
||||
var history
|
||||
|
||||
beforeEach(function () {
|
||||
history = new MockHistory({relativePath: true})
|
||||
})
|
||||
|
||||
it('toURL', function () {
|
||||
// WHEN
|
||||
const url = history.toURL('guide.md', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/zh-ch/guide')
|
||||
})
|
||||
|
||||
it('toURL with double dot', function () {
|
||||
// WHEN
|
||||
const url = history.toURL('../README.md', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/README')
|
||||
})
|
||||
|
||||
it('toURL child path', function () {
|
||||
// WHEN
|
||||
const url = history.toURL('config/example.md', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/zh-ch/config/example')
|
||||
})
|
||||
|
||||
it('toURL absolute path', function () {
|
||||
// WHEN
|
||||
const url = history.toURL('/README', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/README')
|
||||
})
|
||||
})
|
||||
|
||||
it('toURL without relative path', function () {
|
||||
const history = new MockHistory({relativePath: false})
|
||||
|
||||
// WHEN
|
||||
const url = history.toURL('README', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/README')
|
||||
})
|
||||
})
|
||||
require = require('esm')(module/* , options */) /* eslint-disable-line no-global-assign */
|
||||
const { expect } = require('chai')
|
||||
const { History } = require('../../src/core/router/history/base')
|
||||
|
||||
class MockHistory extends History {
|
||||
parse(path) {
|
||||
return { path }
|
||||
}
|
||||
}
|
||||
|
||||
describe('router/history/base', function () {
|
||||
describe('relativePath true', function () {
|
||||
var history
|
||||
|
||||
beforeEach(function () {
|
||||
history = new MockHistory({ relativePath: true })
|
||||
})
|
||||
|
||||
it('toURL', function () {
|
||||
// WHEN
|
||||
const url = history.toURL('guide.md', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/zh-ch/guide')
|
||||
})
|
||||
|
||||
it('toURL with double dot', function () {
|
||||
// WHEN
|
||||
const url = history.toURL('../README.md', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/README')
|
||||
})
|
||||
|
||||
it('toURL child path', function () {
|
||||
// WHEN
|
||||
const url = history.toURL('config/example.md', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/zh-ch/config/example')
|
||||
})
|
||||
|
||||
it('toURL absolute path', function () {
|
||||
// WHEN
|
||||
const url = history.toURL('/README', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/README')
|
||||
})
|
||||
})
|
||||
|
||||
it('toURL without relative path', function () {
|
||||
const history = new MockHistory({ relativePath: false })
|
||||
|
||||
// WHEN
|
||||
const url = history.toURL('README', {}, '/zh-ch/')
|
||||
|
||||
// THEN
|
||||
expect(url).equal('/README')
|
||||
})
|
||||
})
|
||||
|
||||
+35
-38
@@ -1,62 +1,60 @@
|
||||
const path = require('path')
|
||||
const { expect } = require('chai')
|
||||
|
||||
const {expect} = require('chai')
|
||||
const { init, expectSameDom } = require('../_helper')
|
||||
|
||||
const {init, expectSameDom} = require('../_helper')
|
||||
describe('render', function () {
|
||||
it('important content (tips)', async function () {
|
||||
const { 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('render', function() {
|
||||
it('important content (tips)', async function() {
|
||||
const {docsify, dom} = 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() {
|
||||
const {docsify, dom} = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
describe('lists', function () {
|
||||
it('as unordered task list', async function () {
|
||||
const { docsify } = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
- [x] Task 1
|
||||
- [ ] Task 2
|
||||
- [ ] Task 3`)
|
||||
expect(output, `<ul class="task-list">
|
||||
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() {
|
||||
const {docsify, dom} = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
it('as ordered task list', async function () {
|
||||
const { docsify } = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
1. [ ] Task 1
|
||||
2. [x] Task 2`)
|
||||
expectSameDom(output, `<ol class="task-list">
|
||||
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() {
|
||||
const {docsify, dom} = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
it('normal unordered', async function () {
|
||||
const { docsify } = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
- [linktext](link)
|
||||
- just text`)
|
||||
expectSameDom(output, `<ul >
|
||||
expectSameDom(output, `<ul >
|
||||
<li><a href="#/link">linktext</a></li>
|
||||
<li>just text</li>
|
||||
</ul>`)
|
||||
})
|
||||
})
|
||||
|
||||
it('unordered with custom start', async function() {
|
||||
const {docsify, dom} = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
it('unordered with custom start', async function () {
|
||||
const { docsify } = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
1. first
|
||||
2. second
|
||||
|
||||
text
|
||||
|
||||
3. third`)
|
||||
expectSameDom(output, `<ol >
|
||||
expectSameDom(output, `<ol >
|
||||
<li>first</li>
|
||||
<li>second</li>
|
||||
</ol>
|
||||
@@ -64,17 +62,17 @@ text
|
||||
<ol start="3">
|
||||
<li>third</li>
|
||||
</ol>`)
|
||||
})
|
||||
})
|
||||
|
||||
it('nested', async function() {
|
||||
const {docsify, dom} = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
it('nested', async function () {
|
||||
const { docsify } = await init()
|
||||
const output = docsify.compiler.compile(`
|
||||
- 1
|
||||
- 2
|
||||
- 2 a
|
||||
- 2 b
|
||||
- 3`)
|
||||
expectSameDom(output, `<ul >
|
||||
expectSameDom(output, `<ul >
|
||||
<li>1</li>
|
||||
<li>2<ul >
|
||||
<li>2 a</li>
|
||||
@@ -83,7 +81,6 @@ text
|
||||
</li>
|
||||
<li>3</li>
|
||||
</ul>`)
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
+29
-30
@@ -1,30 +1,29 @@
|
||||
/* eslint-env node, chai, mocha */
|
||||
require = require('esm')(module/*, options*/)
|
||||
const {expect} = require('chai')
|
||||
const {resolvePath} = require('../../src/core/router/util')
|
||||
|
||||
describe('router/util', function () {
|
||||
it('resolvePath', async function () {
|
||||
// WHEN
|
||||
const result = resolvePath('hello.md')
|
||||
|
||||
// THEN
|
||||
expect(result).equal('/hello.md')
|
||||
})
|
||||
|
||||
it('resolvePath with dot', async function () {
|
||||
// WHEN
|
||||
const result = resolvePath('./hello.md')
|
||||
|
||||
// THEN
|
||||
expect(result).equal('/hello.md')
|
||||
})
|
||||
|
||||
it('resolvePath with two dots', async function () {
|
||||
// WHEN
|
||||
const result = resolvePath('test/../hello.md')
|
||||
|
||||
// THEN
|
||||
expect(result).equal('/hello.md')
|
||||
})
|
||||
})
|
||||
require = require('esm')(module/* , options */) /* eslint-disable-line no-global-assign */
|
||||
const { expect } = require('chai')
|
||||
const { resolvePath } = require('../../src/core/router/util')
|
||||
|
||||
describe('router/util', function () {
|
||||
it('resolvePath', async function () {
|
||||
// WHEN
|
||||
const result = resolvePath('hello.md')
|
||||
|
||||
// THEN
|
||||
expect(result).equal('/hello.md')
|
||||
})
|
||||
|
||||
it('resolvePath with dot', async function () {
|
||||
// WHEN
|
||||
const result = resolvePath('./hello.md')
|
||||
|
||||
// THEN
|
||||
expect(result).equal('/hello.md')
|
||||
})
|
||||
|
||||
it('resolvePath with two dots', async function () {
|
||||
// WHEN
|
||||
const result = resolvePath('test/../hello.md')
|
||||
|
||||
// THEN
|
||||
expect(result).equal('/hello.md')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user