麻烦设置karma-cordova(Linux)

时间:2015-10-30 16:37:33

标签: linux cordova karma-jasmine

第一次在业力或linux上做任何事情,如果我犯了一个明显的错误,请原谅我。

尝试使用cordova对karma-jasmine进行基本测试。

在业力开始时,我收到以下错误日志:

30 10 2015 17:33:28.644:WARN [karma]: No captured browser, open http://localhost:9876/ 30 10 2015 17:33:28.651:INFO [karma]: Karma v0.13.14 server started at http://localhost:9876/ using settings: { platforms: [ 'android', 'ios' ], mode: 'emulate', hostip: '10.0.2.2', target: '0468de2a213eae29', plugins: [ 'org.apache.cordova.console' ] } 30 10 2015 17:33:28.654:INFO [launcher]: Starting browser undefined on Cordova 30 10 2015 17:33:28.655:ERROR [launcher]: [TypeError: Object undefined on Cordova has no method 'on'] TypeError: Object undefined on Cordova has no method 'on' at /home/phil/node_modules/karma/lib/launcher.js:94:17 at next (/home/phil/node_modules/karma/node_modules/batch/index.js:118:7) at Batch.end (/home/phil/node_modules/karma/node_modules/batch/index.js:154:5) at launch (/home/phil/node_modules/karma/lib/launcher.js:110:11) at invoke (/home/phil/node_modules/karma/node_modules/di/lib/injector.js:75:15) at Server.<anonymous> (/home/phil/node_modules/karma/lib/server.js:170:24) at Server.g (events.js:180:16) at Server.emit (events.js:92:17) at net.js:1056:10 at process._tickCallback (node.js:448:13) [spawn] stdout: Fetching plugin "org.apache.cordova.console" via npm [spawn] stdout: WARNING: org.apache.cordova.console has been renamed to cordova-plugin-console. You may not be getting the latest version! We suggest you cordova插件rm org.apache.cordova.console and cordova插件添加cordova-plugin-console . Fetching plugin "org.apache.cordova.console" via cordova plugins registry [spawn] stdout: Plugin "org.apache.cordova.console" already installed on android. [spawn] stdout: Plugin "org.apache.cordova.console" already installed on ios. [spawn] stderr: Platform android already added. [spawn] stdout: WARNING: Applications for platform ios can not be built on this OS - linux. [spawn] stderr: Platform ios already added. Done adding platforms [spawn] stdout: Running command: /tmp/cordova_test/platforms/android/cordova/build [spawn] stderr: [Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually. Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.] [spawn] stdout: ERROR building one of the platforms: Error: /tmp/cordova_test/platforms/android/cordova/build: Command failed with exit code 2 You may not have the required environment or OS to build this project [spawn] stderr: Error: /tmp/cordova_test/platforms/android/cordova/build: Command failed with exit code 2 at ChildProcess.whenDone (/root/.nvm/v0.10.40/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23) at ChildProcess.emit (events.js:98:17) at maybeClose (child_process.js:766:16) at Process.ChildProcess._handle.onexit (child_process.js:833:5) 30 10 2015 17:33:34.455:ERROR [launcher.cordova]: "cordova build" failed with code 1

下面是我的karma.conf.js文件:

    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: [
      '*.js',
      'test/test1/test1.js'
    ],


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


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preproces                                                                                                                                                             sor
    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_WAR                                                                                                                                                             N || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file chan                                                                                                                                                             ges
    autoWatch: true,


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

    cordovaSettings: {
        platforms:['android', 'ios'],
        mode: 'emulate',
        hostip: '10.0.2.2',
        target :'0468de2a213eae29',
        plugins: ['org.apache.cordova.console']
        },

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

    plugins: [
        'karma-cordova-launcher',
        'karma-jasmine',
        'karma-cordova-launcher'
        ],

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

任何建议表示赞赏,欢呼!

1 个答案:

答案 0 :(得分:0)

似乎运行karma的用户没有设置ANDROID_HOME环境变量。

尝试打开终端并输入:

export ANDROID_HOME=/path/to/your/android/sdk 
export PATH=$PATH:$ANDROID_HOME/bin

您还可以将这些行添加到用户.bashrc,以便在每次登录时加载它们。