linux - 设置 karma-cordova (Linux) 时遇到问题

标签 linux cordova karma-jasmine

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

尝试使用 cordova 在 karma-jasmine 上运行基本测试。

在 karma start 上,我收到以下错误日志:

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
  })
}

感谢任何建议,干杯!

最佳答案

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

尝试打开终端并输入:

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

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

关于linux - 设置 karma-cordova (Linux) 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33440824/

相关文章:

linux - 无法在 bash 中获得正确的 git 分支名称

android - 使用 Cordova 下载文件

android - 找不到PhoneGap引用错误

linux - 使用 bash 编辑 linux 环境变量

Linux IA-32 内存模型

linux - 为什么在 Linux 中 spin_lock 和 spin_unlock 之间的中断被禁用?

ios - 我无法在 iPad 5.1 上运行我的应用程序,因此我需要将其降级到 5.0 或更低的 iOS 版本

angular - Google Chrome 在使用 Karma/Jasmine 进行 Angular 测试的 WSL2 Ubuntu 上启动时出现多个错误

javascript - 使用 Jasmine 测试数据设置是否正确

angular - Karma-Jasmine:TypeError:无法读取未定义的属性(读取 'get')