Skip to content

Commit

Permalink
add js unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yinsang committed Sep 18, 2018
1 parent b51016f commit c003670
Show file tree
Hide file tree
Showing 23 changed files with 16,922 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*/node_modules
*/dist
*/dist
*/vue-unitTest-karma-webpack
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,14 @@ webpack、eslint需要全局npm安装

ps: mocha等单元测试的内容请上网自己搜,[阮一峰mocha](http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutorial-of-examples.html)

es6需要babel来编译,chai是断言库,mocha是测试框架
es6需要babel来编译,chai是断言库,mocha是测试框架

13. js-unitTest-karma-webpack
es6的单元测试demo
karma+mocha+webpack+chrome
坑点:
有时未报错,但是运行不成功,chrome里的debug按钮点击一下,进入debut.html 打开控制台,你就看到错误信息了!!!!!!
* files囊括需要包含的文件 例如'unit/**/*.test.js'
* preprocessors是预处理,需要用webpack进行配置
* webpack 的打包和webpack官网一致
还可以根据需求加入coverage等信息。
86 changes: 86 additions & 0 deletions js-unitTest-karma-webpack/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Karma configuration
// Generated on Tue Sep 18 2018 16:01:24 GMT+0800 (GMT+08:00)

module.exports = function(config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha'],


// list of files / patterns to load in the browser
files: [
'unit/*'
],


// list of files / patterns to exclude
exclude: [
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'unit/**/*.test.js':['webpack']
},
webpack:{
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
}
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
Loading

0 comments on commit c003670

Please sign in to comment.