karma.js在基本的“;因果报应;设置
karma.js not returning any results following basic "karma init" setup
我正在学习egghead.io的"因果报应入门"教程https://egghead.io/lessons/unit-testing-introduction-to-karma,并遵循以下内容(在Windows上):
> npm install --g karma-cli
> npm install karma karma-jasmine karma-chrome-launcher --save-dev
karma init
遵循初始karma配置的默认配置,然后在当前文件夹中创建一个test.spec.js文件,代码如下:
describe('Test', function() {
it('It should be true', function() { expect(true).toBe(true); });
});
最后,我在karma.conf.js文件中添加了这样的文件:
files: [
'test.spec.js'
],
但是,在运行时
karma start karma.conf.js
我只得到一个:
25 11 2015 16:35:35.551:INFO [karma]: Karma v0.13.15 server started at http://localhost:9876/
为什么不执行任何测试?此外,打开localhost url(这与在karma.conf.js中将浏览器设置为['chrome']相同)只会显示karma正在运行,chrome处于空闲状态,但不会返回任何测试结果。
edit:添加了karma.conf.js
// Karma configuration
// Generated on Wed Nov 25 2015 16:19:43 GMT-0600 (Central Standard Time (Mexico))
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: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'*spec.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// 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: [],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultanous
concurrency: Infinity
})
}
edit2:添加了package.json
{
"name": "karma-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "karma start karma.conf.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"jasmine-core": "^2.3.4",
"karma": "^0.13.15",
"karma-chrome-launcher": "^0.2.1",
"karma-jasmine": "^0.3.6"
}
}
edit3:找到了一个解决方案。查看我自己的回复
您需要为Karma设置browsers : ['Chrome']
,以便自动运行测试。
如果你不这样做,你需要在浏览器中打开它:http://localhost:9876/以捕获打开的浏览器。
找到了解决方案,或者有点。我似乎不得不按下localhost:9876url上的大"DEBUG"按钮,打开chrome控制台并在那里找到结果。这非常令人困惑,我希望业力医生告诉我。现在我们只需要一种在窗口控制台中显示结果的方法
编辑
修复了它……我很惊讶这能修复它。不管怎样,我们终于在karma.conf.js和打开中将autoWatch设置为true(它是false),得到了正确的输出http://localhost:9876.我仍然很困惑,我使用了不需要浏览器的无头测试,但我稍后会对此进行研究。我猜这是为了让调试更容易。
- 为什么不'当单元测试出现解析错误时,我的因果报应测试会失败
- 因果报应-找不到模块:错误:无法解析模块'scs'
- 如何将因果报应测试报告上传到声纳
- 因果报应,幻影JS和es6承诺
- AngularJS因果报应测试规范承诺未解析,且未调用.then()
- 如何使用console.log在因果报应测试中检查函数
- $routeUpdate未在角因果报应单元测试中广播
- 因果报应测试
- 通过因果报应测试管理angularjs控制器初始化
- 因果报应并没有执行测试用例
- ngRoute不是因果报应实例化的
- 巴贝尔/因果报应/柴给出类型错误:'呼叫者''被叫',和'自变量'在严格模
- 因果报应-如何指向类型脚本覆盖的源地图
- 无法让因果报应运行我的Angular2测试
- 如何用新版本的因果报应取代被弃用的吞咽因果报应
- 将角度控制器添加到因果报应覆盖(伊斯坦布尔)代码覆盖预处理器
- 节点包因果报应没有在没有信息的情况下运行
- 因果报应单元测试'未定义'不是函数错误
- karma.js在基本的“;因果报应;设置
- 如何在角度单元测试中设置html5Mode?利用因果报应