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 2 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.toString());
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
21 changes: 21 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,21 @@
const assert = require("assert");
const md2html = require("../md2html");

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

<p>これはHTMLです</p>
`.trim();

describe("md2html", () => {
it("default options", () => {
const expected = `
<p>これはサンプルです。
<a href="https://asciidwango.github.io/js-primer/">https://asciidwango.github.io/js-primer/</a></p>
<p>これはHTMLです</p>
`.trim();

assert.deepStrictEqual(md2html(markdown), expected);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=== にする

});
});