通过grunt(qunit)为PhantomJS代理配置

时间:2013-05-02 18:11:54

标签: phantomjs qunit gruntjs grunt-contrib-qunit

我正在尝试通过grunt-contrib-qunit运行集成测试。我通过--proxy对象设置了options标志,每个ajax请求都返回404(未找到)错误。

Gruntfile.js

grunt.loadNpmTasks('grunt-contrib-qunit');
...

grunt.initConfig({
  qunit: {
    options: {
      '--local-to-remote-url-access': true,
      '--proxy': '192.168.1.1:8080'
    },
    all: [
      'test/**/*.html'
    ]
  },
  ...
});

...

grunt.registerTask('test', [
  'clean:server',
  'compass',
  'connect:test',
  'qunit:all'
]);

QUnit测试本身在最简单的AJAX请求中失败了404:

测试/ index.html中

test('Works', function() {
  stop();
  $.ajax({
    url: '/svc/version',
    success: function() {
      ok(true, 'yippee');
      start();
    },
    error: function(xhr) {
      console.log('Error: ' + xhr.status);
    }
  });
});

失败:

Running "qunit:all" (qunit) task
Testing test/index.htmlError: 404

值得注意的是,显式引用主机(url: 'http://192.168.1.1:8080/svc/version')工作正常,因此它不是同源问题。


参考文献:grunt-contrib-qunitPhantomJSgrunt-lib-phantomjsSO "Proxy in PhantomJS"

0 个答案:

没有答案