eslint update
This commit is contained in:
+67
-6
@@ -1,16 +1,19 @@
|
||||
module.exports = {
|
||||
'plugins': ['jest'],
|
||||
'env': {
|
||||
plugins: [ 'jest' ],
|
||||
env: {
|
||||
'commonjs': true,
|
||||
'es2021': true,
|
||||
'node': true,
|
||||
'jest/globals': true,
|
||||
},
|
||||
'extends': ['eslint:recommended', 'plugin:jest/recommended'],
|
||||
'parserOptions': {
|
||||
'ecmaVersion': 12,
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:jest/recommended',
|
||||
],
|
||||
parserOptions: {
|
||||
ecmaVersion: 12,
|
||||
},
|
||||
'rules': {
|
||||
rules: {
|
||||
'indent': [
|
||||
'error',
|
||||
4,
|
||||
@@ -41,5 +44,63 @@ module.exports = {
|
||||
'error',
|
||||
'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) => {
|
||||
if (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(dict).forEach((key) => articles[key] = dict[key]);
|
||||
const nb = Object.keys(articles).length;
|
||||
@@ -81,6 +81,7 @@ module.exports = (config) => {
|
||||
lastRSS = '';
|
||||
|
||||
success();
|
||||
}
|
||||
});
|
||||
};
|
||||
if (config['test']) {
|
||||
@@ -162,7 +163,8 @@ module.exports = (config) => {
|
||||
render(req, res, homePath,
|
||||
{
|
||||
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 (!lastRSS) {
|
||||
const feed = new Rss({
|
||||
'title': config['rss']['title'],
|
||||
'description': config['rss']['description'],
|
||||
'feed_url': host + req.url,
|
||||
'site_url': host,
|
||||
title: config['rss']['title'],
|
||||
description: config['rss']['description'],
|
||||
feed_url: host + req.url,
|
||||
site_url: host,
|
||||
});
|
||||
Object.values(articles)
|
||||
.slice(0, config['rss']['length'])
|
||||
@@ -205,24 +207,29 @@ module.exports = (config) => {
|
||||
//webhook endpoint
|
||||
app.post(config['webhook']['endpoint'], (req, res) => {
|
||||
if (config['modules']['webhook']) {
|
||||
let valid = true;
|
||||
if (config['webhook']['signature_header'] && config['webhook']['secret']) {
|
||||
const payload = JSON.stringify(req.body) || '';
|
||||
const hmac = crypto.createHmac('sha1', config['webhook']['secret']);
|
||||
const digest = 'sha1=' + hmac.update(payload).digest('hex');
|
||||
const checksum = req.headers[config['webhook']['signature_header']];
|
||||
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) => {
|
||||
if (err) {
|
||||
console.log(cons.error, `command '${config['webhook']['pull_command']}' failed : ${err}`);
|
||||
return res.sendStatus(500);
|
||||
}
|
||||
res.sendStatus(500);
|
||||
} else {
|
||||
reload(() => {
|
||||
res.sendStatus(200);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
res.sendStatus(400);
|
||||
}
|
||||
@@ -254,8 +261,8 @@ module.exports = (config) => {
|
||||
renderer.render(article.realPath, (err, html) => {
|
||||
if (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;
|
||||
const templatePath = path.join(config['data_dir'], config['article']['template']);
|
||||
fs.access(templatePath, fs.constants.R_OK, (err) => {
|
||||
@@ -266,6 +273,7 @@ module.exports = (config) => {
|
||||
render(req, res, templatePath, { article: article });
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
+18
-13
@@ -13,20 +13,21 @@ const getFileTree = (dir, cb) => {
|
||||
let remaining = 0;
|
||||
fs.readdir(dir, { withFileTypes: true }, (err, items) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
cb(err);
|
||||
} else {
|
||||
items.forEach((item) => {
|
||||
if (item.isDirectory()) {
|
||||
remaining++;
|
||||
getFileTree(path.join(dir, item.name), (err, out) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
cb(err);
|
||||
} else {
|
||||
list.push(...out);
|
||||
remaining--;
|
||||
if (remaining === 0) {
|
||||
cb(null, list);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
list.push(path.join(dir, item.name));
|
||||
@@ -35,6 +36,7 @@ const getFileTree = (dir, cb) => {
|
||||
if (remaining === 0) {
|
||||
cb(null, list);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -47,9 +49,8 @@ const getFileTree = (dir, cb) => {
|
||||
const readIndexFile = (path, thumbnailTag, cb) => {
|
||||
fs.readFile(path, { encoding: 'UTF-8' }, (err, data) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
cb(err);
|
||||
} else {
|
||||
let info = {};
|
||||
|
||||
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;
|
||||
|
||||
cb(null, info);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -74,8 +76,8 @@ module.exports = (config) => {
|
||||
fetchArticles: (cb) => {
|
||||
getFileTree(config['data_dir'], (err, fileList) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
cb(err);
|
||||
} else {
|
||||
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']) &&
|
||||
@@ -99,11 +101,13 @@ module.exports = (config) => {
|
||||
remaining++;
|
||||
readIndexFile(article.realPath, config['article']['thumbnail_tag'], (err, info) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
cb(err);
|
||||
} else {
|
||||
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.escapedTitle = article.title.toLowerCase().replace(/[^\w]/gm, ' ')
|
||||
.trim()
|
||||
.replace(/ /gm, '_');
|
||||
article.url = '/' + joinUrl(article.path, article.escapedTitle) + '/';
|
||||
if (!articles[article.path] || !article.draft) {
|
||||
articles[article.path] = article;
|
||||
@@ -112,9 +116,10 @@ module.exports = (config) => {
|
||||
if (remaining === 0) {
|
||||
cb(null, articles);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
+36
-16
@@ -67,8 +67,8 @@ module.exports = (config) => {
|
||||
|
||||
const renderPrism = (data, cb) => {
|
||||
if (!config['modules']['prism']) {
|
||||
return cb(data);
|
||||
}
|
||||
cb(data);
|
||||
} else {
|
||||
const codeRegex = /```([\w-]+)\r?\n((?:(?!```)[\s\S])*)\r?\n```/m;
|
||||
let match;
|
||||
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);
|
||||
}
|
||||
cb(data);
|
||||
}
|
||||
};
|
||||
|
||||
if (config['modules']['plantuml']) {
|
||||
@@ -87,8 +88,8 @@ module.exports = (config) => {
|
||||
const renderPlantUML = (data, cb) => {
|
||||
/* global encode64 */
|
||||
if (!config['modules']['plantuml']) {
|
||||
return cb(data);
|
||||
}
|
||||
cb(data);
|
||||
} else {
|
||||
const parts = getParts(data);
|
||||
const umlRegex = /@startuml\r?\n((?:(?!@enduml)[\s\S])*)\r?\n@enduml/m;
|
||||
let match;
|
||||
@@ -103,6 +104,7 @@ module.exports = (config) => {
|
||||
data = data.slice(0, part.index) + part.text + data.slice(part.end);
|
||||
});
|
||||
cb(data);
|
||||
}
|
||||
};
|
||||
|
||||
let mjAPI;
|
||||
@@ -111,8 +113,18 @@ module.exports = (config) => {
|
||||
mjAPI.config({
|
||||
MathJax: {
|
||||
tex2jax: {
|
||||
inlineMath: [['$', '$']],
|
||||
displayMath: [['$$', '$$']],
|
||||
inlineMath: [
|
||||
[
|
||||
'$',
|
||||
'$',
|
||||
],
|
||||
],
|
||||
displayMath: [
|
||||
[
|
||||
'$$',
|
||||
'$$',
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -120,9 +132,8 @@ module.exports = (config) => {
|
||||
|
||||
const renderMathJax = (data, cb) => {
|
||||
if (!config['modules']['mathjax']) {
|
||||
return cb(data);
|
||||
}
|
||||
|
||||
cb(data);
|
||||
} else {
|
||||
const parts = getParts(data);
|
||||
|
||||
const doMJ = (match, format, i) => {
|
||||
@@ -145,15 +156,23 @@ module.exports = (config) => {
|
||||
const eqRegex = /\$\$((?:(?!\$\$)[\s\S])*)\$\$/m;
|
||||
const inlineEqRegex = /\$([^$\n]*)\$/;
|
||||
|
||||
let found = false;
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
let match;
|
||||
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))) {
|
||||
return doMJ(match, 'inline-TeX', i);
|
||||
doMJ(match, 'inline-TeX', i);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
cb(data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let faDiagrams;
|
||||
@@ -165,8 +184,8 @@ module.exports = (config) => {
|
||||
|
||||
const renderFaDiagrams = (data, cb) => {
|
||||
if (!config['modules']['fa-diagrams']) {
|
||||
return cb(data);
|
||||
}
|
||||
cb(data);
|
||||
} else {
|
||||
const parts = getParts(data);
|
||||
const diagramsRegex = /@startfad\r?\n((?:(?!@endfad)[\s\S])*)\r?\n@endfad/m;
|
||||
let match;
|
||||
@@ -195,6 +214,7 @@ module.exports = (config) => {
|
||||
data = data.slice(0, part.index) + part.text + data.slice(part.end);
|
||||
});
|
||||
cb(data);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -207,9 +227,8 @@ module.exports = (config) => {
|
||||
render: (file, cb) => {
|
||||
fs.readFile(file, { encoding: 'UTF-8' }, (err, data) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
cb(err);
|
||||
} else {
|
||||
renderPlantUML(data, (data) => {
|
||||
renderFaDiagrams(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', () => {
|
||||
test('no log', (done) => {
|
||||
request(app).get('/rsstest').then(() => {
|
||||
request(app).get('/rsstest')
|
||||
.then(() => {
|
||||
expect(fs.existsSync(path.join(dataDir, 'access.log'))).toBe(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('get 200', (done) => {
|
||||
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) => {
|
||||
expect(err).toBeNull();
|
||||
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) => {
|
||||
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) => {
|
||||
expect(err).toBeNull();
|
||||
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) => {
|
||||
config['access_log'] = path.join(dataDir, 'access.log');
|
||||
request(app).get('/rss').then(() => {
|
||||
request(app).post('/rsstest').then(() => {
|
||||
request(app).get('/rss')
|
||||
.then(() => {
|
||||
request(app).post('/rsstest')
|
||||
.then(() => {
|
||||
fs.readFile(path.join(dataDir, 'access.log'), { encoding: 'UTF-8' }, (err, data) => {
|
||||
expect(err).toBeNull();
|
||||
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', () => {
|
||||
test('no log', (done) => {
|
||||
config['home']['index'] = null;
|
||||
request(app).get('/').then(() => {
|
||||
request(app).get('/')
|
||||
.then(() => {
|
||||
expect(fs.existsSync(path.join(dataDir, 'error.log'))).toBe(false);
|
||||
done();
|
||||
});
|
||||
@@ -100,10 +106,12 @@ describe('Test error logging', () => {
|
||||
test('null error', (done) => {
|
||||
config['home']['index'] = null;
|
||||
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) => {
|
||||
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.';
|
||||
expect(start.indexOf(expected)).toBe(0);
|
||||
done();
|
||||
@@ -114,14 +122,16 @@ describe('Test error logging', () => {
|
||||
|
||||
describe('Test root path', () => {
|
||||
test('404 no index no error', (done) => {
|
||||
request(app).get('/').then((response) => {
|
||||
request(app).get('/')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(404);
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('404 no index but error page', (done) => {
|
||||
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.text).toBe('error 404');
|
||||
done();
|
||||
@@ -129,7 +139,8 @@ describe('Test root path', () => {
|
||||
});
|
||||
test('500 render error', (done) => {
|
||||
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= null.length %>');
|
||||
request(app).get('/').then((response) => {
|
||||
request(app).get('/')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(500);
|
||||
done();
|
||||
});
|
||||
@@ -137,7 +148,8 @@ describe('Test root path', () => {
|
||||
test('500 render error with page', (done) => {
|
||||
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= null.length %>');
|
||||
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.text).toBe('error 500');
|
||||
done();
|
||||
@@ -146,14 +158,16 @@ describe('Test root path', () => {
|
||||
test('500 render error with failing page', (done) => {
|
||||
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= null.length %>');
|
||||
fs.writeFileSync(path.join(dataDir, testError), 'error <%= null.error %>');
|
||||
request(app).get('/').then((response) => {
|
||||
request(app).get('/')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(500);
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('200 no articles', (done) => {
|
||||
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.text).toBe('articles 0');
|
||||
done();
|
||||
@@ -173,7 +187,8 @@ describe('Test root path', () => {
|
||||
]);
|
||||
fs.writeFileSync(path.join(dataDir, testIndex), 'articles <%= articles.length %>');
|
||||
app.reload(() => {
|
||||
request(app).get('/').then((response) => {
|
||||
request(app).get('/')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.text).toBe('articles 2');
|
||||
done();
|
||||
@@ -185,13 +200,15 @@ describe('Test root path', () => {
|
||||
describe('Test RSS feed', () => {
|
||||
test('404 rss deactivated', (done) => {
|
||||
config['modules']['rss'] = false;
|
||||
request(app).get('/rsstest').then((response) => {
|
||||
request(app).get('/rsstest')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(404);
|
||||
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.type).toBe('application/rss+xml');
|
||||
expect(response.text.length).toBeGreaterThan(0);
|
||||
@@ -200,15 +217,19 @@ describe('Test RSS feed', () => {
|
||||
});
|
||||
});
|
||||
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.type).toBe('text/xml');
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('200 rss cache', (done) => {
|
||||
request(app).get('/rsstest').then(() => {
|
||||
request(app).get('/rsstest').then((response) => {
|
||||
request(app).get('/rsstest')
|
||||
.then(() => {
|
||||
request(app).get('/rsstest')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.text.length).toBeGreaterThan(0);
|
||||
expect(response.text.split('<item>').length).toBe(1);
|
||||
@@ -226,7 +247,8 @@ describe('Test RSS feed', () => {
|
||||
path.join(dataDir, '2018', '05', '05', 'index.md'),
|
||||
]);
|
||||
app.reload(() => {
|
||||
request(app).get('/rsstest').then((response) => {
|
||||
request(app).get('/rsstest')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.text.length).toBeGreaterThan(0);
|
||||
expect(response.text.split('<item>').length).toBe(3);
|
||||
@@ -246,7 +268,8 @@ describe('Test RSS feed', () => {
|
||||
path.join(dataDir, '2017', '05', '05', 'index.md'),
|
||||
]);
|
||||
app.reload(() => {
|
||||
request(app).get('/rsstest').then((response) => {
|
||||
request(app).get('/rsstest')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.text.length).toBeGreaterThan(0);
|
||||
expect(response.text.split('<item>').length).toBe(3);
|
||||
@@ -259,7 +282,8 @@ describe('Test RSS feed', () => {
|
||||
describe('Test webhook', () => {
|
||||
test('400 webhook deactivated', (done) => {
|
||||
config['modules']['webhook'] = false;
|
||||
request(app).post('/webhooktest').then((response) => {
|
||||
request(app).post('/webhooktest')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(400);
|
||||
done();
|
||||
});
|
||||
@@ -271,9 +295,11 @@ describe('Test webhook', () => {
|
||||
path.join(dataDir, testTemplate),
|
||||
]);
|
||||
config['webhook']['pull_command'] = 'git --help';
|
||||
request(app).post('/webhooktest').then((response) => {
|
||||
request(app).post('/webhooktest')
|
||||
.then((response) => {
|
||||
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);
|
||||
done();
|
||||
});
|
||||
@@ -286,7 +312,8 @@ describe('Test webhook', () => {
|
||||
path.join(dataDir, testTemplate),
|
||||
]);
|
||||
config['webhook']['pull_command'] = 'qzgfqgqz';
|
||||
request(app).post('/webhooktest').then((response) => {
|
||||
request(app).post('/webhooktest')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(500);
|
||||
done();
|
||||
});
|
||||
@@ -294,7 +321,9 @@ describe('Test webhook', () => {
|
||||
test('403 wrong secret', (done) => {
|
||||
config['webhook']['signature_header'] = 'testheader';
|
||||
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);
|
||||
done();
|
||||
});
|
||||
@@ -315,7 +344,8 @@ describe('Test webhook', () => {
|
||||
|
||||
describe('Test articles rendering', () => {
|
||||
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);
|
||||
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, testTemplate), '<%- articl.content %><%- `<a href="${article.url}">reload</a>` %>');
|
||||
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);
|
||||
done();
|
||||
});
|
||||
@@ -337,7 +368,8 @@ describe('Test articles rendering', () => {
|
||||
utils.createEmptyDirs([ path.join(dataDir, '2019', '05', '05') ]);
|
||||
fs.writeFileSync(path.join(dataDir, '2019', '05', '05', 'index.md'), '# Hello');
|
||||
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);
|
||||
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, testTemplate), '<%- article.content %><%- `<a href="${article.url}">reload</a>` %>');
|
||||
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.text).toBe('<h1 id="hello">Hello</h1><a href="/2019/05/05/hello/">reload</a>');
|
||||
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, testTemplate), '<%- article.content %><%- `<a href="${article.url}">reload</a>` %>');
|
||||
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.text).toBe('<h1 id="hello">Hello</h1><a href="/2019/05/05/hello/">reload</a>');
|
||||
done();
|
||||
@@ -377,7 +411,8 @@ describe('Test articles rendering', () => {
|
||||
path.join(dataDir, testTemplate),
|
||||
]);
|
||||
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);
|
||||
done();
|
||||
});
|
||||
@@ -391,7 +426,8 @@ describe('Test articles rendering', () => {
|
||||
path.join(dataDir, testTemplate),
|
||||
]);
|
||||
app.reload(() => {
|
||||
request(app).get('/2019/05/05/').then((response) => {
|
||||
request(app).get('/2019/05/05/')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
done();
|
||||
});
|
||||
@@ -402,14 +438,16 @@ describe('Test articles rendering', () => {
|
||||
|
||||
describe('Test static files', () => {
|
||||
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);
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('404 invalid file but error page', (done) => {
|
||||
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.text).toBe('error 404');
|
||||
done();
|
||||
@@ -418,7 +456,8 @@ describe('Test static files', () => {
|
||||
test('404 hidden file', (done) => {
|
||||
utils.createEmptyDirs([ path.join(dataDir, 'tmp') ]);
|
||||
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);
|
||||
done();
|
||||
});
|
||||
@@ -426,14 +465,16 @@ describe('Test static files', () => {
|
||||
test('404 hidden folder', (done) => {
|
||||
utils.createEmptyDirs([ path.join(dataDir, '.git') ]);
|
||||
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);
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('200 valid file', (done) => {
|
||||
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.type).toBe('text/css');
|
||||
expect(response.text).toBe('filecontent');
|
||||
@@ -443,7 +484,8 @@ describe('Test static files', () => {
|
||||
test('200 valid resource of article', (done) => {
|
||||
utils.createEmptyDirs([ path.join(dataDir, '2019', '05', '05') ]);
|
||||
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.text).toBe('filecontent');
|
||||
done();
|
||||
@@ -453,19 +495,22 @@ describe('Test static files', () => {
|
||||
|
||||
describe('Test other requests', () => {
|
||||
test('400 POST', (done) => {
|
||||
request(app).post('/').then((response) => {
|
||||
request(app).post('/')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('400 PUT', (done) => {
|
||||
request(app).put('/').then((response) => {
|
||||
request(app).put('/')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(400);
|
||||
done();
|
||||
});
|
||||
});
|
||||
test('400 DELETE', (done) => {
|
||||
request(app).delete('/').then((response) => {
|
||||
request(app).delete('/')
|
||||
.then((response) => {
|
||||
expect(response.statusCode).toBe(400);
|
||||
done();
|
||||
});
|
||||
|
||||
+8
-2
@@ -70,12 +70,18 @@ test('array parsing', () => {
|
||||
fs.writeFileSync(configFile, '{"home":{"hidden":["item1","item2"]}}');
|
||||
const config = require('../src/config')();
|
||||
expect(config).toBeDefined();
|
||||
expect(config['home']['hidden']).toEqual(['item1', 'item2']);
|
||||
expect(config['home']['hidden']).toEqual([
|
||||
'item1',
|
||||
'item2',
|
||||
]);
|
||||
});
|
||||
|
||||
test('array fix', () => {
|
||||
fs.writeFileSync(configFile, '{"home":{"hidden":{}}}');
|
||||
const config = require('../src/config')();
|
||||
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 config = {
|
||||
'test': true,
|
||||
'data_dir': dataDir,
|
||||
'article': {
|
||||
'index': testIndex,
|
||||
'draft': 'draft.md',
|
||||
'default_title': 'Untitled',
|
||||
'default_thumbnail': 'default.png',
|
||||
'thumbnail_tag': 'thumbnail',
|
||||
test: true,
|
||||
data_dir: dataDir,
|
||||
article: {
|
||||
index: testIndex,
|
||||
draft: 'draft.md',
|
||||
default_title: 'Untitled',
|
||||
default_thumbnail: 'default.png',
|
||||
thumbnail_tag: 'thumbnail',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -316,7 +316,10 @@ describe('Test article fetching', () => {
|
||||
const file = path.join(dir, testIndex);
|
||||
const file2 = path.join(dir, 'draft.md');
|
||||
utils.createEmptyDirs([ dir ]);
|
||||
utils.createEmptyFiles([file, file2]);
|
||||
utils.createEmptyFiles([
|
||||
file,
|
||||
file2,
|
||||
]);
|
||||
const date = new Date(2019, 5, 5);
|
||||
date.setUTCHours(0);
|
||||
fw.fetchArticles((err, dict) => {
|
||||
|
||||
+11
-13
@@ -6,23 +6,23 @@ const dataDir = 'test_data';
|
||||
const file = path.join(dataDir, 'test.md');
|
||||
|
||||
const config = {
|
||||
'test': true,
|
||||
'modules': {
|
||||
test: true,
|
||||
modules: {
|
||||
'prism': true,
|
||||
'mathjax': true,
|
||||
'plantuml': true,
|
||||
'fa-diagrams': true,
|
||||
},
|
||||
'showdown': {
|
||||
'simplifiedAutoLink': true,
|
||||
'smartIndentationFix': true,
|
||||
showdown: {
|
||||
simplifiedAutoLink: true,
|
||||
smartIndentationFix: true,
|
||||
},
|
||||
'mathjax': {
|
||||
'output_format': 'html',
|
||||
'speak_text': false,
|
||||
mathjax: {
|
||||
output_format: 'html',
|
||||
speak_text: false,
|
||||
},
|
||||
'plantuml': {
|
||||
'output_format': 'svg',
|
||||
plantuml: {
|
||||
output_format: 'svg',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -47,9 +47,7 @@ describe('get parts', () => {
|
||||
test('normal', () => {
|
||||
const data = 'Hello\nthere\ngeneral\nkenobi';
|
||||
const parts = renderer.getParts(data);
|
||||
expect(parts.map(p => p.text)).toEqual([
|
||||
'Hello\nthere\ngeneral\nkenobi',
|
||||
]);
|
||||
expect(parts.map(p => p.text)).toEqual([ 'Hello\nthere\ngeneral\nkenobi' ]);
|
||||
});
|
||||
test('lot of stuff', () => {
|
||||
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