【问题标题】:Wallaby with Browserify and TypeScript modules带有 Browserify 和 TypeScript 模块的 Wallaby
【发布时间】:2016-01-24 14:46:26
【问题描述】:

我正在尝试使用 Browserify 和 Wallabify 让 Wallaby 与 TypeScript 应用程序一起工作。但是,当我运行 Wallaby 时,它会输出 No failing tests, 0 passing,并且所有测试指标都是灰色的。

文件app/spec.setup.ts负责加载节点模块依赖,如chai、sinon和app的主模块。 app/spec.util.ts 提供了一些帮助程序,由各个规范文件导入。

module.exports = function() {
  var wallabify = require('wallabify');

  var wallabyPostprocessor = wallabify({
        entryPatterns: [
          'app/spec.setup.ts',
          'app/src/**/*.spec.ts'
        ]
      }
  );

  return {
    files: [
      {pattern: 'app/spec.setup.ts', load: false, instrument: false},
      {pattern: 'app/spec.util.ts', load: false, instrument: false},
      {pattern: 'app/src/**/*.ts', load: false},
      {pattern: 'app/src/**/*.spec.ts', ignore: true}
    ],

    tests: [
      {pattern: 'app/src/**/*.spec.ts', load: false}
    ],

    testFramework: 'mocha',

    postprocessor: wallabyPostprocessor,

    bootstrap: function (w) {
      // outputs test file names, with .ts extensions changed to .js
      console.log(w.tests);

      window.__moduleBundler.loadTests();
    }
  };
};

有趣的是,我没有从更改entryPatterns 中得到任何反馈,即使将其设置为空数组或无效文件名也是如此。结果还是一样。只有当我完全删除它时,我才会收到诸如Can't find variable: sinon之类的错误。

我还发现entryPatterns 列表可能需要编译后的文件名,即.js 而不是.ts 扩展名。但是,当我这样做时,我会在 spec.setup.ts 上得到 Postprocessor run failure: 'import' and 'export' may appear only with 'sourceType: module'

我不知道为 TypeScript 编译配置 Wallabify 的正确方法是什么,而且我在网上找不到任何完整的示例,所以我很感激任何提示。

附言以我目前的 StackOverflow 声誉,我无法添加两个新标签:wallabywallabify。有人可以帮我一个忙,请添加两个标签。

【问题讨论】:

    标签: testing typescript browserify wallaby.js


    【解决方案1】:

    因为TypeScript compiler renames files to .js and applied before wallabify,您需要像这样更改您的输入模式才能使其工作:

    entryPatterns: [
          'app/spec.setup.js',
          'app/src/**/*.spec.js'
        ]
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 2016-06-14
    • 1970-01-01
    • 2014-01-03
    • 2018-04-07
    • 2015-02-03
    • 2020-01-06
    相关资源
    最近更新 更多