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

旧街凉风 提交于 2019-12-30 23:25:31

问题


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

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)

  • client
  • lib
  • packages
  • server
  • tests
    • mocha
      • client
      • server

Thoughts ?


回答1:


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");
  }


来源:https://stackoverflow.com/questions/26866008/mocha-web-client-side-tests-not-running-with-velocity-for-meteor-application

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