Mocha-web客户端测试未与Velocity for Meteor应用程序一起运行 [英] Mocha-web client-side tests not running with Velocity for Meteor application

查看:69
本文介绍了Mocha-web客户端测试未与Velocity for Meteor应用程序一起运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个要使用Velocity运行的Mocha网络测试示例.

I have 2 samples Mocha web tests which I'm trying to run using Velocity.

由于某些原因,永远不会执行/tests/mocha/client文件夹下的客户端测试,而/tests/mocha/server文件夹下的服务器端测试运行正常.

For some reason, client-side tests under the /tests/mocha/client folder are never executed, whereas the server side tests under the /tests/mocha/server folder run fine.

这是我的项目待办事项(流星示例项目)的结构

Here is the structure of my project todos (meteor example project)

  • 客户端
  • lib
  • 包装
  • 服务器
  • 测试
    • 摩卡咖啡
      • 客户
      • 服务器
      • client
      • lib
      • packages
      • server
      • tests
        • mocha
          • client
          • server

          有想法吗?

          推荐答案

          我遇到了这个问题,它与安装浏览器策略软件包有关.

          I ran into this problem and it was related to having the browser-policy package installed.

          您需要做的是在JavaScript控制台中查看,例如在Chrome开发者工具中,查看控制台标签. (Apple键+选项键+ I).您应该会看到如下错误:

          What you need to do is look in the JavaScript console, e.g. in Chrome developer tools, look at the console tab. (Apple Key + option key + I). You should see errors like this:

          拒绝框架'http://localhost:5000/?mocha=true',因为它 违反以下内容安全策略指令:"default-src 'self'".请注意,未明确设置"frame-src",因此 'default-src'用作后备.

          Refused to frame 'http://localhost:5000/?mocha=true' because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'frame-src' was not explicitly set, so 'default-src' is used as a fallback.

          出于安全目的,您仍应安装此软件包,但要进行测试,请执行以下操作:

          You should still have this package installed for security purposes, but for a test do the following:

          meteor remove browser-policy
          meteor
          

          我想您会看到您的客户端测试正在运行吗?就我而言,删除浏览器策略包后,便立即看到了它们.基本上,您目前需要做的是针对您的应用调整浏览器策略设置,以允许iframe用于摩卡(mocha),例如http://localhost:5000,但仅适用于开发环境.

          I would guess that you see your client tests running now? In my case I saw them as soon as I removed the browser-policy package. Basically what you need to do at this point is to tweak your browser policy settings for your application to allow the iframe for mocha, e.g. http://localhost:5000, but only for the development environment.

          在更改代码之前,请放回浏览器策略包.

          Before changing the code put back the browser-policy package.

          meteor add browser-policy
          

          现在更改您的浏览器策略设置:

          Now make the changes to your browser policy settings:

            // Your browser policy settings, e.g.
            // BrowserPolicy.content...
          
            // Need to run this at the end so that it overrides normal broswer policy settings.
            if (process.env.NODE_ENV === "development")
            {
              console.log("In development mode. Allowing all framing so that mocha-web can run for tests.");
              this.BrowserPolicy.content.allowOriginForAll("localhost:*");
              this.BrowserPolicy.content.allowConnectOrigin("ws://localhost:5000");
              this.BrowserPolicy.content.allowConnectOrigin("ws://localhost:3000");
            }
          

          这篇关于Mocha-web客户端测试未与Velocity for Meteor应用程序一起运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆