-
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nodecli): ユニットテストのセクション、目次とサンプルコード (#210)
* feat(nodecli): ユニットテストのセクション、目次とサンプルコード * chore: npm test -> mocha * chore: use === * chore: レビューを受けて修正 * chore: レビュー反映
- Loading branch information
Suguru Inatomi
authored
Apr 2, 2017
1 parent
3d73aaf
commit 73d8192
Showing
10 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
author: laco | ||
--- | ||
|
||
# ユニットテストを記述する | ||
|
||
## スクリプトをモジュールに分割する | ||
|
||
## ユニットテスト実行環境を作る | ||
|
||
## ユニットテストを記述する | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
source/use-case/nodecli/refactor-and-unittest/src/md2html.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
source/use-case/nodecli/refactor-and-unittest/src/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# サンプルファイル | ||
|
||
これはサンプルです。 | ||
https://asciidwango.github.io/js-primer/ | ||
|
||
- サンプル1 | ||
- サンプル2 |
3 changes: 3 additions & 0 deletions
3
source/use-case/nodecli/refactor-and-unittest/src/test/fixtures/expected.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
4 changes: 4 additions & 0 deletions
4
source/use-case/nodecli/refactor-and-unittest/src/test/fixtures/sample.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
source/use-case/nodecli/refactor-and-unittest/src/test/md2html.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters