Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nodecli): ユニットテストのセクション、目次とサンプルコード #210

Merged
merged 5 commits into from
Apr 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,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