【问题标题】:Using multiple versions of dependencies in Karma tests在 Karma 测试中使用多个版本的依赖项
【发布时间】:2014-05-12 17:21:27
【问题描述】:

我正在为 Angular JS 编写一个模块,我想确保它适用于多个版本的 Angular。 有没有办法告诉 Karma 运行具有多个不同依赖项的测试套件(例如,首先使用 Angular 1.2.1 进行所有测试,然后使用 1.2.2 等等)?

【问题讨论】:

    标签: javascript angularjs testing karma-runner


    【解决方案1】:

    我假设你使用 Grunt 运行测试,所以你可以

    1) 为不同的角度版本定义不同的条目

    karma: {
      ang11: {
        configFile: './test/karma-ang1.1.conf.js',
        autoWatch: false,
        singleRun: true
      },
      ang12: {
        configFile: './test/karma-ang1.2.conf.js',
        autoWatch: false,
        singleRun: true
      }
    }
    

    2) 在每个文件中,您引用不同的角度版本和测试套装

    3) 你配置一个任务来依次运行你的业力配置文件

    【讨论】:

    • 它仍然需要一些配置,但它会做。谢谢!
    【解决方案2】:

    another question 的帮助下,我使用grunt-karma's overrides 来重用我的业力配置文件。所以我的Gruntfile.js 有这个:

    meta: {
      jsFiles: [
        'app/scripts/**/*.js',
        'test/spec/**/*.js'
      ]
    },
    karma: {
      options: {
        configFile: 'karma.conf.js',
        singleRun: true
      },
      angular13: {
        files: [{
          src: [
            'test/ref/angular-v1.3.js',
            '<%= meta.jsFiles %>'
          ]}
        ]
      },
      angular14: {
        files: [{
          src: [
            'test/ref/angular-v1.4.js',
            '<%= meta.jsFiles %>'
          ]}
        ]
      }
    

    注意files: 中的src:。没有它,您将收到“不能使用 'in' 运算符 ...”错误,这与 Grunt handles files 的方式有关。

    【讨论】:

      猜你喜欢
      • 2015-02-27
      • 1970-01-01
      • 1970-01-01
      • 2018-05-11
      • 1970-01-01
      • 2012-04-05
      • 1970-01-01
      • 2014-12-18
      • 1970-01-01
      相关资源
      最近更新 更多