【问题标题】:Wallabyjs with Bower and Requirejs (Visual Studio)Wallabyjs 与 Bower 和 Requirejs (Visual Studio)
【发布时间】:2016-07-08 03:18:20
【问题描述】:

我现在开始在我的 Web 应用程序中使用 bower,因为我正在使用 wallabyjs 进行测试,所以我添加了

{ pattern: 'bower_components/**/*.*', instrument: false, load: false }

到我的 wallabyjs 配置。一切都以这种方式工作正常。但正如我在webpack documentation 中所读到的,这并不是真正推荐的方式:

我们推荐的更有效的方法是指定一个 您的 webpack 的小袋鼠配置中的绝对路径 改为外部模块(不是您的源文件)

我尝试为我的场景(使用 requirejs)实现类似的目标,但失败了。我目前的问题:

  • 使用 requirejs/wallabyjs 处理 bower_components 文件夹的最佳方法是什么?

  • 似乎必须将 bower_components 文件夹设为解决方案文件夹。只要我在 Visual Studio 中说“从项目中排除”,我的测试就会再次失败。

【问题讨论】:

    标签: wallaby.js


    【解决方案1】:

    如果是 require.js,你只需要让 wallaby.js 知道它的内部网络服务器应该从哪里提供文件。这样您就可以将它们从您的 files 列表中删除,而不必包含在解决方案中。

    您可以通过添加middleware function 来做到这一点,它可以将网络服务器路径映射到本地文件夹:

     module.exports = function () {
       return {
         files: [
           ...
         ],
    
         tests: [
           ...
         ],
    
         // telling wallaby to serve bower_components project folder
         // ‘as is’ from the wallaby.js web server
         middleware: (app, express) => {
           app.use('/bower_components',
                   express.static(
                      require('path').join(__dirname, 'bower_components')));
         }
       };
     };
    

    您可能需要根据应用请求 bower_components 的方式更改映射。

    【讨论】:

    • 不行,函数只能在JS中定义。将 JSON 配置文件移动到 JS 非常简单:只需创建一个具有相同名称的 JS 文件,添加 module.exports = function () { return ...;} 并粘贴您当前的 JSON 而不是 ...
    猜你喜欢
    • 1970-01-01
    • 2013-08-18
    • 1970-01-01
    • 2018-08-03
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-16
    相关资源
    最近更新 更多