forked from asciidwango/js-primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(npm): npm run-scriptsを整理 (asciidwango#84)
- `npm test` から `npm run build` を外した - Travis CIでは全てテストするようにした - `npm run lint` と `npm run lint:fix` を追加 - ESLintの設定ファイルをjsに統一 - gulpfileを削除 - gulpにあったテストをmochaに移行
- Loading branch information
Showing
14 changed files
with
140 additions
and
161 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,6 @@ | |
"sourceType": "module" | ||
}, | ||
"extends": [ | ||
"./config/style.eslintconfig.js" | ||
"./config/style.eslintrc.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
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ env: | |
- GH_USER_EMAIL="[email protected]" | ||
- GH_USER_NAME="azu" | ||
script: | ||
- npm test | ||
- npm run travis | ||
after_success: | ||
- | | ||
|
@@ -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" |
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
This file was deleted.
Oops, something went wrong.
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 @@ | ||
module.exports = { | ||
"rules": { | ||
"no-undef": "off", | ||
"no-unused-vars": "off", | ||
"no-var": "off" | ||
}, | ||
"plugins": [ | ||
"markdown" | ||
], | ||
"extends": [ | ||
"./style.eslintrc.js" | ||
] | ||
}; |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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
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,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); | ||
} | ||
}); | ||
}); | ||
}); |
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,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`); | ||
} | ||
}); | ||
}); | ||
}); |
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,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; | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |