eslint integration
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
module.exports = {
|
||||
'plugins': ['jest'],
|
||||
'env': {
|
||||
'commonjs': true,
|
||||
'es2021': true,
|
||||
'node': true,
|
||||
'jest/globals': true
|
||||
},
|
||||
'extends': ['eslint:recommended'],
|
||||
'parserOptions': {
|
||||
'ecmaVersion': 12
|
||||
},
|
||||
'rules': {
|
||||
'indent': [
|
||||
'error',
|
||||
4
|
||||
],
|
||||
'linebreak-style': [
|
||||
'error',
|
||||
'unix'
|
||||
],
|
||||
'quotes': [
|
||||
'error',
|
||||
'single'
|
||||
],
|
||||
'semi': [
|
||||
'error',
|
||||
'always'
|
||||
],
|
||||
'curly': [
|
||||
'error',
|
||||
'all'
|
||||
],
|
||||
'brace-style': [
|
||||
'error',
|
||||
'1tbs'
|
||||
]
|
||||
}
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"esversion": 6,
|
||||
"maxerr": 999,
|
||||
"indent": true,
|
||||
"camelcase": true,
|
||||
"eqeqeq": true,
|
||||
"forin": true,
|
||||
"immed": true,
|
||||
"latedef": true,
|
||||
"noarg": true,
|
||||
"noempty": true,
|
||||
"nonew": true,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"varstmt": true,
|
||||
"sub": true,
|
||||
"quotmark": "single",
|
||||
"node": true,
|
||||
"globals": {
|
||||
}
|
||||
}
|
||||
Generated
+2616
-28
File diff suppressed because it is too large
Load Diff
+4
-1
@@ -19,6 +19,8 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"coveralls": "^3.0.4",
|
||||
"eslint": "^7.23.0",
|
||||
"eslint-plugin-jest": "^24.3.2",
|
||||
"jest": "^24.8.0",
|
||||
"superagent": "^5.1.0",
|
||||
"supertest": "^4.0.2"
|
||||
@@ -26,7 +28,8 @@
|
||||
"scripts": {
|
||||
"start": "node src/server.js",
|
||||
"test": "jest --silent -i",
|
||||
"install": "node src/postinstall.js"
|
||||
"install": "node src/postinstall.js",
|
||||
"lint": "eslint --fix ."
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
+22
-14
@@ -71,18 +71,20 @@ module.exports = (config) => {
|
||||
Object.keys(dict).forEach((key) => articles[key] = dict[key]);
|
||||
const nb = Object.keys(articles).length;
|
||||
const dnb = Object.values(articles).filter(a => a.draft).length;
|
||||
if (nb > 0)
|
||||
if (nb > 0) {
|
||||
console.log(cons.ok, `loaded ${nb} article${nb > 1 ? 's' : ''} (${dnb} drafted)`);
|
||||
else
|
||||
console.log(cons.warn, `no articles loaded, check your configuration`);
|
||||
} else {
|
||||
console.log(cons.warn, 'no articles loaded, check your configuration');
|
||||
}
|
||||
|
||||
lastRSS = '';
|
||||
|
||||
success();
|
||||
});
|
||||
};
|
||||
if (config['test'])
|
||||
if (config['test']) {
|
||||
app.reload = reload;
|
||||
}
|
||||
|
||||
render = (req, res, vPath, data, code = 200) => {
|
||||
data.info = {
|
||||
@@ -100,18 +102,20 @@ module.exports = (config) => {
|
||||
} else if (err) {
|
||||
res.sendStatus(500);
|
||||
console.log(cons.error, `failed to render error page : ${err}`);
|
||||
} else
|
||||
} else {
|
||||
res.status(code).send(html);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
showError = (req, res, code) => {
|
||||
const errorPath = path.join(config['data_dir'], config['home']['error']);
|
||||
fs.access(errorPath, fs.constants.R_OK, (err) => {
|
||||
if (err)
|
||||
if (err) {
|
||||
res.sendStatus(code);
|
||||
else
|
||||
} else {
|
||||
render(req, res, errorPath, {error: code}, code);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -150,14 +154,15 @@ module.exports = (config) => {
|
||||
app.get('/', (req, res) => {
|
||||
const homePath = path.join(config['data_dir'], config['home']['index']);
|
||||
fs.access(homePath, fs.constants.R_OK, (err) => {
|
||||
if (err)
|
||||
if (err) {
|
||||
showError(req, res, 404);
|
||||
else
|
||||
} else {
|
||||
render(req, res, homePath,
|
||||
{
|
||||
articles: Object.values(articles)
|
||||
.filter(d => !d.draft).sort((a, b) => ('' + b.path).localeCompare(a.path))
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -216,8 +221,9 @@ module.exports = (config) => {
|
||||
|
||||
//rewrite urls to hide articles titles : /2019/05/05/sometitle/img.png => /2019/05/05/img.png
|
||||
app.use((req, res, next) => {
|
||||
if (/^\/\d{4}\/\d{2}\/\d{2}\//.test(req.url))
|
||||
if (/^\/\d{4}\/\d{2}\/\d{2}\//.test(req.url)) {
|
||||
req.url = req.url.slice(0, 11) + req.url.slice(req.url.lastIndexOf('/'));
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
@@ -226,9 +232,9 @@ module.exports = (config) => {
|
||||
if (/^\/\d{4}\/\d{2}\/\d{2}\/$/.test(req.path)) {
|
||||
const articlePath = req.path.substr(1, 10);
|
||||
const article = articles[articlePath];
|
||||
if (!article)
|
||||
if (!article) {
|
||||
showError(req, res, 404);
|
||||
else {
|
||||
} else {
|
||||
renderer.render(article.realPath, (err, html) => {
|
||||
if (err) {
|
||||
console.log(cons.error, `failed to render article ${req.path} : ${err}`);
|
||||
@@ -240,8 +246,9 @@ module.exports = (config) => {
|
||||
if (err) {
|
||||
console.log(cons.error, `no template found at ${templatePath}`);
|
||||
showError(req, res, 500);
|
||||
} else
|
||||
} else {
|
||||
render(req, res, templatePath, {article: article});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -272,8 +279,9 @@ module.exports = (config) => {
|
||||
//log all server errors
|
||||
app.use((err, req, res, next) => {
|
||||
console.log(cons.error, `error when handling ${req.method} ${req.path} request : ${err}`);
|
||||
if (!config['error_log'])
|
||||
if (!config['error_log']) {
|
||||
next(err);
|
||||
}
|
||||
fs.appendFile(config['error_log'],
|
||||
`500 ${req.method} ${req.url} ${new Date().toUTCString()} ${req.ips.join(' ') || req.ip}\n${err.stack}\n`,
|
||||
{encoding: 'UTF-8'}, () => {
|
||||
|
||||
+20
-10
@@ -12,25 +12,29 @@ const getFileTree = (dir, cb) => {
|
||||
let list = [];
|
||||
let remaining = 0;
|
||||
fs.readdir(dir, {withFileTypes: true}, (err, items) => {
|
||||
if (err)
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
items.forEach((item) => {
|
||||
if (item.isDirectory()) {
|
||||
remaining++;
|
||||
getFileTree(path.join(dir, item.name), (err, out) => {
|
||||
if (err)
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
list.push(...out);
|
||||
remaining--;
|
||||
if (remaining === 0)
|
||||
if (remaining === 0) {
|
||||
cb(null, list);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
list.push(path.join(dir, item.name));
|
||||
}
|
||||
});
|
||||
if (remaining === 0)
|
||||
if (remaining === 0) {
|
||||
cb(null, list);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -42,8 +46,9 @@ const getFileTree = (dir, cb) => {
|
||||
*/
|
||||
const readIndexFile = (path, thumbnailTag, cb) => {
|
||||
fs.readFile(path, {encoding: 'UTF-8'}, (err, data) => {
|
||||
if (err)
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
let info = {};
|
||||
|
||||
@@ -68,14 +73,16 @@ module.exports = (config) => {
|
||||
*/
|
||||
fetchArticles: (cb) => {
|
||||
getFileTree(config['data_dir'], (err, fileList) => {
|
||||
if (err)
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
const paths = fileList
|
||||
.map((p) => p.substr(config['data_dir'].length + 1).split(path.sep))
|
||||
.filter((p) => p.length === 4 && (p[3] === config['article']['index'] || p[3] === config['article']['draft']) &&
|
||||
/^\d{4}$/.test(p[0]) && /^\d{2}$/.test(p[1]) && /^\d{2}$/.test(p[2]));
|
||||
if (paths.length === 0)
|
||||
if (paths.length === 0) {
|
||||
cb(null, {});
|
||||
}
|
||||
const articles = {};
|
||||
let remaining = 0;
|
||||
paths.forEach((p) => {
|
||||
@@ -91,17 +98,20 @@ module.exports = (config) => {
|
||||
article.date.setUTCHours(0);
|
||||
remaining++;
|
||||
readIndexFile(article.realPath, config['article']['thumbnail_tag'], (err, info) => {
|
||||
if (err)
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
article.title = info.title || config['article']['default_title'];
|
||||
article.thumbnail = info.thumbnail ? joinUrl(article.path, info.thumbnail) : config['article']['default_thumbnail'];
|
||||
article.escapedTitle = article.title.toLowerCase().replace(/[^\w]/gm, ' ').trim().replace(/ /gm, '_');
|
||||
article.url = '/' + joinUrl(article.path, article.escapedTitle) + '/';
|
||||
if (!articles[article.path] || !article.draft)
|
||||
if (!articles[article.path] || !article.draft) {
|
||||
articles[article.path] = article;
|
||||
}
|
||||
remaining--;
|
||||
if (remaining === 0)
|
||||
if (remaining === 0) {
|
||||
cb(null, articles);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+5
-3
@@ -4,10 +4,11 @@ const ncp = require('ncp').ncp;
|
||||
|
||||
const copy = (src, dest) => {
|
||||
ncp(src, dest, function (err) {
|
||||
if (err)
|
||||
if (err) {
|
||||
console.error(err);
|
||||
else
|
||||
} else {
|
||||
console.log(`copied ${src} to ${dest}`);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -23,8 +24,9 @@ if (!fs.existsSync('data')) {
|
||||
const datetime = new Date();
|
||||
const dir = path.join('data', datetime.getFullYear().toString(), pad0(datetime.getMonth() + 1), pad0(datetime.getDate()));
|
||||
|
||||
if (!fs.existsSync(dir))
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, {recursive: true});
|
||||
}
|
||||
|
||||
copy(path.join('sample_data', 'article'), dir);
|
||||
}
|
||||
+22
-12
@@ -21,11 +21,12 @@ module.exports = (config) => {
|
||||
});
|
||||
i += match.index + match[0].length;
|
||||
}
|
||||
if (i < data.length)
|
||||
if (i < data.length) {
|
||||
parts.push({
|
||||
index: i,
|
||||
text: data.slice(i, data.length),
|
||||
});
|
||||
}
|
||||
|
||||
parts = parts.filter((p, i) => i % 2 === 0); //filter out code parts
|
||||
|
||||
@@ -40,11 +41,12 @@ module.exports = (config) => {
|
||||
});
|
||||
i += match.index + match[0].length;
|
||||
}
|
||||
if (i < p.text.length)
|
||||
if (i < p.text.length) {
|
||||
subParts.push({
|
||||
index: p.index + i,
|
||||
text: p.text.slice(i, p.text.length),
|
||||
});
|
||||
}
|
||||
parts.splice(pi, 1, ...subParts);
|
||||
});
|
||||
|
||||
@@ -59,12 +61,14 @@ module.exports = (config) => {
|
||||
};
|
||||
|
||||
let Prism;
|
||||
if (config['modules']['prism'])
|
||||
if (config['modules']['prism']) {
|
||||
Prism = require('node-prismjs');
|
||||
}
|
||||
|
||||
const renderPrism = (data, cb) => {
|
||||
if (!config['modules']['prism'])
|
||||
if (!config['modules']['prism']) {
|
||||
return cb(data);
|
||||
}
|
||||
const codeRegex = /```([\w-]+)\r?\n((?:(?!```)[\s\S])*)\r?\n```/m;
|
||||
let match;
|
||||
while ((match = codeRegex.exec(data))) {
|
||||
@@ -81,17 +85,19 @@ module.exports = (config) => {
|
||||
}
|
||||
|
||||
const renderPlantUML = (data, cb) => {
|
||||
if (!config['modules']['plantuml'])
|
||||
/* global encode64 */
|
||||
if (!config['modules']['plantuml']) {
|
||||
return cb(data);
|
||||
}
|
||||
const parts = getParts(data);
|
||||
const umlRegex = /@startuml\r?\n((?:(?!@enduml)[\s\S])*)\r?\n@enduml/m;
|
||||
let match;
|
||||
parts.forEach(part => {
|
||||
while ((match = umlRegex.exec(part.text))) {
|
||||
const code = match[1].trim();
|
||||
const s = unescape(encodeURIComponent(code)); // jshint ignore:line
|
||||
const s = unescape(encodeURIComponent(code));
|
||||
const compressed = global['zip_deflate'](s);
|
||||
const url = `http://www.plantuml.com/plantuml/${config['plantuml']['output_format']}/${encode64(compressed)}`;// jshint ignore:line
|
||||
const url = `http://www.plantuml.com/plantuml/${config['plantuml']['output_format']}/${encode64(compressed)}`;
|
||||
part.text = part.text.slice(0, match.index) + `<img alt="generated PlantUML diagram" src="${url}">` + part.text.slice(match.index + match[0].length);
|
||||
}
|
||||
data = data.slice(0, part.index) + part.text + data.slice(part.end);
|
||||
@@ -113,8 +119,9 @@ module.exports = (config) => {
|
||||
}
|
||||
|
||||
const renderMathJax = (data, cb) => {
|
||||
if (!config['modules']['mathjax'])
|
||||
if (!config['modules']['mathjax']) {
|
||||
return cb(data);
|
||||
}
|
||||
|
||||
const parts = getParts(data);
|
||||
|
||||
@@ -157,8 +164,9 @@ module.exports = (config) => {
|
||||
}
|
||||
|
||||
const renderFaDiagrams = (data, cb) => {
|
||||
if (!config['modules']['fa-diagrams'])
|
||||
if (!config['modules']['fa-diagrams']) {
|
||||
return cb(data);
|
||||
}
|
||||
const parts = getParts(data);
|
||||
const diagramsRegex = /@startfad\r?\n((?:(?!@endfad)[\s\S])*)\r?\n@endfad/m;
|
||||
let match;
|
||||
@@ -170,10 +178,11 @@ module.exports = (config) => {
|
||||
const diagData = toml.parse(code);
|
||||
const findLineBreaks = (data) => {
|
||||
Object.keys(data).forEach(key => {
|
||||
if (typeof data[key] === 'object')
|
||||
if (typeof data[key] === 'object') {
|
||||
findLineBreaks(data[key]);
|
||||
else if (typeof data[key] === 'string')
|
||||
} else if (typeof data[key] === 'string') {
|
||||
data[key] = data[key].replace(/\\n/gm, '\n');
|
||||
}
|
||||
});
|
||||
};
|
||||
findLineBreaks(diagData);
|
||||
@@ -197,8 +206,9 @@ module.exports = (config) => {
|
||||
renderFaDiagrams: config['test'] ? renderFaDiagrams : undefined,
|
||||
render: (file, cb) => {
|
||||
fs.readFile(file, {encoding: 'UTF-8'}, (err, data) => {
|
||||
if (err)
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
renderPlantUML(data, (data) => {
|
||||
renderFaDiagrams(data, (data) => {
|
||||
|
||||
+6
-7
@@ -1,4 +1,3 @@
|
||||
/* jshint -W117 */
|
||||
const request = require('supertest');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
@@ -49,13 +48,13 @@ describe('Test reload', () => {
|
||||
});
|
||||
|
||||
describe('Test request logging', () => {
|
||||
test('test no log', (done) => {
|
||||
test('no log', (done) => {
|
||||
request(app).get('/rsstest').then(() => {
|
||||
expect(fs.existsSync(path.join(dataDir, 'access.log'))).toBe(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('test get 200', (done) => {
|
||||
test('get 200', (done) => {
|
||||
config['access_log'] = path.join(dataDir, 'access.log');
|
||||
request(app).get('/rsstest').then(() => {
|
||||
fs.readFile(path.join(dataDir, 'access.log'), {encoding: 'UTF-8'}, (err, data) => {
|
||||
@@ -65,7 +64,7 @@ describe('Test request logging', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
test('test post 400', (done) => {
|
||||
test('post 400', (done) => {
|
||||
config['access_log'] = path.join(dataDir, 'access.log');
|
||||
request(app).post('/rsstest').then(() => {
|
||||
fs.readFile(path.join(dataDir, 'access.log'), {encoding: 'UTF-8'}, (err, data) => {
|
||||
@@ -75,7 +74,7 @@ describe('Test request logging', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
test('test 2 requests', (done) => {
|
||||
test('2 requests', (done) => {
|
||||
config['access_log'] = path.join(dataDir, 'access.log');
|
||||
request(app).get('/rss').then(() => {
|
||||
request(app).post('/rsstest').then(() => {
|
||||
@@ -91,14 +90,14 @@ describe('Test request logging', () => {
|
||||
});
|
||||
|
||||
describe('Test error logging', () => {
|
||||
test('test no log', (done) => {
|
||||
test('no log', (done) => {
|
||||
config['home']['index'] = null;
|
||||
request(app).get('/').then(() => {
|
||||
expect(fs.existsSync(path.join(dataDir, 'error.log'))).toBe(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('test null error ', (done) => {
|
||||
test('null error', (done) => {
|
||||
config['home']['index'] = null;
|
||||
config['error_log'] = path.join(dataDir, 'error.log');
|
||||
request(app).get('/').then(() => {
|
||||
|
||||
+4
-3
@@ -1,4 +1,3 @@
|
||||
/* jshint -W117 */
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
@@ -21,8 +20,9 @@ afterAll(() => {
|
||||
});
|
||||
|
||||
test('no config', () => {
|
||||
if (fs.existsSync(configFile))
|
||||
if (fs.existsSync(configFile)) {
|
||||
fs.unlinkSync(configFile);
|
||||
}
|
||||
expect(fs.existsSync(configFile)).toBeFalsy();
|
||||
const config = require('../src/config')();
|
||||
expect(config).toBeDefined();
|
||||
@@ -31,8 +31,9 @@ test('no config', () => {
|
||||
});
|
||||
|
||||
test('example config', () => {
|
||||
if (fs.existsSync(configFile))
|
||||
if (fs.existsSync(configFile)) {
|
||||
fs.unlinkSync(configFile);
|
||||
}
|
||||
fs.copyFileSync(path.join('src', 'config.default.json'), configFile);
|
||||
const data = fs.readFileSync(configFile, {encoding: 'UTF-8'});
|
||||
fs.writeFileSync(configFile, data.replace('3000', '3333'), {encoding: 'UTF-8'});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* jshint -W117 */
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const utils = require('./test_utils');
|
||||
|
||||
+16
-17
@@ -1,4 +1,3 @@
|
||||
/* jshint -W117 */
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const utils = require('./test_utils');
|
||||
@@ -181,9 +180,9 @@ describe('Test MathJax', () => {
|
||||
});
|
||||
test('full eq', (done) => {
|
||||
renderer.renderMathJax('$$\n\nA\n\n$$', (data) => {
|
||||
expect(data).toBe('<span class=\"mjx-chtml MJXc-display\" style=\"text-align: center;\">' +
|
||||
'<span class=\"mjx-math\"><span class=\"mjx-mrow\"><span class=\"mjx-mi\">' +
|
||||
'<span class=\"mjx-char MJXc-TeX-math-I\" style=\"padding-top: 0.519em; padding-bottom: 0.298em;\">' +
|
||||
expect(data).toBe('<span class="mjx-chtml MJXc-display" style="text-align: center;">' +
|
||||
'<span class="mjx-math"><span class="mjx-mrow"><span class="mjx-mi">' +
|
||||
'<span class="mjx-char MJXc-TeX-math-I" style="padding-top: 0.519em; padding-bottom: 0.298em;">' +
|
||||
'A' +
|
||||
'</span></span></span></span></span>');
|
||||
done();
|
||||
@@ -192,9 +191,9 @@ describe('Test MathJax', () => {
|
||||
test('inline eq', (done) => {
|
||||
renderer.renderMathJax('start $a$ end', (data) => {
|
||||
expect(data).toBe('start ' +
|
||||
'<span class=\"mjx-chtml\">' +
|
||||
'<span class=\"mjx-math\"><span class=\"mjx-mrow\"><span class=\"mjx-mi\">' +
|
||||
'<span class=\"mjx-char MJXc-TeX-math-I\" style=\"padding-top: 0.225em; padding-bottom: 0.298em;\">' +
|
||||
'<span class="mjx-chtml">' +
|
||||
'<span class="mjx-math"><span class="mjx-mrow"><span class="mjx-mi">' +
|
||||
'<span class="mjx-char MJXc-TeX-math-I" style="padding-top: 0.225em; padding-bottom: 0.298em;">' +
|
||||
'a' +
|
||||
'</span></span></span></span></span>' +
|
||||
' end');
|
||||
@@ -216,21 +215,21 @@ describe('Test MathJax', () => {
|
||||
test('multiple eq', (done) => {
|
||||
renderer.renderMathJax('$$\n\nA\n\n$$\nstart $a$ end\n$$\n\nA\n\n$$', (data) => {
|
||||
expect(data).toBe('' +
|
||||
'<span class=\"mjx-chtml MJXc-display\" style=\"text-align: center;\">' +
|
||||
'<span class=\"mjx-math\"><span class=\"mjx-mrow\"><span class=\"mjx-mi\">' +
|
||||
'<span class=\"mjx-char MJXc-TeX-math-I\" style=\"padding-top: 0.519em; padding-bottom: 0.298em;\">' +
|
||||
'<span class="mjx-chtml MJXc-display" style="text-align: center;">' +
|
||||
'<span class="mjx-math"><span class="mjx-mrow"><span class="mjx-mi">' +
|
||||
'<span class="mjx-char MJXc-TeX-math-I" style="padding-top: 0.519em; padding-bottom: 0.298em;">' +
|
||||
'A' +
|
||||
'</span></span></span></span></span>\n' +
|
||||
'start ' +
|
||||
'<span class=\"mjx-chtml\">' +
|
||||
'<span class=\"mjx-math\"><span class=\"mjx-mrow\"><span class=\"mjx-mi\">' +
|
||||
'<span class=\"mjx-char MJXc-TeX-math-I\" style=\"padding-top: 0.225em; padding-bottom: 0.298em;\">' +
|
||||
'<span class="mjx-chtml">' +
|
||||
'<span class="mjx-math"><span class="mjx-mrow"><span class="mjx-mi">' +
|
||||
'<span class="mjx-char MJXc-TeX-math-I" style="padding-top: 0.225em; padding-bottom: 0.298em;">' +
|
||||
'a' +
|
||||
'</span></span></span></span></span>' +
|
||||
' end\n' +
|
||||
'<span class=\"mjx-chtml MJXc-display\" style=\"text-align: center;\">' +
|
||||
'<span class=\"mjx-math\"><span class=\"mjx-mrow\"><span class=\"mjx-mi\">' +
|
||||
'<span class=\"mjx-char MJXc-TeX-math-I\" style=\"padding-top: 0.519em; padding-bottom: 0.298em;\">' +
|
||||
'<span class="mjx-chtml MJXc-display" style="text-align: center;">' +
|
||||
'<span class="mjx-math"><span class="mjx-mrow"><span class="mjx-mi">' +
|
||||
'<span class="mjx-char MJXc-TeX-math-I" style="padding-top: 0.519em; padding-bottom: 0.298em;">' +
|
||||
'A' +
|
||||
'</span></span></span></span></span>');
|
||||
done();
|
||||
@@ -279,7 +278,7 @@ describe('Test render', () => {
|
||||
});
|
||||
|
||||
test('normal file', (done) => {
|
||||
fs.writeFileSync(file, `# Hello`);
|
||||
fs.writeFileSync(file, '# Hello');
|
||||
renderer.render(file, (err, html) => {
|
||||
expect(err).toBeNull();
|
||||
expect(html).toBe('<h1 id="hello">Hello</h1>');
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* jshint -W117 */
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const utils = require('./test_utils');
|
||||
|
||||
+5
-3
@@ -2,14 +2,16 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const deleteFolderSync = (dir) => {
|
||||
if (!fs.existsSync(dir))
|
||||
if (!fs.existsSync(dir)) {
|
||||
return;
|
||||
}
|
||||
let items;
|
||||
const deleteItem = (item) => {
|
||||
if (item.isDirectory())
|
||||
if (item.isDirectory()) {
|
||||
deleteFolderSync(path.join(dir, item.name));
|
||||
else
|
||||
} else {
|
||||
fs.unlinkSync(path.join(dir, item.name));
|
||||
}
|
||||
};
|
||||
do {
|
||||
items = fs.readdirSync(dir, {withFileTypes: true});
|
||||
|
||||
Reference in New Issue
Block a user