Skip to content

Commit 44f8849

Browse files
committed
test: add keywords test
1 parent 9504f14 commit 44f8849

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

ORGANIZATION.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# この書籍の内容について
22

3-
## [jQuery](/ja/jQuery/README.md)
3+
## [jQuery](ja/jQuery/README.md)
44

55
jQueryのプラグインについて解説しています。
66
`<script>`タグをベースとしたプラグインアーキテクチャについて解説しています。
77

8-
## [ESLint](/ja/ESLint/README.md)
8+
## [ESLint](ja/ESLint/README.md)
99

1010
ESLintのルールを拡張する仕組みについて解説しています。
1111
ESLintではJavaScriptのコードをパースして作成されたASTを元にコードのLintを行います。
1212
実際にESLintのルールを解釈できる小さな実装を作りながらプラグインの仕組みについて学びます。
1313

14-
## [Connect](/ja/connect/README.md)
14+
## [Connect](ja/connect/README.md)
1515

1616
Connectの **middleware** と呼ばれるプラグインアーキテクチャについて解説しています。
1717
Node.js以外においても_Rack_などHTTPサーバーでよく見られるプラグインを使った階層構造について学びます。
1818

19-
## [gulp](/ja/gulp/README.md)
19+
## [gulp](ja/gulp/README.md)
2020

2121
**タスク自動化ツール** であるgulpのプラグインアーキテクチャについて解説しています。

test/keywords-test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
import {getFilePathListAsync} from "gitbook-summary-to-path";
4+
import path from "path";
5+
import fs from "fs";
6+
const rootDir = path.join(__dirname, "..");
7+
const keywordInfo = require("./keywords.json");
8+
9+
function getKeywords(matchPath) {
10+
return getFilePathListAsync(__dirname + "/../SUMMARY.md").then(fileList => {
11+
let filteredList = fileList.filter(filePath => {
12+
return filePath.indexOf(matchPath) !== -1;
13+
});
14+
return filteredList[0];
15+
}).then(filePath => {
16+
let relativePath = path.relative(rootDir, filePath);
17+
let content = fs.readFileSync(filePath, "utf-8");
18+
return {
19+
filePath,
20+
content,
21+
keywords: keywordInfo[relativePath]
22+
};
23+
});
24+
}
25+
26+
function isNotContain(content, keywords) {
27+
// 含んでないものだけを返す
28+
return keywords.filter(keyword => {
29+
return content.indexOf(keyword) === -1;
30+
});
31+
}
32+
// キーワードが書くコンテンツに含まれているかをテストする
33+
describe("keywords", function () {
34+
it("Each chapter contain the keyword", function (done) {
35+
let promises = Object.keys(keywordInfo).map(key => {
36+
return getKeywords(key).then(({filePath, content, keywords}) => {
37+
let unusedKeywords = isNotContain(content, keywords);
38+
if (unusedKeywords.length === 0) {
39+
return Promise.resolve();
40+
} else {
41+
return Promise.reject(new Error(`"${unusedKeywords.join(",")}" are not used in ${filePath}`));
42+
}
43+
});
44+
});
45+
Promise.all(promises).then(() => {
46+
done();
47+
}, done);
48+
});
49+
});

test/keywords.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"ja/jQuery/README.md": [
3+
"jQuery",
4+
"<script>"
5+
],
6+
"ja/ESLint/README.md": [
7+
"ESLint",
8+
"AST",
9+
"ルール"
10+
],
11+
"ja/connect/README.md": [
12+
"middleware",
13+
"Node.js",
14+
"Rack",
15+
"HTTPサーバー"
16+
],
17+
"ja/gulp/README.md": [
18+
"タスク自動化ツール"
19+
]
20+
}

0 commit comments

Comments
 (0)