karma一些笔记

一个测试运行器

为什么要

to bring a productive testing environment to developers:

01.just write the code
02.get instant feedback from tests

它是什么

01.Test on Real Devices
02.Remote Control
03.Testing Framework Agnostic
04.Easy Debugging
05.Continuous Integration
06.Open Source

如何使用

安装软件

::<<eof
npm install karma --save-dev
# 一些插件
npm install karma-jasmine karma-chrome-launcher jasmine-core --save-dev
# 检查结果
./node_modules/karma/bin/karma start
eof

配置软件

::<<eof
#生成文件
./node_modules/karma/bin/karma init my.conf.js
#2 需要哪个测试框架?
#2 是否需要模块加载?
#2 运行于哪些浏览器?
#2 源码文件放在哪里?
#2 测试文件放在哪里?
#2 需要排除哪些文件?
#2 测试时用监控模式?
#运行软件
./node_modules/karma/bin/karma start karma.conf.js
#获取帮助
./node_modules/karma/bin/karma start --help
eof

如何工作

常见问题

::<<eof
#集成测试框架?

#能够端到端测?

#集成持续集成?

#该用哪个版本?
eof

遇到问题

::<<eof
#如何进行调试?
--log-level debug
--no-single-run
#装模块出问题?

#浏览器没启动?

#有一大堆错误?
#2 http://localhost:9876/debug.html

#文件语法错误?
--log-level debug
eof

配置文件

::<<eof
#读取顺序?

#文件匹配?

#配置选项?

eof

哪些文件

The files array determines which files are included in the browser and which files are watched and served by Karma.

::<<eof

eof

何浏览器

::<<eof
# 基本结构
browsers: ['Chrome']

# 有效取值

# 某个示例
#2 安装插件
npm install karma-firefox-launcher --save-dev
#2 添加配置
module.exports = function(config) {
  config.set({
    browsers : ['Chrome', 'Firefox']
  });
};

# 域名端口

# 设发布器
sauceLabs: {
  username: 'michael_jackson'
}
# 浏端路径
#2 win-cmd:
SET IE_BIN=C:\Program Files\Internet Explorer\iexplore.exe

# 自定浏端
// in the karma.conf.js
browsers: ['/usr/local/bin/custom-browser.sh'],
// from cli
karma start --browsers /usr/local/bin/custom-browser.sh
eof

`预处理器`
```sh
::<<eof
# 基本结构
preprocessors: {
  '**/*.coffee': ['coffee'],
  '**/*.tea': ['coffee'],
  '**/*.html': ['html2js']
},

# 有效取值

# 执行顺序
preprocessors: {
  '*.js': ['a', 'b']
}

# 某个示例
#2 安装插件
npm install karma-coffee-preprocessor --save-dev
#2 添加配置
preprocessors: {
  '**/*.coffee': ['coffee'],
},
#2 设置选项
coffeePreprocessor: {
  options: {
    bare: false
  }
}
eof

软件插件

::<<eof
#安装
npm install karma-<plugin name> --save-dev

# 加载
plugins: [
  // Karma will require() these plugins
  'karma-chrome-launcher'

  // inlined plugins
  {'framework:xyz': ['factory', factoryFn]},
  require('./plugin-required-from-config')
]
eof

参考文献

karma.4.0-intro-configuration.github[p].
karma.4.0-intro-faq.github[p].
karma.4.0-config-configuration-file.github[p].
karma.4.0-config-browsers.github[p].
karma.4.0-config-preprocessors.github[p].
karma.4.0-config-plugins.github[p].
karma.4.0-plus-travis.github[p].

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 2,938评论 0 0
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,546评论 0 13
  • # Awesome Python [![Awesome](https://cdn.rawgit.com/sindr...
    emily_007阅读 2,243评论 0 3
  • 早上,为了呼吸新鲜空气,用遥控器按了电动窗帘的开关按钮,在柔和的丝丝的声音中,白色的薄纱和浅灰的厚窗帘缓缓的拉开了...
    周安柱阅读 337评论 0 0
  • 分享一个编写DAX的编辑器,网上其实也能找到,但是也分享下,我这个是在QQ群里面找的最新的,目前自己在用,但是没有...
    大鹏_Power阅读 2,864评论 4 3