Mocha
https://github.com/mochajs/mocha
Mocha web
https://mochajs.org/
My Node.js Setup (Mocha & Chai, Babel7, ES6)
https://dev.to/bnorbertjs/my-nodejs-setup-mocha--chai-babel7-es6-43ei
Mocha / compilers deprecation
https://github.com/mochajs/mocha/wiki/compilers-deprecation
測試框架 Mocha 實例教程
http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutorial-of-examples.html
Mocha 是一個 JavaScript 的測試框架,目的是用來管理測試的程式碼。
※若要使用Mocha測試ES6 code,需透過Babel7轉譯,於npm安裝:
npm install --save-dev @babel/cli @babel/core @babel/node @babel/register @babel/preset-env mocha
使用Babel v7編譯es6: --require @babel/register
故package.json內scripts的test需改為:
"scripts": {
"test": "mocha --require @babel/register"
},
記得.babelrc內需提供:
{
"presets": ["@babel/preset-env"]
}
但針對node_modules裡面es6的程式碼,仍得透過設定ignore=[]才能編譯:
https://babeljs.io/docs/en/babel-register
require("@babel/register")({
ignore: [],
})
但放在.babelrc內失效,變成仍得用require模組設定,導致無法全es6 import。
※可用-t或--timeout參數,改變默認的超時設置:
mocha -t 5000
※指定執行test/req目錄下面的所有js檔:
mocha test/req/*.js
※通過npm執行測試指令:
npm test
#Javascript, Mocha, Unit Test, babel, 單元測試
https://github.com/mochajs/mocha
Mocha web
https://mochajs.org/
My Node.js Setup (Mocha & Chai, Babel7, ES6)
https://dev.to/bnorbertjs/my-nodejs-setup-mocha--chai-babel7-es6-43ei
Mocha / compilers deprecation
https://github.com/mochajs/mocha/wiki/compilers-deprecation
測試框架 Mocha 實例教程
http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutorial-of-examples.html
※若要使用Mocha測試ES6 code,需透過Babel7轉譯,於npm安裝:
npm install --save-dev @babel/cli @babel/core @babel/node @babel/register @babel/preset-env mocha
使用Babel v7編譯es6: --require @babel/register
故package.json內scripts的test需改為:
"scripts": {
"test": "mocha --require @babel/register"
},
記得.babelrc內需提供:
{
"presets": ["@babel/preset-env"]
}
但針對node_modules裡面es6的程式碼,仍得透過設定ignore=[]才能編譯:
https://babeljs.io/docs/en/babel-register
require("@babel/register")({
ignore: [],
})
但放在.babelrc內失效,變成仍得用require模組設定,導致無法全es6 import。
※可用-t或--timeout參數,改變默認的超時設置:
mocha -t 5000
※指定執行test/req目錄下面的所有js檔:
mocha test/req/*.js
npm test
#Javascript, Mocha, Unit Test, babel, 單元測試
留言
張貼留言