Skip to content

Commit 40a86dd

Browse files
committed
refactor(test): spilit functions
1 parent ee6edfc commit 40a86dd

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

Diff for: test/keywords-test.js

+20-14
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,31 @@ function isAlreadyCheckKeyword(list, keyword) {
4242
return list.indexOf(keyword) !== -1;
4343
}
4444

45-
function checkKeyword(text){
45+
// P ASTからキーワードを抽出する
46+
function getKeywordsOfParagraphsAsync(paragraphs) {
47+
let _keywords = [];
48+
let promiseList = paragraphs.map(p => {
49+
let text = nlcstToString(p);
50+
return getKeywords(text).then(keywords => {
51+
_keywords = _keywords.concat(keywords);
52+
});
53+
});
54+
return Promise.all(promiseList).then(()=> {
55+
return _keywords;
56+
});
57+
}
58+
function checkKeyword(text) {
4659
let ast = mdast.parse(text);
4760
let headerLinks = select(parents(ast), "heading link[href]");
4861
let paragraphList = headerLinks.map(link => {
4962
let filePath = path.resolve(rootDir, link.href);
5063
let paragraphs = findAllAfter(ast, link.parent.node, "paragraph");
51-
let results = {
52-
filePath: filePath,
53-
content: fs.readFileSync(filePath, "utf-8"),
54-
keywords: []
55-
};
56-
let keywords = paragraphs.map(p => {
57-
let text = nlcstToString(p);
58-
return getKeywords(text).then(a => {
59-
results.keywords = results.keywords.concat(a);
60-
});
61-
});
62-
return Promise.all(keywords).then(()=> {
63-
return results;
64+
return getKeywordsOfParagraphsAsync(paragraphs).then(keywords => {
65+
return {
66+
filePath: filePath,
67+
content: fs.readFileSync(filePath, "utf-8"),
68+
keywords: keywords
69+
};
6470
});
6571
});
6672
return Promise.all(paragraphList).then(results => {

0 commit comments

Comments
 (0)