Skip to content

Commit 82794c2

Browse files
committed
test(keywords): キーワードがその章以前で解説されていた場合は例外とする
先頭から順番に章で使われているキーワードを見ていき 一度使われたキーワードを対象外とする
1 parent f3445f8 commit 82794c2

File tree

4 files changed

+23
-41
lines changed

4 files changed

+23
-41
lines changed

ORGANIZATION.md

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

3+
## [Introduction](ja/introduction/README.md)
4+
5+
この書籍の目的について書かれています。
6+
なぜプラグインアーキテクチャを学ぶ必要があるのか、どのようにして学ぶことができるのかについて書かれています。
7+
38
## [jQuery](ja/jQuery/README.md)
49

510
jQueryのプラグインについて解説しています。

test/keywords-test.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
11
// LICENSE : MIT
22
"use strict";
3+
import {getKeywords} from "stemming-x-keywords";
34
import {getFilePathListAsync} from "gitbook-summary-to-path";
4-
let getKeywords = require("stemming-x-keywords").getKeywords;
55
import path from "path";
66
import fs from "fs";
77
import mdast from "mdast";
88
import parents from "unist-util-parents";
99
import select from "unist-util-select";
1010
import isUnist from "unist-util-is";
1111
import nlcstToString from "nlcst-to-string";
12-
13-
1412
const rootDir = path.join(__dirname, "..");
15-
const keywordInfo = require("./keywords.json");
16-
const Org = fs.readFileSync(__dirname + "/../ORGANIZATION.md", "utf-8");
17-
function getSummary() {
18-
if (getSummary.cache) {
19-
return Promise.resolve(getSummary.cache);
20-
}
21-
return getFilePathListAsync(__dirname + "/../SUMMARY.md").then(fileList => {
22-
getSummary.cache = fileList;
23-
return fileList;
24-
});
25-
}
26-
13+
const OrganizationText = fs.readFileSync(__dirname + "/../ORGANIZATION.md", "utf-8");
2714
function isNotContain(content, keywords) {
2815
// 含んでないものだけを返す
2916
return keywords.filter(keyword => {
@@ -50,14 +37,16 @@ function findAllAfter(ast, node, type) {
5037

5138
return results;
5239
}
40+
41+
function isAlreadyCheckKeyword(list, keyword) {
42+
return list.indexOf(keyword) !== -1;
43+
}
44+
5345
// キーワードが書くコンテンツに含まれているかをテストする
5446
describe("keywords", function () {
5547
it("Each chapter contain the keyword", function () {
56-
let ast = mdast.parse(Org);
48+
let ast = mdast.parse(OrganizationText);
5749
let headerLinks = select(parents(ast), "heading link[href]");
58-
let filePathList = headerLinks.map(link => {
59-
return path.resolve(rootDir, link.href);
60-
});
6150
let paragraphList = headerLinks.map(link => {
6251
let filePath = path.resolve(rootDir, link.href);
6352
let paragraphs = findAllAfter(ast, link.parent.node, "paragraph");
@@ -69,17 +58,25 @@ describe("keywords", function () {
6958
let keywords = paragraphs.map(p => {
7059
let text = nlcstToString(p);
7160
return getKeywords(text).then(a => {
72-
results.keywords = results.keywords.concat(a)
61+
results.keywords = results.keywords.concat(a);
7362
});
7463
});
7564
return Promise.all(keywords).then(()=> {
7665
return results;
7766
});
7867
});
7968
let promises = Promise.all(paragraphList).then(results => {
69+
let confirmedKeywords = [];
8070
return results.forEach(({filePath, content, keywords}) => {
8171
let unusedKeywords = isNotContain(content, keywords);
72+
let isChecked = isAlreadyCheckKeyword.bind(null, confirmedKeywords);
8273
if (unusedKeywords.length === 0) {
74+
// 使用済みのキーワードを登録
75+
confirmedKeywords = confirmedKeywords.concat(keywords);
76+
return;
77+
}
78+
if (unusedKeywords.every(isChecked)) {
79+
console.log(unusedKeywords.join(",") + "はチェック済み");
8380
return;
8481
}
8582
throw new Error(`"${unusedKeywords.join(",")}" are not used in ${filePath}`);

test/keywords.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/mocha.opts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
--timeout 5000
1+
--timeout 100000
22
--recursive
33
--compilers js:espower-babel/guess

0 commit comments

Comments
 (0)