eslint update
This commit is contained in:
+67
-6
@@ -1,16 +1,19 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
'plugins': ['jest'],
|
plugins: [ 'jest' ],
|
||||||
'env': {
|
env: {
|
||||||
'commonjs': true,
|
'commonjs': true,
|
||||||
'es2021': true,
|
'es2021': true,
|
||||||
'node': true,
|
'node': true,
|
||||||
'jest/globals': true,
|
'jest/globals': true,
|
||||||
},
|
},
|
||||||
'extends': ['eslint:recommended', 'plugin:jest/recommended'],
|
extends: [
|
||||||
'parserOptions': {
|
'eslint:recommended',
|
||||||
'ecmaVersion': 12,
|
'plugin:jest/recommended',
|
||||||
|
],
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 12,
|
||||||
},
|
},
|
||||||
'rules': {
|
rules: {
|
||||||
'indent': [
|
'indent': [
|
||||||
'error',
|
'error',
|
||||||
4,
|
4,
|
||||||
@@ -41,5 +44,63 @@ module.exports = {
|
|||||||
'error',
|
'error',
|
||||||
'always-multiline',
|
'always-multiline',
|
||||||
],
|
],
|
||||||
|
'complexity': 'error',
|
||||||
|
'consistent-return': 'error',
|
||||||
|
'dot-location': [
|
||||||
|
'error',
|
||||||
|
'property',
|
||||||
|
],
|
||||||
|
'eqeqeq': [
|
||||||
|
'error',
|
||||||
|
'always',
|
||||||
|
{ null: 'ignore' },
|
||||||
|
],
|
||||||
|
'no-empty-function': 'error',
|
||||||
|
'no-floating-decimal': 'error',
|
||||||
|
'no-multi-spaces': 'error',
|
||||||
|
'camelcase': [
|
||||||
|
'error',
|
||||||
|
{ properties: 'never' },
|
||||||
|
],
|
||||||
|
'comma-spacing': [
|
||||||
|
'error',
|
||||||
|
{ before: false, after: true },
|
||||||
|
],
|
||||||
|
'array-bracket-newline': [
|
||||||
|
'error',
|
||||||
|
{ multiline: true },
|
||||||
|
],
|
||||||
|
'array-element-newline': [
|
||||||
|
'error',
|
||||||
|
{ multiline: true, minItems: 2 },
|
||||||
|
],
|
||||||
|
'array-bracket-spacing': [
|
||||||
|
'error',
|
||||||
|
'always',
|
||||||
|
],
|
||||||
|
'object-curly-spacing': [
|
||||||
|
'error',
|
||||||
|
'always',
|
||||||
|
],
|
||||||
|
'comma-style': 'error',
|
||||||
|
'computed-property-spacing': 'error',
|
||||||
|
'eol-last': 'error',
|
||||||
|
'func-call-spacing': 'error',
|
||||||
|
'key-spacing': 'error',
|
||||||
|
'keyword-spacing': 'error',
|
||||||
|
'multiline-comment-style': 'error',
|
||||||
|
'newline-per-chained-call': 'error',
|
||||||
|
'no-lonely-if': 'error',
|
||||||
|
'no-multiple-empty-lines': 'error',
|
||||||
|
'no-trailing-spaces': 'error',
|
||||||
|
'no-unneeded-ternary': 'error',
|
||||||
|
'no-whitespace-before-property': 'error',
|
||||||
|
'operator-assignment': 'error',
|
||||||
|
'quote-props': [
|
||||||
|
'error',
|
||||||
|
'consistent-as-needed',
|
||||||
|
],
|
||||||
|
'space-before-blocks': 'error',
|
||||||
|
'space-infix-ops': 'error',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
+20
-12
@@ -66,8 +66,8 @@ module.exports = (config) => {
|
|||||||
fw.fetchArticles((err, dict) => {
|
fw.fetchArticles((err, dict) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(cons.error, 'error loading articles : ' + err);
|
console.error(cons.error, 'error loading articles : ' + err);
|
||||||
return error ? error() : null;
|
error();
|
||||||
}
|
} else {
|
||||||
Object.keys(articles).forEach((key) => delete articles[key]);
|
Object.keys(articles).forEach((key) => delete articles[key]);
|
||||||
Object.keys(dict).forEach((key) => articles[key] = dict[key]);
|
Object.keys(dict).forEach((key) => articles[key] = dict[key]);
|
||||||
const nb = Object.keys(articles).length;
|
const nb = Object.keys(articles).length;
|
||||||
@@ -81,6 +81,7 @@ module.exports = (config) => {
|
|||||||
lastRSS = '';
|
lastRSS = '';
|
||||||
|
|
||||||
success();
|
success();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
if (config['test']) {
|
if (config['test']) {
|
||||||
@@ -162,7 +163,8 @@ module.exports = (config) => {
|
|||||||
render(req, res, homePath,
|
render(req, res, homePath,
|
||||||
{
|
{
|
||||||
articles: Object.values(articles)
|
articles: Object.values(articles)
|
||||||
.filter(d => !d.draft).sort((a, b) => ('' + b.path).localeCompare(a.path)),
|
.filter(d => !d.draft)
|
||||||
|
.sort((a, b) => ('' + b.path).localeCompare(a.path)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -180,10 +182,10 @@ module.exports = (config) => {
|
|||||||
if (config['modules']['rss']) {
|
if (config['modules']['rss']) {
|
||||||
if (!lastRSS) {
|
if (!lastRSS) {
|
||||||
const feed = new Rss({
|
const feed = new Rss({
|
||||||
'title': config['rss']['title'],
|
title: config['rss']['title'],
|
||||||
'description': config['rss']['description'],
|
description: config['rss']['description'],
|
||||||
'feed_url': host + req.url,
|
feed_url: host + req.url,
|
||||||
'site_url': host,
|
site_url: host,
|
||||||
});
|
});
|
||||||
Object.values(articles)
|
Object.values(articles)
|
||||||
.slice(0, config['rss']['length'])
|
.slice(0, config['rss']['length'])
|
||||||
@@ -205,24 +207,29 @@ module.exports = (config) => {
|
|||||||
//webhook endpoint
|
//webhook endpoint
|
||||||
app.post(config['webhook']['endpoint'], (req, res) => {
|
app.post(config['webhook']['endpoint'], (req, res) => {
|
||||||
if (config['modules']['webhook']) {
|
if (config['modules']['webhook']) {
|
||||||
|
let valid = true;
|
||||||
if (config['webhook']['signature_header'] && config['webhook']['secret']) {
|
if (config['webhook']['signature_header'] && config['webhook']['secret']) {
|
||||||
const payload = JSON.stringify(req.body) || '';
|
const payload = JSON.stringify(req.body) || '';
|
||||||
const hmac = crypto.createHmac('sha1', config['webhook']['secret']);
|
const hmac = crypto.createHmac('sha1', config['webhook']['secret']);
|
||||||
const digest = 'sha1=' + hmac.update(payload).digest('hex');
|
const digest = 'sha1=' + hmac.update(payload).digest('hex');
|
||||||
const checksum = req.headers[config['webhook']['signature_header']];
|
const checksum = req.headers[config['webhook']['signature_header']];
|
||||||
if (!checksum || !digest || checksum !== digest) {
|
if (!checksum || !digest || checksum !== digest) {
|
||||||
return res.sendStatus(403);
|
res.sendStatus(403);
|
||||||
|
valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (valid) {
|
||||||
cp.exec(config['webhook']['pull_command'], { cwd: path.join(__dirname, '..', config['data_dir']) }, (err) => {
|
cp.exec(config['webhook']['pull_command'], { cwd: path.join(__dirname, '..', config['data_dir']) }, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(cons.error, `command '${config['webhook']['pull_command']}' failed : ${err}`);
|
console.log(cons.error, `command '${config['webhook']['pull_command']}' failed : ${err}`);
|
||||||
return res.sendStatus(500);
|
res.sendStatus(500);
|
||||||
}
|
} else {
|
||||||
reload(() => {
|
reload(() => {
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
res.sendStatus(400);
|
res.sendStatus(400);
|
||||||
}
|
}
|
||||||
@@ -254,8 +261,8 @@ module.exports = (config) => {
|
|||||||
renderer.render(article.realPath, (err, html) => {
|
renderer.render(article.realPath, (err, html) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(cons.error, `failed to render article ${req.path} : ${err}`);
|
console.log(cons.error, `failed to render article ${req.path} : ${err}`);
|
||||||
return showError(req, res, 500);
|
showError(req, res, 500);
|
||||||
}
|
} else {
|
||||||
article.content = html;
|
article.content = html;
|
||||||
const templatePath = path.join(config['data_dir'], config['article']['template']);
|
const templatePath = path.join(config['data_dir'], config['article']['template']);
|
||||||
fs.access(templatePath, fs.constants.R_OK, (err) => {
|
fs.access(templatePath, fs.constants.R_OK, (err) => {
|
||||||
@@ -266,6 +273,7 @@ module.exports = (config) => {
|
|||||||
render(req, res, templatePath, { article: article });
|
render(req, res, templatePath, { article: article });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+18
-13
@@ -13,20 +13,21 @@ const getFileTree = (dir, cb) => {
|
|||||||
let remaining = 0;
|
let remaining = 0;
|
||||||
fs.readdir(dir, { withFileTypes: true }, (err, items) => {
|
fs.readdir(dir, { withFileTypes: true }, (err, items) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
cb(err);
|
||||||
}
|
} else {
|
||||||
items.forEach((item) => {
|
items.forEach((item) => {
|
||||||
if (item.isDirectory()) {
|
if (item.isDirectory()) {
|
||||||
remaining++;
|
remaining++;
|
||||||
getFileTree(path.join(dir, item.name), (err, out) => {
|
getFileTree(path.join(dir, item.name), (err, out) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
cb(err);
|
||||||
}
|
} else {
|
||||||
list.push(...out);
|
list.push(...out);
|
||||||
remaining--;
|
remaining--;
|
||||||
if (remaining === 0) {
|
if (remaining === 0) {
|
||||||
cb(null, list);
|
cb(null, list);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
list.push(path.join(dir, item.name));
|
list.push(path.join(dir, item.name));
|
||||||
@@ -35,6 +36,7 @@ const getFileTree = (dir, cb) => {
|
|||||||
if (remaining === 0) {
|
if (remaining === 0) {
|
||||||
cb(null, list);
|
cb(null, list);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,9 +49,8 @@ const getFileTree = (dir, cb) => {
|
|||||||
const readIndexFile = (path, thumbnailTag, cb) => {
|
const readIndexFile = (path, thumbnailTag, cb) => {
|
||||||
fs.readFile(path, { encoding: 'UTF-8' }, (err, data) => {
|
fs.readFile(path, { encoding: 'UTF-8' }, (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
cb(err);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
let info = {};
|
let info = {};
|
||||||
|
|
||||||
const regRes1 = data.match(/(^|[^#])#([^#\r\n]*)\r?\n?$/m);
|
const regRes1 = data.match(/(^|[^#])#([^#\r\n]*)\r?\n?$/m);
|
||||||
@@ -60,6 +61,7 @@ const readIndexFile = (path, thumbnailTag, cb) => {
|
|||||||
info.thumbnail = regRes2 ? regRes2[1].trim() : undefined;
|
info.thumbnail = regRes2 ? regRes2[1].trim() : undefined;
|
||||||
|
|
||||||
cb(null, info);
|
cb(null, info);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -74,8 +76,8 @@ module.exports = (config) => {
|
|||||||
fetchArticles: (cb) => {
|
fetchArticles: (cb) => {
|
||||||
getFileTree(config['data_dir'], (err, fileList) => {
|
getFileTree(config['data_dir'], (err, fileList) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
cb(err);
|
||||||
}
|
} else {
|
||||||
const paths = fileList
|
const paths = fileList
|
||||||
.map((p) => p.substr(config['data_dir'].length + 1).split(path.sep))
|
.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']) &&
|
.filter((p) => p.length === 4 && (p[3] === config['article']['index'] || p[3] === config['article']['draft']) &&
|
||||||
@@ -99,11 +101,13 @@ module.exports = (config) => {
|
|||||||
remaining++;
|
remaining++;
|
||||||
readIndexFile(article.realPath, config['article']['thumbnail_tag'], (err, info) => {
|
readIndexFile(article.realPath, config['article']['thumbnail_tag'], (err, info) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
cb(err);
|
||||||
}
|
} else {
|
||||||
article.title = info.title || config['article']['default_title'];
|
article.title = info.title || config['article']['default_title'];
|
||||||
article.thumbnail = info.thumbnail ? joinUrl(article.path, info.thumbnail) : config['article']['default_thumbnail'];
|
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.escapedTitle = article.title.toLowerCase().replace(/[^\w]/gm, ' ')
|
||||||
|
.trim()
|
||||||
|
.replace(/ /gm, '_');
|
||||||
article.url = '/' + joinUrl(article.path, article.escapedTitle) + '/';
|
article.url = '/' + joinUrl(article.path, article.escapedTitle) + '/';
|
||||||
if (!articles[article.path] || !article.draft) {
|
if (!articles[article.path] || !article.draft) {
|
||||||
articles[article.path] = article;
|
articles[article.path] = article;
|
||||||
@@ -112,9 +116,10 @@ module.exports = (config) => {
|
|||||||
if (remaining === 0) {
|
if (remaining === 0) {
|
||||||
cb(null, articles);
|
cb(null, articles);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
+36
-16
@@ -67,8 +67,8 @@ module.exports = (config) => {
|
|||||||
|
|
||||||
const renderPrism = (data, cb) => {
|
const renderPrism = (data, cb) => {
|
||||||
if (!config['modules']['prism']) {
|
if (!config['modules']['prism']) {
|
||||||
return cb(data);
|
cb(data);
|
||||||
}
|
} else {
|
||||||
const codeRegex = /```([\w-]+)\r?\n((?:(?!```)[\s\S])*)\r?\n```/m;
|
const codeRegex = /```([\w-]+)\r?\n((?:(?!```)[\s\S])*)\r?\n```/m;
|
||||||
let match;
|
let match;
|
||||||
while ((match = codeRegex.exec(data))) {
|
while ((match = codeRegex.exec(data))) {
|
||||||
@@ -78,6 +78,7 @@ module.exports = (config) => {
|
|||||||
data = data.slice(0, match.index) + `<pre><code class="${lang} language-${lang}">` + block + '</code></pre>' + data.slice(match.index + match[0].length);
|
data = data.slice(0, match.index) + `<pre><code class="${lang} language-${lang}">` + block + '</code></pre>' + data.slice(match.index + match[0].length);
|
||||||
}
|
}
|
||||||
cb(data);
|
cb(data);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (config['modules']['plantuml']) {
|
if (config['modules']['plantuml']) {
|
||||||
@@ -87,8 +88,8 @@ module.exports = (config) => {
|
|||||||
const renderPlantUML = (data, cb) => {
|
const renderPlantUML = (data, cb) => {
|
||||||
/* global encode64 */
|
/* global encode64 */
|
||||||
if (!config['modules']['plantuml']) {
|
if (!config['modules']['plantuml']) {
|
||||||
return cb(data);
|
cb(data);
|
||||||
}
|
} else {
|
||||||
const parts = getParts(data);
|
const parts = getParts(data);
|
||||||
const umlRegex = /@startuml\r?\n((?:(?!@enduml)[\s\S])*)\r?\n@enduml/m;
|
const umlRegex = /@startuml\r?\n((?:(?!@enduml)[\s\S])*)\r?\n@enduml/m;
|
||||||
let match;
|
let match;
|
||||||
@@ -103,6 +104,7 @@ module.exports = (config) => {
|
|||||||
data = data.slice(0, part.index) + part.text + data.slice(part.end);
|
data = data.slice(0, part.index) + part.text + data.slice(part.end);
|
||||||
});
|
});
|
||||||
cb(data);
|
cb(data);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mjAPI;
|
let mjAPI;
|
||||||
@@ -111,8 +113,18 @@ module.exports = (config) => {
|
|||||||
mjAPI.config({
|
mjAPI.config({
|
||||||
MathJax: {
|
MathJax: {
|
||||||
tex2jax: {
|
tex2jax: {
|
||||||
inlineMath: [['$', '$']],
|
inlineMath: [
|
||||||
displayMath: [['$$', '$$']],
|
[
|
||||||
|
'$',
|
||||||
|
'$',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
displayMath: [
|
||||||
|
[
|
||||||
|
'$$',
|
||||||
|
'$$',
|
||||||
|
],
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -120,9 +132,8 @@ module.exports = (config) => {
|
|||||||
|
|
||||||
const renderMathJax = (data, cb) => {
|
const renderMathJax = (data, cb) => {
|
||||||
if (!config['modules']['mathjax']) {
|
if (!config['modules']['mathjax']) {
|
||||||
return cb(data);
|
cb(data);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
const parts = getParts(data);
|
const parts = getParts(data);
|
||||||
|
|
||||||
const doMJ = (match, format, i) => {
|
const doMJ = (match, format, i) => {
|
||||||
@@ -145,15 +156,23 @@ module.exports = (config) => {
|
|||||||
const eqRegex = /\$\$((?:(?!\$\$)[\s\S])*)\$\$/m;
|
const eqRegex = /\$\$((?:(?!\$\$)[\s\S])*)\$\$/m;
|
||||||
const inlineEqRegex = /\$([^$\n]*)\$/;
|
const inlineEqRegex = /\$([^$\n]*)\$/;
|
||||||
|
|
||||||
|
let found = false;
|
||||||
for (let i = 0; i < parts.length; i++) {
|
for (let i = 0; i < parts.length; i++) {
|
||||||
let match;
|
let match;
|
||||||
if ((match = eqRegex.exec(parts[i].text))) {
|
if ((match = eqRegex.exec(parts[i].text))) {
|
||||||
return doMJ(match, 'TeX', i);
|
doMJ(match, 'TeX', i);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
} else if ((match = inlineEqRegex.exec(parts[i].text))) {
|
} else if ((match = inlineEqRegex.exec(parts[i].text))) {
|
||||||
return doMJ(match, 'inline-TeX', i);
|
doMJ(match, 'inline-TeX', i);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!found) {
|
||||||
cb(data);
|
cb(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let faDiagrams;
|
let faDiagrams;
|
||||||
@@ -165,8 +184,8 @@ module.exports = (config) => {
|
|||||||
|
|
||||||
const renderFaDiagrams = (data, cb) => {
|
const renderFaDiagrams = (data, cb) => {
|
||||||
if (!config['modules']['fa-diagrams']) {
|
if (!config['modules']['fa-diagrams']) {
|
||||||
return cb(data);
|
cb(data);
|
||||||
}
|
} else {
|
||||||
const parts = getParts(data);
|
const parts = getParts(data);
|
||||||
const diagramsRegex = /@startfad\r?\n((?:(?!@endfad)[\s\S])*)\r?\n@endfad/m;
|
const diagramsRegex = /@startfad\r?\n((?:(?!@endfad)[\s\S])*)\r?\n@endfad/m;
|
||||||
let match;
|
let match;
|
||||||
@@ -195,6 +214,7 @@ module.exports = (config) => {
|
|||||||
data = data.slice(0, part.index) + part.text + data.slice(part.end);
|
data = data.slice(0, part.index) + part.text + data.slice(part.end);
|
||||||
});
|
});
|
||||||
cb(data);
|
cb(data);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -207,9 +227,8 @@ module.exports = (config) => {
|
|||||||
render: (file, cb) => {
|
render: (file, cb) => {
|
||||||
fs.readFile(file, { encoding: 'UTF-8' }, (err, data) => {
|
fs.readFile(file, { encoding: 'UTF-8' }, (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
cb(err);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
renderPlantUML(data, (data) => {
|
renderPlantUML(data, (data) => {
|
||||||
renderFaDiagrams(data, (data) => {
|
renderFaDiagrams(data, (data) => {
|
||||||
renderMathJax(data, (data) => {
|
renderMathJax(data, (data) => {
|
||||||
@@ -221,6 +240,7 @@ module.exports = (config) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
+88
-43
@@ -49,14 +49,16 @@ describe('Test reload', () => {
|
|||||||
|
|
||||||
describe('Test request logging', () => {
|
describe('Test request logging', () => {
|
||||||
test('no log', (done) => {
|
test('no log', (done) => {
|
||||||
request(app).get('/rsstest').then(() => {
|
request(app).get('/rsstest')
|
||||||
|
.then(() => {
|
||||||
expect(fs.existsSync(path.join(dataDir, 'access.log'))).toBe(false);
|
expect(fs.existsSync(path.join(dataDir, 'access.log'))).toBe(false);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('get 200', (done) => {
|
test('get 200', (done) => {
|
||||||
config['access_log'] = path.join(dataDir, 'access.log');
|
config['access_log'] = path.join(dataDir, 'access.log');
|
||||||
request(app).get('/rsstest').then(() => {
|
request(app).get('/rsstest')
|
||||||
|
.then(() => {
|
||||||
fs.readFile(path.join(dataDir, 'access.log'), { encoding: 'UTF-8' }, (err, data) => {
|
fs.readFile(path.join(dataDir, 'access.log'), { encoding: 'UTF-8' }, (err, data) => {
|
||||||
expect(err).toBeNull();
|
expect(err).toBeNull();
|
||||||
expect(data).toBe('200 GET /rsstest ' + new Date().toUTCString() + ' ::ffff:127.0.0.1\n');
|
expect(data).toBe('200 GET /rsstest ' + new Date().toUTCString() + ' ::ffff:127.0.0.1\n');
|
||||||
@@ -66,7 +68,8 @@ describe('Test request logging', () => {
|
|||||||
});
|
});
|
||||||
test('post 400', (done) => {
|
test('post 400', (done) => {
|
||||||
config['access_log'] = path.join(dataDir, 'access.log');
|
config['access_log'] = path.join(dataDir, 'access.log');
|
||||||
request(app).post('/rsstest').then(() => {
|
request(app).post('/rsstest')
|
||||||
|
.then(() => {
|
||||||
fs.readFile(path.join(dataDir, 'access.log'), { encoding: 'UTF-8' }, (err, data) => {
|
fs.readFile(path.join(dataDir, 'access.log'), { encoding: 'UTF-8' }, (err, data) => {
|
||||||
expect(err).toBeNull();
|
expect(err).toBeNull();
|
||||||
expect(data).toBe('400 POST /rsstest ' + new Date().toUTCString() + ' ::ffff:127.0.0.1\n');
|
expect(data).toBe('400 POST /rsstest ' + new Date().toUTCString() + ' ::ffff:127.0.0.1\n');
|
||||||
@@ -76,8 +79,10 @@ describe('Test request logging', () => {
|
|||||||
});
|
});
|
||||||
test('2 requests', (done) => {
|
test('2 requests', (done) => {
|
||||||
config['access_log'] = path.join(dataDir, 'access.log');
|
config['access_log'] = path.join(dataDir, 'access.log');
|
||||||
request(app).get('/rss').then(() => {
|
request(app).get('/rss')
|
||||||
request(app).post('/rsstest').then(() => {
|
.then(() => {
|
||||||
|
request(app).post('/rsstest')
|
||||||
|
.then(() => {
|
||||||
fs.readFile(path.join(dataDir, 'access.log'), { encoding: 'UTF-8' }, (err, data) => {
|
fs.readFile(path.join(dataDir, 'access.log'), { encoding: 'UTF-8' }, (err, data) => {
|
||||||
expect(err).toBeNull();
|
expect(err).toBeNull();
|
||||||
expect(data).toBe('404 GET /rss ' + new Date().toUTCString() + ' ::ffff:127.0.0.1\n' +
|
expect(data).toBe('404 GET /rss ' + new Date().toUTCString() + ' ::ffff:127.0.0.1\n' +
|
||||||
@@ -92,7 +97,8 @@ describe('Test request logging', () => {
|
|||||||
describe('Test error logging', () => {
|
describe('Test error logging', () => {
|
||||||
test('no log', (done) => {
|
test('no log', (done) => {
|
||||||
config['home']['index'] = null;
|
config['home']['index'] = null;
|
||||||
request(app).get('/').then(() => {
|
request(app).get('/')
|
||||||
|
.then(() => {
|
||||||
expect(fs.existsSync(path.join(dataDir, 'error.log'))).toBe(false);
|
expect(fs.existsSync(path.join(dataDir, 'error.log'))).toBe(false);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -100,10 +106,12 @@ describe('Test error logging', () => {
|
|||||||
test('null error', (done) => {
|
test('null error', (done) => {
|
||||||
config['home']['index'] = null;
|
config['home']['index'] = null;
|
||||||
config['error_log'] = path.join(dataDir, 'error.log');
|
config['error_log'] = path.join(dataDir, 'error.log');
|
||||||
request(app).get('/').then(() => {
|
request(app).get('/')
|
||||||
|
.then(() => {
|
||||||
fs.readFile(path.join(dataDir, 'error.log'), { encoding: 'UTF-8' }, (err, data) => {
|
fs.readFile(path.join(dataDir, 'error.log'), { encoding: 'UTF-8' }, (err, data) => {
|
||||||
expect(err).toBeNull();
|
expect(err).toBeNull();
|
||||||
const start = data.split('\n').slice(0, 2).join('\n');
|
const start = data.split('\n').slice(0, 2)
|
||||||
|
.join('\n');
|
||||||
const expected = '500 GET / ' + new Date().toUTCString() + ' ::ffff:127.0.0.1\nTypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string.';
|
const expected = '500 GET / ' + new Date().toUTCString() + ' ::ffff:127.0.0.1\nTypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string.';
|
||||||
expect(start.indexOf(expected)).toBe(0);
|
expect(start.indexOf(expected)).toBe(0);
|
||||||
done();
|
done();
|
||||||
@@ -114,14 +122,16 @@ describe('Test error logging', () => {
|
|||||||
|
|
||||||
describe('Test root path', () => {
|
describe('Test root path', () => {
|
||||||
test('404 no index no error', (done) => {
|
test('404 no index no error', (done) => {
|
||||||
request(app).get('/').then((response) => {
|
request(app).get('/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(404);
|
expect(response.statusCode).toBe(404);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('404 no index but error page', (done) => {
|
test('404 no index but error page', (done) => {
|
||||||
fs.writeFileSync(path.join(dataDir, testError), 'error <%= error %>');
|
fs.writeFileSync(path.join(dataDir, testError), 'error <%= error %>');
|
||||||
request(app).get('/').then((response) => {
|
request(app).get('/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(404);
|
expect(response.statusCode).toBe(404);
|
||||||
expect(response.text).toBe('error 404');
|
expect(response.text).toBe('error 404');
|
||||||
done();
|
done();
|
||||||
@@ -129,7 +139,8 @@ describe('Test root path', () => {
|
|||||||
});
|
});
|
||||||
test('500 render error', (done) => {
|
test('500 render error', (done) => {
|
||||||
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= null.length %>');
|
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= null.length %>');
|
||||||
request(app).get('/').then((response) => {
|
request(app).get('/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(500);
|
expect(response.statusCode).toBe(500);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -137,7 +148,8 @@ describe('Test root path', () => {
|
|||||||
test('500 render error with page', (done) => {
|
test('500 render error with page', (done) => {
|
||||||
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= null.length %>');
|
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= null.length %>');
|
||||||
fs.writeFileSync(path.join(dataDir, testError), 'error <%= error %>');
|
fs.writeFileSync(path.join(dataDir, testError), 'error <%= error %>');
|
||||||
request(app).get('/').then((response) => {
|
request(app).get('/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(500);
|
expect(response.statusCode).toBe(500);
|
||||||
expect(response.text).toBe('error 500');
|
expect(response.text).toBe('error 500');
|
||||||
done();
|
done();
|
||||||
@@ -146,14 +158,16 @@ describe('Test root path', () => {
|
|||||||
test('500 render error with failing page', (done) => {
|
test('500 render error with failing page', (done) => {
|
||||||
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= null.length %>');
|
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= null.length %>');
|
||||||
fs.writeFileSync(path.join(dataDir, testError), 'error <%= null.error %>');
|
fs.writeFileSync(path.join(dataDir, testError), 'error <%= null.error %>');
|
||||||
request(app).get('/').then((response) => {
|
request(app).get('/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(500);
|
expect(response.statusCode).toBe(500);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('200 no articles', (done) => {
|
test('200 no articles', (done) => {
|
||||||
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= articles.length %>');
|
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= articles.length %>');
|
||||||
request(app).get('/').then((response) => {
|
request(app).get('/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
expect(response.text).toBe('articles 0');
|
expect(response.text).toBe('articles 0');
|
||||||
done();
|
done();
|
||||||
@@ -173,7 +187,8 @@ describe('Test root path', () => {
|
|||||||
]);
|
]);
|
||||||
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= articles.length %>');
|
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= articles.length %>');
|
||||||
app.reload(() => {
|
app.reload(() => {
|
||||||
request(app).get('/').then((response) => {
|
request(app).get('/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
expect(response.text).toBe('articles 2');
|
expect(response.text).toBe('articles 2');
|
||||||
done();
|
done();
|
||||||
@@ -185,13 +200,15 @@ describe('Test root path', () => {
|
|||||||
describe('Test RSS feed', () => {
|
describe('Test RSS feed', () => {
|
||||||
test('404 rss deactivated', (done) => {
|
test('404 rss deactivated', (done) => {
|
||||||
config['modules']['rss'] = false;
|
config['modules']['rss'] = false;
|
||||||
request(app).get('/rsstest').then((response) => {
|
request(app).get('/rsstest')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(404);
|
expect(response.statusCode).toBe(404);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('200 empty rss', (done) => {
|
test('200 empty rss', (done) => {
|
||||||
request(app).get('/rsstest').then((response) => {
|
request(app).get('/rsstest')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
expect(response.type).toBe('application/rss+xml');
|
expect(response.type).toBe('application/rss+xml');
|
||||||
expect(response.text.length).toBeGreaterThan(0);
|
expect(response.text.length).toBeGreaterThan(0);
|
||||||
@@ -200,15 +217,19 @@ describe('Test RSS feed', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('200 Mozilla fix', (done) => {
|
test('200 Mozilla fix', (done) => {
|
||||||
request(app).get('/rsstest').set('user-agent', 'Mozilla Firefox 64.0').then((response) => {
|
request(app).get('/rsstest')
|
||||||
|
.set('user-agent', 'Mozilla Firefox 64.0')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
expect(response.type).toBe('text/xml');
|
expect(response.type).toBe('text/xml');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('200 rss cache', (done) => {
|
test('200 rss cache', (done) => {
|
||||||
request(app).get('/rsstest').then(() => {
|
request(app).get('/rsstest')
|
||||||
request(app).get('/rsstest').then((response) => {
|
.then(() => {
|
||||||
|
request(app).get('/rsstest')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
expect(response.text.length).toBeGreaterThan(0);
|
expect(response.text.length).toBeGreaterThan(0);
|
||||||
expect(response.text.split('<item>').length).toBe(1);
|
expect(response.text.split('<item>').length).toBe(1);
|
||||||
@@ -226,7 +247,8 @@ describe('Test RSS feed', () => {
|
|||||||
path.join(dataDir, '2018', '05', '05', 'index.md'),
|
path.join(dataDir, '2018', '05', '05', 'index.md'),
|
||||||
]);
|
]);
|
||||||
app.reload(() => {
|
app.reload(() => {
|
||||||
request(app).get('/rsstest').then((response) => {
|
request(app).get('/rsstest')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
expect(response.text.length).toBeGreaterThan(0);
|
expect(response.text.length).toBeGreaterThan(0);
|
||||||
expect(response.text.split('<item>').length).toBe(3);
|
expect(response.text.split('<item>').length).toBe(3);
|
||||||
@@ -246,7 +268,8 @@ describe('Test RSS feed', () => {
|
|||||||
path.join(dataDir, '2017', '05', '05', 'index.md'),
|
path.join(dataDir, '2017', '05', '05', 'index.md'),
|
||||||
]);
|
]);
|
||||||
app.reload(() => {
|
app.reload(() => {
|
||||||
request(app).get('/rsstest').then((response) => {
|
request(app).get('/rsstest')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
expect(response.text.length).toBeGreaterThan(0);
|
expect(response.text.length).toBeGreaterThan(0);
|
||||||
expect(response.text.split('<item>').length).toBe(3);
|
expect(response.text.split('<item>').length).toBe(3);
|
||||||
@@ -259,7 +282,8 @@ describe('Test RSS feed', () => {
|
|||||||
describe('Test webhook', () => {
|
describe('Test webhook', () => {
|
||||||
test('400 webhook deactivated', (done) => {
|
test('400 webhook deactivated', (done) => {
|
||||||
config['modules']['webhook'] = false;
|
config['modules']['webhook'] = false;
|
||||||
request(app).post('/webhooktest').then((response) => {
|
request(app).post('/webhooktest')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(400);
|
expect(response.statusCode).toBe(400);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -271,9 +295,11 @@ describe('Test webhook', () => {
|
|||||||
path.join(dataDir, testTemplate),
|
path.join(dataDir, testTemplate),
|
||||||
]);
|
]);
|
||||||
config['webhook']['pull_command'] = 'git --help';
|
config['webhook']['pull_command'] = 'git --help';
|
||||||
request(app).post('/webhooktest').then((response) => {
|
request(app).post('/webhooktest')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
request(app).get('/2019/05/05/').then((response) => {
|
request(app).get('/2019/05/05/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -286,7 +312,8 @@ describe('Test webhook', () => {
|
|||||||
path.join(dataDir, testTemplate),
|
path.join(dataDir, testTemplate),
|
||||||
]);
|
]);
|
||||||
config['webhook']['pull_command'] = 'qzgfqgqz';
|
config['webhook']['pull_command'] = 'qzgfqgqz';
|
||||||
request(app).post('/webhooktest').then((response) => {
|
request(app).post('/webhooktest')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(500);
|
expect(response.statusCode).toBe(500);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -294,7 +321,9 @@ describe('Test webhook', () => {
|
|||||||
test('403 wrong secret', (done) => {
|
test('403 wrong secret', (done) => {
|
||||||
config['webhook']['signature_header'] = 'testheader';
|
config['webhook']['signature_header'] = 'testheader';
|
||||||
config['webhook']['secret'] = 'testvalue';
|
config['webhook']['secret'] = 'testvalue';
|
||||||
request(app).post('/webhooktest').set('testheader', 'sha1=invalid').then((response) => {
|
request(app).post('/webhooktest')
|
||||||
|
.set('testheader', 'sha1=invalid')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(403);
|
expect(response.statusCode).toBe(403);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -315,7 +344,8 @@ describe('Test webhook', () => {
|
|||||||
|
|
||||||
describe('Test articles rendering', () => {
|
describe('Test articles rendering', () => {
|
||||||
test('404 article not found', (done) => {
|
test('404 article not found', (done) => {
|
||||||
request(app).get('/2019/05/06/untitled/').then((response) => {
|
request(app).get('/2019/05/06/untitled/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(404);
|
expect(response.statusCode).toBe(404);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -326,7 +356,8 @@ describe('Test articles rendering', () => {
|
|||||||
fs.writeFileSync(path.join(dataDir, '2019', '05', '05', 'index.md'), '# Hello');
|
fs.writeFileSync(path.join(dataDir, '2019', '05', '05', 'index.md'), '# Hello');
|
||||||
fs.writeFileSync(path.join(dataDir, testTemplate), '<%- articl.content %><%- `<a href="${article.url}">reload</a>` %>');
|
fs.writeFileSync(path.join(dataDir, testTemplate), '<%- articl.content %><%- `<a href="${article.url}">reload</a>` %>');
|
||||||
app.reload(() => {
|
app.reload(() => {
|
||||||
request(app).get('/2019/05/05/hello/').then((response) => {
|
request(app).get('/2019/05/05/hello/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(500);
|
expect(response.statusCode).toBe(500);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -337,7 +368,8 @@ describe('Test articles rendering', () => {
|
|||||||
utils.createEmptyDirs([ path.join(dataDir, '2019', '05', '05') ]);
|
utils.createEmptyDirs([ path.join(dataDir, '2019', '05', '05') ]);
|
||||||
fs.writeFileSync(path.join(dataDir, '2019', '05', '05', 'index.md'), '# Hello');
|
fs.writeFileSync(path.join(dataDir, '2019', '05', '05', 'index.md'), '# Hello');
|
||||||
app.reload(() => {
|
app.reload(() => {
|
||||||
request(app).get('/2019/05/05/hello/').then((response) => {
|
request(app).get('/2019/05/05/hello/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(500);
|
expect(response.statusCode).toBe(500);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -349,7 +381,8 @@ describe('Test articles rendering', () => {
|
|||||||
fs.writeFileSync(path.join(dataDir, '2019', '05', '05', 'index.md'), '# Hello');
|
fs.writeFileSync(path.join(dataDir, '2019', '05', '05', 'index.md'), '# Hello');
|
||||||
fs.writeFileSync(path.join(dataDir, testTemplate), '<%- article.content %><%- `<a href="${article.url}">reload</a>` %>');
|
fs.writeFileSync(path.join(dataDir, testTemplate), '<%- article.content %><%- `<a href="${article.url}">reload</a>` %>');
|
||||||
app.reload(() => {
|
app.reload(() => {
|
||||||
request(app).get('/2019/05/05/hello/').then((response) => {
|
request(app).get('/2019/05/05/hello/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
expect(response.text).toBe('<h1 id="hello">Hello</h1><a href="/2019/05/05/hello/">reload</a>');
|
expect(response.text).toBe('<h1 id="hello">Hello</h1><a href="/2019/05/05/hello/">reload</a>');
|
||||||
done();
|
done();
|
||||||
@@ -362,7 +395,8 @@ describe('Test articles rendering', () => {
|
|||||||
fs.writeFileSync(path.join(dataDir, '2019', '05', '05', 'draft.md'), '# Hello');
|
fs.writeFileSync(path.join(dataDir, '2019', '05', '05', 'draft.md'), '# Hello');
|
||||||
fs.writeFileSync(path.join(dataDir, testTemplate), '<%- article.content %><%- `<a href="${article.url}">reload</a>` %>');
|
fs.writeFileSync(path.join(dataDir, testTemplate), '<%- article.content %><%- `<a href="${article.url}">reload</a>` %>');
|
||||||
app.reload(() => {
|
app.reload(() => {
|
||||||
request(app).get('/2019/05/05/hello/').then((response) => {
|
request(app).get('/2019/05/05/hello/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
expect(response.text).toBe('<h1 id="hello">Hello</h1><a href="/2019/05/05/hello/">reload</a>');
|
expect(response.text).toBe('<h1 id="hello">Hello</h1><a href="/2019/05/05/hello/">reload</a>');
|
||||||
done();
|
done();
|
||||||
@@ -377,7 +411,8 @@ describe('Test articles rendering', () => {
|
|||||||
path.join(dataDir, testTemplate),
|
path.join(dataDir, testTemplate),
|
||||||
]);
|
]);
|
||||||
app.reload(() => {
|
app.reload(() => {
|
||||||
request(app).get('/2019/05/05/anything/').then((response) => {
|
request(app).get('/2019/05/05/anything/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -391,7 +426,8 @@ describe('Test articles rendering', () => {
|
|||||||
path.join(dataDir, testTemplate),
|
path.join(dataDir, testTemplate),
|
||||||
]);
|
]);
|
||||||
app.reload(() => {
|
app.reload(() => {
|
||||||
request(app).get('/2019/05/05/').then((response) => {
|
request(app).get('/2019/05/05/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -402,14 +438,16 @@ describe('Test articles rendering', () => {
|
|||||||
|
|
||||||
describe('Test static files', () => {
|
describe('Test static files', () => {
|
||||||
test('404 invalid file no error page', (done) => {
|
test('404 invalid file no error page', (done) => {
|
||||||
request(app).get('/somefile.txt').then((response) => {
|
request(app).get('/somefile.txt')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(404);
|
expect(response.statusCode).toBe(404);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('404 invalid file but error page', (done) => {
|
test('404 invalid file but error page', (done) => {
|
||||||
fs.writeFileSync(path.join(dataDir, testError), 'error <%= error %>');
|
fs.writeFileSync(path.join(dataDir, testError), 'error <%= error %>');
|
||||||
request(app).get('/somefile.txt').then((response) => {
|
request(app).get('/somefile.txt')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(404);
|
expect(response.statusCode).toBe(404);
|
||||||
expect(response.text).toBe('error 404');
|
expect(response.text).toBe('error 404');
|
||||||
done();
|
done();
|
||||||
@@ -418,7 +456,8 @@ describe('Test static files', () => {
|
|||||||
test('404 hidden file', (done) => {
|
test('404 hidden file', (done) => {
|
||||||
utils.createEmptyDirs([ path.join(dataDir, 'tmp') ]);
|
utils.createEmptyDirs([ path.join(dataDir, 'tmp') ]);
|
||||||
fs.writeFileSync(path.join(dataDir, 'tmp', 'somefile.ejs'), '');
|
fs.writeFileSync(path.join(dataDir, 'tmp', 'somefile.ejs'), '');
|
||||||
request(app).get('/tmp/somefile.ejs').then((response) => {
|
request(app).get('/tmp/somefile.ejs')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(404);
|
expect(response.statusCode).toBe(404);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -426,14 +465,16 @@ describe('Test static files', () => {
|
|||||||
test('404 hidden folder', (done) => {
|
test('404 hidden folder', (done) => {
|
||||||
utils.createEmptyDirs([ path.join(dataDir, '.git') ]);
|
utils.createEmptyDirs([ path.join(dataDir, '.git') ]);
|
||||||
fs.writeFileSync(path.join(dataDir, '.git', 'file.txt'), '');
|
fs.writeFileSync(path.join(dataDir, '.git', 'file.txt'), '');
|
||||||
request(app).get('/.git/file.txt').then((response) => {
|
request(app).get('/.git/file.txt')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(404);
|
expect(response.statusCode).toBe(404);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('200 valid file', (done) => {
|
test('200 valid file', (done) => {
|
||||||
fs.writeFileSync(path.join(dataDir, 'somefile.css'), 'filecontent');
|
fs.writeFileSync(path.join(dataDir, 'somefile.css'), 'filecontent');
|
||||||
request(app).get('/somefile.css').then((response) => {
|
request(app).get('/somefile.css')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
expect(response.type).toBe('text/css');
|
expect(response.type).toBe('text/css');
|
||||||
expect(response.text).toBe('filecontent');
|
expect(response.text).toBe('filecontent');
|
||||||
@@ -443,7 +484,8 @@ describe('Test static files', () => {
|
|||||||
test('200 valid resource of article', (done) => {
|
test('200 valid resource of article', (done) => {
|
||||||
utils.createEmptyDirs([ path.join(dataDir, '2019', '05', '05') ]);
|
utils.createEmptyDirs([ path.join(dataDir, '2019', '05', '05') ]);
|
||||||
fs.writeFileSync(path.join(dataDir, '2019', '05', '05', 'somefile.txt'), 'filecontent');
|
fs.writeFileSync(path.join(dataDir, '2019', '05', '05', 'somefile.txt'), 'filecontent');
|
||||||
request(app).get('/2019/05/05/title/somefile.txt').then((response) => {
|
request(app).get('/2019/05/05/title/somefile.txt')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
expect(response.text).toBe('filecontent');
|
expect(response.text).toBe('filecontent');
|
||||||
done();
|
done();
|
||||||
@@ -453,19 +495,22 @@ describe('Test static files', () => {
|
|||||||
|
|
||||||
describe('Test other requests', () => {
|
describe('Test other requests', () => {
|
||||||
test('400 POST', (done) => {
|
test('400 POST', (done) => {
|
||||||
request(app).post('/').then((response) => {
|
request(app).post('/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(400);
|
expect(response.statusCode).toBe(400);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('400 PUT', (done) => {
|
test('400 PUT', (done) => {
|
||||||
request(app).put('/').then((response) => {
|
request(app).put('/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(400);
|
expect(response.statusCode).toBe(400);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('400 DELETE', (done) => {
|
test('400 DELETE', (done) => {
|
||||||
request(app).delete('/').then((response) => {
|
request(app).delete('/')
|
||||||
|
.then((response) => {
|
||||||
expect(response.statusCode).toBe(400);
|
expect(response.statusCode).toBe(400);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
+8
-2
@@ -70,12 +70,18 @@ test('array parsing', () => {
|
|||||||
fs.writeFileSync(configFile, '{"home":{"hidden":["item1","item2"]}}');
|
fs.writeFileSync(configFile, '{"home":{"hidden":["item1","item2"]}}');
|
||||||
const config = require('../src/config')();
|
const config = require('../src/config')();
|
||||||
expect(config).toBeDefined();
|
expect(config).toBeDefined();
|
||||||
expect(config['home']['hidden']).toEqual(['item1', 'item2']);
|
expect(config['home']['hidden']).toEqual([
|
||||||
|
'item1',
|
||||||
|
'item2',
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('array fix', () => {
|
test('array fix', () => {
|
||||||
fs.writeFileSync(configFile, '{"home":{"hidden":{}}}');
|
fs.writeFileSync(configFile, '{"home":{"hidden":{}}}');
|
||||||
const config = require('../src/config')();
|
const config = require('../src/config')();
|
||||||
expect(config).toBeDefined();
|
expect(config).toBeDefined();
|
||||||
expect(config['home']['hidden']).toEqual(['*.ejs', '/.git*']);
|
expect(config['home']['hidden']).toEqual([
|
||||||
|
'*.ejs',
|
||||||
|
'/.git*',
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
@@ -8,14 +8,14 @@ const testIndex = 'testindex.md';
|
|||||||
const joinUrl = (...paths) => path.join(...paths).replace(/\\/g, '/');
|
const joinUrl = (...paths) => path.join(...paths).replace(/\\/g, '/');
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
'test': true,
|
test: true,
|
||||||
'data_dir': dataDir,
|
data_dir: dataDir,
|
||||||
'article': {
|
article: {
|
||||||
'index': testIndex,
|
index: testIndex,
|
||||||
'draft': 'draft.md',
|
draft: 'draft.md',
|
||||||
'default_title': 'Untitled',
|
default_title: 'Untitled',
|
||||||
'default_thumbnail': 'default.png',
|
default_thumbnail: 'default.png',
|
||||||
'thumbnail_tag': 'thumbnail',
|
thumbnail_tag: 'thumbnail',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -316,7 +316,10 @@ describe('Test article fetching', () => {
|
|||||||
const file = path.join(dir, testIndex);
|
const file = path.join(dir, testIndex);
|
||||||
const file2 = path.join(dir, 'draft.md');
|
const file2 = path.join(dir, 'draft.md');
|
||||||
utils.createEmptyDirs([ dir ]);
|
utils.createEmptyDirs([ dir ]);
|
||||||
utils.createEmptyFiles([file, file2]);
|
utils.createEmptyFiles([
|
||||||
|
file,
|
||||||
|
file2,
|
||||||
|
]);
|
||||||
const date = new Date(2019, 5, 5);
|
const date = new Date(2019, 5, 5);
|
||||||
date.setUTCHours(0);
|
date.setUTCHours(0);
|
||||||
fw.fetchArticles((err, dict) => {
|
fw.fetchArticles((err, dict) => {
|
||||||
|
|||||||
+11
-13
@@ -6,23 +6,23 @@ const dataDir = 'test_data';
|
|||||||
const file = path.join(dataDir, 'test.md');
|
const file = path.join(dataDir, 'test.md');
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
'test': true,
|
test: true,
|
||||||
'modules': {
|
modules: {
|
||||||
'prism': true,
|
'prism': true,
|
||||||
'mathjax': true,
|
'mathjax': true,
|
||||||
'plantuml': true,
|
'plantuml': true,
|
||||||
'fa-diagrams': true,
|
'fa-diagrams': true,
|
||||||
},
|
},
|
||||||
'showdown': {
|
showdown: {
|
||||||
'simplifiedAutoLink': true,
|
simplifiedAutoLink: true,
|
||||||
'smartIndentationFix': true,
|
smartIndentationFix: true,
|
||||||
},
|
},
|
||||||
'mathjax': {
|
mathjax: {
|
||||||
'output_format': 'html',
|
output_format: 'html',
|
||||||
'speak_text': false,
|
speak_text: false,
|
||||||
},
|
},
|
||||||
'plantuml': {
|
plantuml: {
|
||||||
'output_format': 'svg',
|
output_format: 'svg',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,9 +47,7 @@ describe('get parts', () => {
|
|||||||
test('normal', () => {
|
test('normal', () => {
|
||||||
const data = 'Hello\nthere\ngeneral\nkenobi';
|
const data = 'Hello\nthere\ngeneral\nkenobi';
|
||||||
const parts = renderer.getParts(data);
|
const parts = renderer.getParts(data);
|
||||||
expect(parts.map(p => p.text)).toEqual([
|
expect(parts.map(p => p.text)).toEqual([ 'Hello\nthere\ngeneral\nkenobi' ]);
|
||||||
'Hello\nthere\ngeneral\nkenobi',
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
test('lot of stuff', () => {
|
test('lot of stuff', () => {
|
||||||
const data = 'Hello\nthere\n```code```\ngeneral<script>script</script>\n<script>script2</script>\n```<script>script3</script>```kenobi';
|
const data = 'Hello\nthere\n```code```\ngeneral<script>script</script>\n<script>script2</script>\n```<script>script3</script>```kenobi';
|
||||||
|
|||||||
Reference in New Issue
Block a user