【问题标题】:How to get xml output from running grunt jasmine如何从运行 grunt jasmine 获取 xml 输出
【发布时间】:2013-08-02 20:12:14
【问题描述】:

我正在尝试将我的测试集成到竹子中。使用竹子,我似乎需要测试结果为junit xml格式。因此,我需要让我的“grunt jasmine”执行以 xml 格式输出测试结果。我是 jasmine/grunt/junit 的新手,并且花了比我愿意承认的时间更多的时间来尝试让它发挥作用。我遵循了各种教程和板(主要是https://gist.github.com/asabaylus/3059886),但只是卡住了。

当我从 gitbash 运行“grunt jasmine”时,规范运行成功,但没有生成输出文件,并且出现以下错误... " 处理模板时出错(无法调用方法 'indexO f' 的未定义)。使用 --force 继续。

由于警告而中止。"

我是否必须更改任何其他文件?谁能帮我解决这个问题?

请,谢谢! 抄送

grunt.js 文件

/*global module:false*/
    module.exports = function ( grunt ) {

        // Project configuration.
        grunt.initConfig({
            meta: {
                banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
                    '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
                    '<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
                    '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
                    ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
            },

            lint: {
                files: ['grunt.js', 'src/**/*.js']
            },

            jasmine: {
                all: ['./SpecRunner.html'],
                junit: {
                    dest: 'test-results' 
                }  
            },

            concat: {
                dist: {
                    src : ['<banner:meta.banner>', '<file_strip_banner:src/buyitnow.js>'],
                    dest: 'dist/buyitnow/<%= meta.version %>/buyitnow.js'
                }
            },

            min: {
                dist: {
                    src : ['<banner:meta.banner>', '<config:concat.dist.dest>'],
                    dest: 'dist/buyitnow/<%= meta.version %>/buyitnow.min.js'
                }
            },

            watch: {
                files: '<config:lint.files>',
                tasks: 'lint'
            },

            jshint: {
                options: {
                    curly  : true,
                    eqeqeq : true,
                    immed  : true,
                    latedef: true,
                    newcap : true,
                    noarg  : true,
                    sub    : true,
                    undef  : true,
                    boss   : true,
                    eqnull : true,
                    browser: true,
                    jquery : true,
                    node   : true
                },
                globals: {}
            },

            uglify: {}
        });

        grunt.loadNpmTasks('grunt-jasmine-task');

        // Default task.
        grunt.registerTask('default', 'lint jasmine concat min cssmin');};

我的 specrunner.html 文件

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>Jasmine Spec Runner</title>

  <link rel="shortcut icon" type="image/png" href="lib/jasmine-1.3.1/jasmine_favicon.png">
  <link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css">
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script>
  <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script>
  <script type="text/javascript" src="lib/jasmine.async.min.js"></script>
  <script type="text/javascript" src="lib/sinon-1.6.0.js"></script>

  <!-- For JUnit output of test results include the following link to Lary Myer's JUnit reporter -->
  <script type="text/javascript" src="node_modules/jasmine-reporters/src/jasmine.junit_reporter.js"></script>

  <!-- include spec files here... -->
  <script type="text/javascript" src="spec/binSpec.js"></script>

  <script type="text/javascript">
    (function() {
      var jasmineEnv = jasmine.getEnv();
      jasmineEnv.updateInterval = 1000;

      var htmlReporter = new jasmine.HtmlReporter();
      jasmineEnv.addReporter(htmlReporter);

      // Specify target test results folder as below, for now
      var junitReporter = new jasmine.JUnitXmlReporter('test-results/');
      jasmineEnv.addReporter(junitReporter);

      jasmineEnv.specFilter = function(spec) {
        return htmlReporter.specFilter(spec);
      };

      var currentWindowOnload = window.onload;

      window.onload = function() {
        if (currentWindowOnload) {
          currentWindowOnload();
        }
        execJasmine();
      };

      function execJasmine() {
        jasmineEnv.execute();
      }

    })();
  </script>

</head>

<body>
</body>
</html>

【问题讨论】:

    标签: junit jasmine gruntjs


    【解决方案1】:

    正如 Amir T 所说,您可以使用 grunt-contrib-jasmine。此外,grunt-jasmine-task 不再处于活动状态。

    options.junit.path 选项可用于创建 junit 报告,然后可供 Jenkins/Hudson、Travis、Bamboo 等使用。此选项应提供将在其中创建报告的文件夹的名称(@ 987654326@ 将为每个规范文件创建一个 xml)。这是一个示例配置:

    jasmine: {
        tests: {
            src: 'dist/buyitnow/<%= meta.version %>/buyitnow.min.js',
            options: {
                specs: 'spec/*Spec.js',
                junit: {
                    path: 'build/junit'
                },
            }
        }
    }
    

    您不需要创建SpecRunner.html 文件,因为它是由grunt-contrib-jasmine 自动创建的

    【讨论】:

      【解决方案2】:

      我可以使用 grunt-contrib-jasmine@0.5.2 来做到这一点

      jasmine: {
        pivotal: {
          src: 'build/application.js',
          options: {
            specs: 'test/**/*_spec.js',
            helpers: 'test/**/*_helper.js',
            junit: {
              path: 'build/.test'
            },
          }
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2016-05-30
        • 1970-01-01
        • 2016-03-29
        • 1970-01-01
        • 2023-03-27
        • 1970-01-01
        • 2015-07-19
        • 2014-09-02
        • 1970-01-01
        相关资源
        最近更新 更多