grunt-contrib-jasmine and PhantomJS security

2019-02-07 06:43发布

问题:

I'm getting an error

XMLHttpRequest cannot load https://my-api.domain.com. Origin file:// is not allowed by Access-Control-Allow-Origin.

when I try to run some async unit tests that query an API through grunt-contrib-jasmine, which in turn using PhantomJS. I see that the command line version of PhantomJS does have a 'web-security' options. Can I control how grunt-contrib-jasmine uses PhantomJS to include this option and disable the cross-domain security?

回答1:

You can pass options to phantomjs similarly to how you would on the command line, e.g.

The following options may help, but more can be found at the phantomjs docs

jasmine : {
  your_task : {
    options : {
      '--web-security' : false,
      '--local-to-remote-url-access' : true,
      '--ignore-ssl-errors' : true
    }
  }
}