gpt4 book ai didi

javascript - Mocha 的 before() 函数在 CircleCI 中使用时失败

转载 作者:太空宇宙 更新时间:2023-11-04 02:47:24 24 4
gpt4 key购买 nike

我尝试使用 Mocha 在 CircleCI 上测试我的 JS 代码,但在测试开始时出现以下错误:

Sample test suite
1) "before all" hook: applyFixture

0 passing (77ms)
1 failing

1) Sample test suite "before all" hook: applyFixture:
StatusCodeError: 404 - {"message":"Not Found"}
at _stream_readable.js:943:16

sample_test.js文件:

describe('Sample test suite', function() {

before(function applyFixture() {
var options = {
uri: 'http://localhost:8000/sampleRoute',
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
form: {dataset: 'test_dataset'},
resolveWithFullResponse: true
};

return rp(options)
.then(function(response) {
if (response.statusCode === 200) {
console.log('ready for testing!');
} else {
throw new Error('failed to load');
}
});
});

以下代码在本地运行良好。如果我将 before block 中的代码包含到第一个测试中,它也适用于 CircleCI。 localhost:8000/sampleRoute 在测试开始之前也可用。

不知道如何解决此问题...

最佳答案

然后问题出在请求的 header 上。我必须在其中指定身份验证 token 才能正确执行 POST 请求。这与 CircleCI 无关。

下面是有效的 options 对象:

var options = {
uri: 'http://localhost:8000/sampleRoute',
method: 'POST',
headers: {
authorization: 'authorizationToken'
},
form: {dataset: 'test_dataset'},
resolveWithFullResponse: true
};

关于javascript - Mocha 的 before() 函数在 CircleCI 中使用时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32528798/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com