Skip to content

Commit

Permalink
refactor(npm): npm run-scriptsを整理 (asciidwango#84)
Browse files Browse the repository at this point in the history
- `npm test` から `npm run build` を外した
- Travis CIでは全てテストするようにした
- `npm run lint` と `npm run lint:fix` を追加
- ESLintの設定ファイルをjsに統一
- gulpfileを削除
- gulpにあったテストをmochaに移行
  • Loading branch information
azu authored Jul 9, 2016
1 parent 6b47967 commit 8e575f9
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 161 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"sourceType": "module"
},
"extends": [
"./config/style.eslintconfig.js"
"./config/style.eslintrc.js"
]
}
2 changes: 1 addition & 1 deletion .textlintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"rules": {
"eslint": {
"configFile": "./config/.md.eslintrc.json"
"configFile": "./config/markdown.eslintrc.js"
},
"preset-japanese": true,
"ja-no-mixed-period": true,
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
- GH_USER_EMAIL="[email protected]"
- GH_USER_NAME="azu"
script:
- npm test
- npm run travis
after_success:
- |
Expand All @@ -18,4 +18,4 @@ after_success:
--commit-message "Deploy GitBook build [skip ci]" \
--directory "_book" \
--distribution-branch "gh-pages" \
--source-branch "master"
--source-branch "master"
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

## 確認方法

`npm start`を実行後、 [http://localhost:4000/](http://localhost:4000/) へアクセスすることでプレビューを見られます。
`npm start`を実行後、[http://localhost:4000/](http://localhost:4000/)へアクセスすることでプレビューを見られます。

npm run start
# open http://localhost:4000/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ GitBookのbuildをします
GitBookのbuildかつWatchをします。
プレビューをする場合は、ローカルサーバを利用してください。

次のコマンドを実行後、 http://localhost:4000/ へアクセスすることでプレビューを見られます。
次のコマンドを実行後、[http://localhost:4000/](http://localhost:4000/)へアクセスすることでプレビューを見られます。

npm run start
# open http://localhost:4000/
Expand Down
13 changes: 0 additions & 13 deletions config/.md.eslintrc.json

This file was deleted.

13 changes: 13 additions & 0 deletions config/markdown.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
"rules": {
"no-undef": "off",
"no-unused-vars": "off",
"no-var": "off"
},
"plugins": [
"markdown"
],
"extends": [
"./style.eslintrc.js"
]
};
File renamed without changes.
134 changes: 0 additions & 134 deletions gulpfile.js

This file was deleted.

15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
"prepublish": "gitbook install",
"start": "gitbook serve",
"build": "gitbook build",
"eslint:js": "eslint source/",
"eslint": "eslint source/",
"eslint:fix": "eslint --fix source/",
"textlint": "gulp textlint",
"textlint": "summary-to-path ./source/README.md | xargs textlint -f pretty-error",
"textlint:fix": "summary-to-path ./source/README.md | xargs textlint --fix",
"test:example": "gulp test:example test:invalid test:doc-code",
"lint": "npm-run-all --parallel textlint eslint",
"lint:fix": "npm-run-all --parallel textlint:fix eslint:fix",
"test:example": "mocha test/",
"test:basic": "mocha './source/basic/**/*-test.js'",
"test:ajaxapp": "mocha './source/ajaxapp/**/*-test.js'",
"test": "npm-run-all -l --parallel test:* textlint eslint:* build"
"test": "npm-run-all -l --parallel test:* lint",
"travis": "npm-run-all -l --parallel test build"
},
"keywords": [
"gitbook",
Expand All @@ -39,9 +42,7 @@
"gitbook-plugin-include-codeblock": "^1.4.0",
"gitbook-plugin-japanese-support": "0.0.1",
"gitbook-summary-to-path": "^1.0.1",
"gulp": "^3.9.0",
"gulp-textlint": "^2.0.1",
"gulp-util": "^3.0.7",
"globby": "^5.0.0",
"mocha": "^2.2.5",
"npm-run-all": "^2.3.0",
"power-assert": "^1.3.1",
Expand Down
1 change: 0 additions & 1 deletion source/basic/data-type/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ JavaScriptにおいてあらゆるものの基礎となるのがオブジェク

```js
var object = {}; // 中身が空のオブジェクトを作成
console.log(object); // => {}
```

オブジェクトリテラルはオブジェクトの作成と同時に中身を定義することができます。
Expand Down
34 changes: 34 additions & 0 deletions test/example-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// LICENSE : MIT
"use strict";
const assert = require("power-assert");
const globby = require('globby');
const fs = require("fs");
const path = require("path");
const strictEval = require("strict-eval");
const sourceDir = path.join(__dirname, "..", "source");
const toDoc = require("power-doctest");
/**
* *-example.js を実行しdoctestを行う
* a // => "aの評価結果"
* が一致するかのdoctestを行う
* 詳細は CONTRIBUTING.md を見る
**/
describe("doctest:js", function() {
const files = globby.sync([`${sourceDir}/**/*-example.js`, `!${sourceDir}/**/node_modules{,/**}`]);
files.forEach(filePath => {
const normalizeFilePath = filePath.replace(sourceDir, "");
it(`can eval ${normalizeFilePath}`, function(done) {
const content = fs.readFileSync(filePath, "utf-8");
try {
const powerCode = toDoc.convertCode(content, filePath);
strictEval(powerCode);
done();
} catch (error) {
// Stack Trace like
console.error(`StrictEvalError: strict eval is failed
at strictEval (${filePath}:1:1)`);
done(error);
}
});
});
});
30 changes: 30 additions & 0 deletions test/invalid-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// LICENSE : MIT
"use strict";
const assert = require("power-assert");
const globby = require('globby');
const fs = require("fs");
const path = require("path");
const strictEval = require("strict-eval");
const sourceDir = path.join(__dirname, "..", "source");
/**
* `*-invalid.js` が実行 または パースエラーとなることをテストする
**/
describe("invalid:js", function() {
const files = globby.sync([`${sourceDir}/**/*-invalid.js`, `!${sourceDir}/**/node_modules{,/**}`]);
files.forEach(filePath => {
const normalizeFilePath = filePath.replace(sourceDir, "");
it(`Should be invalid ${normalizeFilePath}`, function() {
const content = fs.readFileSync(filePath, "utf-8");
try {
strictEval(content);
throw new Error("NO_REACH_CODE");
} catch (error) {
// evalしようとしたらエラーになっていることが期待値
// "NO_REACH_CODE"になってるのはおかしい
assert.notEqual(error.message, "NO_REACH_CODE", `Should be SyntaxError(parse error) or EvalError: ${error.message}
Please check it:
at NotError (${filePath}:1:1)\n`);
}
});
});
});
49 changes: 49 additions & 0 deletions test/markdown-doc-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// LICENSE : MIT
"use strict";
const assert = require("power-assert");
const globby = require('globby');
const fs = require("fs");
const path = require("path");
const strictEval = require("strict-eval");
const sourceDir = path.join(__dirname, "..", "source");
const toDoc = require("power-doctest");
const remark = require("remark")();
const select = require('unist-util-select');

/**
* Markdownファイルの CodeBlock に対してdoctestを行う
* CodeBlockは必ず実行できるとは限らないので、
* AssertionError(doctestにおける失敗)以外は成功したことにして無視する
* 詳細は CONTRIBUTING.md を読む
**/
describe("doctest:md", function() {
const files = globby.sync([`${sourceDir}/**/*.md`, `!${sourceDir}/**/node_modules{,/**}`]);
files.forEach(filePath => {
const normalizeFilePath = filePath.replace(sourceDir, "");
it(`can eval ${normalizeFilePath}`, function() {
const content = fs.readFileSync(filePath, "utf-8");
const markdownAST = remark.parse(content);
const codeBlocks = [].concat(select(markdownAST, 'code[lang="js"]'), select(markdownAST, 'code[lang="javascript"]'));
const codes = codeBlocks.map(codeBlock => {
return codeBlock.value;
}).filter(code => code.length > 0);
// try to eval
codes.forEach(code => {
try {
const poweredCode = toDoc.convertCode(code, filePath);
strictEval(poweredCode);
} catch (error) {
// AssertionError以外は無視する
if (error.name !== "AssertionError") {
return;
}
// Stack Trace like
console.info(code);
console.error(`StrictEvalError: strict eval is failed
at strictEval (${filePath}:1:1)`);
throw error;
}
});
});
});
});

0 comments on commit 8e575f9

Please sign in to comment.