javascript - karma.js 在基本 "karma init"设置后不返回任何结果

标签 javascript node.js unit-testing jasmine karma-runner

我正在关注 Egghead.io 的“Karma 简介”教程,可在此处找到 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 处于空闲状态,但不会返回任何测试结果。

编辑:添加了 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:找到解决方案。查看我自己的回复

最佳答案

您需要设置浏览器:['Chrome'],以便 Karma 自动运行您的测试。

如果您不这样做,则需要在浏览器中打开:http://localhost:9876/捕获打开的浏览器。

关于javascript - karma.js 在基本 "karma init"设置后不返回任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33927730/

相关文章:

objective-c - 单元测试自定义 UIView

javascript - Jquery UI 对话框中的 PlUpload 无法单击添加文件

javascript - 创建一个要使用的 URL,而不是多个 URL

JavaScript - 正则表达式与自定义检查

node.js - 如何在MongoDB中插入500万条记录?

javascript - 无法在 express.js 中的文件夹之间进行链接

php - 多个测试在 phing 中发生冲突

javascript - 无法使用 Select2 以编程方式选择选项

javascript - 在 angularJs 中返回请求响应

java - 适当的单元测试