我正在使用带有 node.js 的实习生,试图为 ajax 测试设置实习生。下面的服务器代码服务于直接 GET 请求,但 Intern 的 XHR 请求似乎没有到达它。我怀疑问题与 Node.js 的 proxyUrl 设置有关。
服务器/main.js:节点/快递
...
app.get('/data', function(request, response, next){
if(request.xhr)
{
var data = dfs.readFileSync("src/server/data.json");
response.render(data, {
root: root,
error: new Error('Cant read file')
});
}
else
next();
});
...
app.listen(8001);
http_proxy.createServer(function(req,res, proxy){
proxy.proxyRequest(req,res, {host:'localhost', port:8001});
}).listen(9000);
intern.hello.js:(单元测试代码)
...
'async test': function () {
var dfd = this.async(1000);
request('/data').then(dfd.callback(function (data) {
assert.strictEqual(data, 'hello world');
}, dfd.reject.bind(dfd)));
}
实习生配置:
...
proxyPort:9000,
proxyUrl: 'http://localhost:8001/',
...
实习错误:
Warning: FAIL: async test (1015ms)
Error: Timeout reached on main - wait - async test
at Error (<anonymous>)
at new ErrorCtor (.../node_modules/intern/node_modules/dojo/errors/create.js:13:21)
at null._onTimeout (.../node_modules/intern/lib/Test.js:164:21)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
2/3 tests passed
2/3 tests passed Use --force to continue.