Skip to content

Commit

Permalink
feat(nodecli): ユニットテストのセクション、目次とサンプルコード (#210)
Browse files Browse the repository at this point in the history
* feat(nodecli): ユニットテストのセクション、目次とサンプルコード

* chore: npm test -> mocha

* chore: use ===

* chore: レビューを受けて修正

* chore: レビュー反映
  • Loading branch information
Suguru Inatomi authored Apr 2, 2017
1 parent 3d73aaf commit 73d8192
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
- [コマンドライン引数を処理する](use-case/nodecli/argument-parse/README.md)
- [ファイルを読み込む](use-case/nodecli/read-file/README.md)
- [MarkdownをHTMLに変換する](use-case/nodecli/md-to-html/README.md)
- ユニットテストを記述する
- [ユニットテストを記述する](use-case/nodecli/refactor-and-unittest/README.md)
- TODOアプリ
14 changes: 14 additions & 0 deletions source/use-case/nodecli/refactor-and-unittest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
author: laco
---

# ユニットテストを記述する

## スクリプトをモジュールに分割する

## ユニットテスト実行環境を作る

## ユニットテストを記述する



20 changes: 20 additions & 0 deletions source/use-case/nodecli/refactor-and-unittest/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const program = require("commander");
const fs = require("fs");
const md2html = require("./md2html");

program
.option("--gfm <flag>", "GFMを有効にする")
.option("-S, --sanitize <flag>", "サニタイズを行う");

program.parse(process.argv);
const filePath = program.args[0];

fs.readFile(filePath, "utf8", (err, file) => {
if (err) {
console.error(err);
process.exit(err.code);
return;
}
const html = md2html(file, program);
console.log(html);
});
13 changes: 13 additions & 0 deletions source/use-case/nodecli/refactor-and-unittest/src/md2html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const marked = require("marked");

module.exports = (markdown, options = {}) => {
const markedOptions = Object.assign({}, {
gfm: true,
sanitize: false
}, options);

return marked(markdown, {
gfm: markedOptions.gfm,
sanitize: markedOptions.sanitize
});
};
19 changes: 19 additions & 0 deletions source/use-case/nodecli/refactor-and-unittest/src/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "nodecli",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "mocha"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"commander": "^2.9.0",
"marked": "^0.3.6"
},
"devDependencies": {
"mocha": "^3.2.0"
}
}
7 changes: 7 additions & 0 deletions source/use-case/nodecli/refactor-and-unittest/src/sample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# サンプルファイル

これはサンプルです。
https://asciidwango.github.io/js-primer/

- サンプル1
- サンプル2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>これはサンプルです。
<a href="https://asciidwango.github.io/js-primer/">https://asciidwango.github.io/js-primer/</a></p>
<p>これはHTMLです</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
これはサンプルです。
https://asciidwango.github.io/js-primer/

<p>これはHTMLです</p>
11 changes: 11 additions & 0 deletions source/use-case/nodecli/refactor-and-unittest/src/test/md2html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const md2html = require("../md2html");

it("converts Markdown to HTML", () => {
const sample = fs.readFileSync(path.resolve(__dirname, "./fixtures/sample.md"), "utf8");
const expected = fs.readFileSync(path.resolve(__dirname, "./fixtures/expected.html"), "utf8");

assert(md2html(sample) === expected);
});
2 changes: 1 addition & 1 deletion test/front-matter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("front-matter", function() {
`!${sourceDir}/README.md`,
`!${sourceDir}/OUTLINE.md`,
// サンプルコードの一部
`!${sourceDir}/use-case/nodecli/**/src/sample*.md`,
`!${sourceDir}/use-case/nodecli/**/src/**/sample*.md`,
]);
context("author", function() {
files.forEach(filePath => {
Expand Down

0 comments on commit 73d8192

Please sign in to comment.