繁体   English   中英

使用Karma进行E2E测试Angular-ng场景“未定义模块”

[英]E2E Testing Angular with Karma - ng-scenario 'Module is not defined'

我一直在尝试使用Karma运行一些e2e测试。 它根本不适合我。

现在,我收到以下错误:

    Firefox 28.0.0 (Windows 7) ERROR
  ReferenceError: module is not defined
  at C:/MYPATH/Test/node_modules/karma-ng-scenario/lib/ind
ex.js:12

Firefox 28.0.0 (Windows 7) ERROR
  ReferenceError: browser is not defined
  at C:/MYPATH/Test/e2e/scenarios.js:12

我的配置文件如下所示:

module.exports = function(config){
  config.set({

    basePath : './',

    frameworks: ['ng-scenario'],

    files : [
    './node_modules/karma-ng-scenario/lib/*.js',
      './e2e/*.js'
    ],

    autoWatch : true,

    singleRun : true,

    browsers : ['Firefox'],

    plugins : [
            'karma-ng-scenario',
            'karma-chrome-launcher',
            'karma-firefox-launcher'
            ],

    junitReporter : {
      outputFile: 'test_out/unit.xml',
      suite: 'unit'
    },

    urlRoot : '/__karma/',

    proxies : {
      '/public/' : 'http://localhost:8080'
    }

  });
};

我的场景文件只是测试以查看基本路径是否重定向。 为了达到这一点,我已经对npm进行了很多处理,最近一次是“ npm install karma-ng-scenario --save-dev”,但是不幸的是没有运气。

files:[...]数组中,您必须指定包含要编写测试的实际代码的所有文件,如果您的模块正在使用其他模块,则应添加该模块所依赖的所有模块的文件。

假设您正在测试“ someModule”模块,则必须包含“ someModule”控制器,视图,服务,指令和其他模块(如果您的模块依赖于它们)

注意:假设您的文件位于其特定目录中

files: [
  ...       //angularjs, angular-mocks, karma, protractor and other files you need
  ...                                
  'scripts/someModule/controllers/*.js',
  'scripts/someModule/services/*.js',
  'scripts/someModule/directives/*.js',
  'views/someModule/*.html'
]

或简单地

files: [
   ...       //angularjs, angular-mocks, karma, protractor and other files you need
   ...
   'scripts/someModule/**/*.js',
   'views/someModule/*.html'
]

并确保在文件数组中安装并包含所有您依赖的测试库(例如,angularjs,angular-mocks,protrator,karma等)

首先在files[]指定angular.js的路径,然后指定您使用的任何其他angular模块(angular-mocks.js,angular-resource.js,angular-cookies.js),然后指定您使用的任何库,然后再指定自己的代码。

因此,我终于可以使用E2E测试的配置是这样的:

// Karma configuration
// Generated on Fri Apr 11 2014 02:35:20 GMT+0800 (China Standard Time)

module.exports = function(config) {
  config.set({

    // base path, that will be used to resolve files and exclude
    basePath: '..',


    // frameworks to use
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
    ANGULAR_SCENARIO,
    ANGULAR_SCENARIO_ADAPTER,
      'test/e2e/*.js',
    ],


    // list of files to exclude
    exclude: [

    ],


    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
    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, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera (has to be installed with `npm install karma-opera-launcher`)
    // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
    // - PhantomJS
    // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
    //browsers: ['PhantomJS', 'Firefox', 'Chrome'],
    browsers: ['Firefox', 'Chrome'],



    // If browser does not capture in given timeout [ms], kill it
    captureTimeout: 60000,


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false,

    proxies : {
    "/": "http://localhost:8080"
    },

    urlRoot : "/__karma/"
  });
};

似乎进行端到端测试的更好解决方案是使用量角器。 NG-SCENARIO已贬值,并且会引起警告,但仍应运行。 https://github.com/angular/protractor

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM