Mocha-web client-side tests not running with Velocity for Meteor application

醉酒当歌 提交于 2019-12-01 19:49:03

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

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:

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

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");
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!