1

我是使用 Karma 的新手,所以我可能看不到一些微不足道的东西。我有一个简单的测试,可以在 io.js 2.4.0 (Windows) 上使用这个设置正确运行:

业力.conf.js

// Karma configuration
// Generated on Thu Jul 23 2015 12:55:43 GMT+0200 (Hora de verano romance)

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', 'should'],

    plugins: ['karma-mocha',
              'karma-should',
              'karma-chrome-launcher',
              'karma-firefox-launcher'],


    // list of files / patterns to load in the browser
    files: [
      'test/**/*.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: true,


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


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

包.json

{
  "name": "mdl-sample-project",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "~1.13.1",
    "cookie-parser": "~1.3.5",
    "debug": "~2.2.0",
    "express": "^4.13.1",
    "jade": "~1.11.0",
    "morgan": "~1.6.1",
    "serve-favicon": "~2.3.0",
    "string.prototype.endswith": "^0.2.0"
  },
  "devDependencies": {
    "del": "^1.2.0",
    "gulp": "^3.9.0",
    "gulp-gzip": "^1.1.0",
    "gulp-install": "^0.4.0",
    "gulp-jshint": "^1.11.2",
    "gulp-livereload": "^3.8.0",
    "gulp-load-plugins": "^1.0.0-rc.1",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^2.0.3",
    "gulp-sourcemaps": "^1.5.2",
    "gulp-uglify": "^1.2.0",
    "jshint-stylish": "^2.0.1",
    "karma": "^0.13.3",
    "karma-chrome-launcher": "^0.2.0",
    "karma-firefox-launcher": "^0.1.6",
    "karma-mocha": "^0.2.0",
    "karma-phantomjs-launcher": "^0.2.0",
    "karma-should": "0.0.1",
    "mocha": "^2.2.5",
    "requirejs": "^2.1.19",
    "run-sequence": "^1.1.2",
    "should": "^6.0.2",
    "yargs": "^3.15.0"
  }
}

确定测试输出

24 07 2015 10:11:24.358:WARN [karma]: No captured browser, open http://localhost:9876/
24 07 2015 10:11:24.367:INFO [karma]: Karma v0.13.3 server started at http://localhost:9876/
24 07 2015 10:11:24.373:INFO [launcher]: Starting browser Chrome
24 07 2015 10:11:24.380:INFO [launcher]: Starting browser Firefox
24 07 2015 10:11:28.441:INFO [Chrome 44.0.2403 (Windows 7 0.0.0)]: Connected on socket 52Pj8cHaWNN1wGcrAAAA with id 88045217
24 07 2015 10:11:30.042:INFO [Firefox 39.0.0 (Windows 7 0.0.0)]: Connected on socket pSaobM8ZderSspd2AAAB with id 73665649
Firefox 39.0.0 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.004 secs / 0.001 secs)
Chrome 44.0.2403 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.008 secs / 0.001 secs)
TOTAL: 2 SUCCESS

但是,如果我添加urlRoot: '/__karma__/',,则会收到此错误You need to include some adapter that implements __karma__.start method!

失败测试输出:

24 07 2015 10:13:23.291:WARN [karma]: No captured browser, open http://localhost:9876/__karma__/
24 07 2015 10:13:23.301:INFO [karma]: Karma v0.13.3 server started at http://localhost:9876/__karma__/
24 07 2015 10:13:23.360:INFO [launcher]: Starting browser Chrome
24 07 2015 10:13:23.367:INFO [launcher]: Starting browser Firefox
24 07 2015 10:13:26.458:INFO [Chrome 44.0.2403 (Windows 7 0.0.0)]: Connected on socket zP_yFHB94kFtlJalAAAA with id 12198579
24 07 2015 10:13:28.496:INFO [Firefox 39.0.0 (Windows 7 0.0.0)]: Connected on socket _G3AQzXgkG9lJGKXAAAB with id 37574163
24 07 2015 10:13:28.735:WARN [web-server]: 404: /__karma__/base/node_modules/should/should.js?1fa5d1e7937262cfd609c49a24eb2e10e4864350
24 07 2015 10:13:28.737:WARN [web-server]: 404: /__karma__/base/node_modules/mocha/mocha.js?452afbc6302de4c245643397222e5d4f828605ed
24 07 2015 10:13:28.737:WARN [web-server]: 404: /__karma__/base/node_modules/karma-mocha/lib/adapter.js?e5a7345f36c47707271097c75093340dfbb3e190
24 07 2015 10:13:28.738:WARN [web-server]: 404: /__karma__/base/test/simpleTest.js?3c5c35a356cfa67ad6512d3e09d2b86a0aa4b0a0
24 07 2015 10:13:28.739:WARN [web-server]: 404: /__karma__/base/test/simpleTest.js?3c5c35a356cfa67ad6512d3e09d2b86a0aa4b0a0
Firefox 39.0.0 (Windows 7 0.0.0) ERROR
  You need to include some adapter that implements __karma__.start method!


24 07 2015 10:13:28.810:WARN [web-server]: 404: /__karma__/base/node_modules/should/should.js?1fa5d1e7937262cfd609c49a24eb2e10e4864350
24 07 2015 10:13:28.811:WARN [web-server]: 404: /__karma__/base/node_modules/mocha/mocha.js?452afbc6302de4c245643397222e5d4f828605ed
24 07 2015 10:13:28.812:WARN [web-server]: 404: /__karma__/base/node_modules/karma-mocha/lib/adapter.js?e5a7345f36c47707271097c75093340dfbb3e190
24 07 2015 10:13:28.812:WARN [web-server]: 404: /__karma__/base/test/simpleTest.js?3c5c35a356cfa67ad6512d3e09d2b86a0aa4b0a0
Chrome 44.0.2403 (Windows 7 0.0.0) ERROR
  You need to include some adapter that implements __karma__.start method!

我需要使用 urlRoot,因为我将使用代理来测试一些 DOM 交互。我已经用谷歌搜索过这个错误,但我仍然没有找到任何解决方法。

4

0 回答 0