【问题标题】:Jenkins integration with JestJenkins 与 Jest 的集成
【发布时间】:2014-09-29 02:47:00
【问题描述】:

有没有办法将 Jenkins 集成到基于 Jasmine 构建的 Javascript Jest 测试框架中?

我尝试将 Jest 与 jasmine-reporters 集成,但未能获得 JUnit XML 输出。我使用 npm install jasmine-reporters@~1.0.0 安装了 Jasmine 1.3 的记者,然后在我的 setupTestFrameworkScriptFile 中:

require('jasmine-reporters');

jasmine.VERBOSE = true;

jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter({
  savePath: "output/"
}));

当我运行jest 时,我得到NodeJS attempt: Arguments to path.join must be stringsNodeJS attempt: Object [object Object] has no method 'join'

【问题讨论】:

    标签: javascript jasmine jestjs


    【解决方案1】:

    我已经设法在repo 中获得了它的工作版本。问题是我没有在测试文件中嘲笑pathfs

    【讨论】:

      【解决方案2】:

      您正在使用 jasmine-reporters 2.x 的语法和 1.x 分支。具体来说,您正在传递一个选项对象,但您需要发送位置参数。

      不要这样做:

      jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter({
        savePath: "output/"
      }));
      

      相反,您应该这样做:

      jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter("output/"));
      

      您可以查看the source 以获取可用选项列表。以下是当前选项:

      /**
       * Generates JUnit XML for the given spec run.
       * Allows the test results to be used in java based CI
       * systems like CruiseControl and Hudson.
       *
       * @param {string} [savePath] where to save the files
       * @param {boolean} [consolidate] whether to save nested describes within the
       *                  same file as their parent; default: true
       * @param {boolean} [useDotNotation] whether to separate suite names with
       *                  dots rather than spaces (ie "Class.init" not
       *                  "Class init"); default: true
       * @param {string} [filePrefix] is the string value that is prepended to the
       *                 xml output file; default: 'TEST-'
       * @param {boolean} [consolidateAll] whether to save test results from different
       *                  specs all in a single file; filePrefix is then the whole file
       *                  name without extension; default: false
       */
      var JUnitXmlReporter = function(savePath, consolidate, useDotNotation, filePrefix, consolidateAll) {
          /* ... */
      }
      

      【讨论】:

      • 感谢您的提示,但它仍然无法正常工作,并且出现同样的错误。 github.com/palcu/jest-example
      • 感谢您的示例应用程序,我可以重现您的错误,尽管原因对我来说没有意义。看起来正在发生的事情是通过 NodeJS require 加载的变量以某种方式混淆了。我不知道为什么,到目前为止我只在jest 环境中看到过这种情况。我用观察到的行为评论了您在 jest 存储库中打开的问题。
      【解决方案3】:

      看起来jest-junit也是一个选项。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-05-08
        • 2014-07-08
        • 2016-06-29
        • 2014-11-02
        • 2014-03-12
        • 2016-02-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多