我正在使用 Supertest 和 Jest 来测试 Node.js API。
示例测试具有以下格式
it('Read a note for a user', (done) => {
request(graphqlURL)
.post('/graphql')
.set(baseHeaders())
.send({
query: graphQLQuery
})
.end((err, res) => {
expect(res.status).toBe(200);
done();
})
});
Run Code Online (Sandbox Code Playgroud)
当前,当期望失败时,会记录以下内容
expect(received).toBe(expected) // Object.is equality
Expected: 200
Received: 404
Run Code Online (Sandbox Code Playgroud)
我还想在失败的测试旁边记录请求和响应,以便在调试时获得更多上下文。
有没有办法打印那些,仅用于失败的测试?
当我运行以下程序时
async function functionOne() {
throw new Error('Error here prints the complete stack');
await new Promise((resolve) => {
setTimeout(() => { resolve(); }, 1000);
});
}
async function functionTwo() {
await functionOne();
}
async function functionThree() {
await functionTwo();
}
functionThree()
.catch((error) => {
console.error(error);
});
Run Code Online (Sandbox Code Playgroud)
我得到以下输出,该输出通过各种调用的函数打印堆栈
Error: Error here prints the complete stack
at functionOne (/home/divyanshu/programming/errorHandlingAsyncAwait/index.js:3:9)
at functionTwo (/home/divyanshu/programming/errorHandlingAsyncAwait/index.js:11:9)
at functionThree (/home/divyanshu/programming/errorHandlingAsyncAwait/index.js:15:9)
at Object.<anonymous> (/home/divyanshu/programming/errorHandlingAsyncAwait/index.js:18:1)
at Module._compile (module.js:612:30)
at Object.Module._extensions..js (module.js:623:10)
at Module.load (module.js:531:32)
at tryModuleLoad (module.js:494:12)
at Function.Module._load …Run Code Online (Sandbox Code Playgroud) 我想使用引用本地存储库的提交哈希来提供 Docker 构建命令的上下文。
涵盖 Docker 构建的文档指定如何引用远程存储库上而不是本地存储库上的分支或标签。参考
我尝试用协议替换 URLfile://以引用本地 git 存储库,但这会返回错误
docker build file:///home/username/repositories/hello-world
错误
无法准备上下文:找不到路径“file:///home/username/repositories/hello-world”
我想将本地 Git 存储库(特定提交、标签或分支)作为 Docker 构建映像的构建上下文。
我已经看过这个问题Docker build Specific local gitbranch但我不希望必须克隆或签出分支来从中构建。
node.js ×2
async-await ×1
docker ×1
git ×1
javascript ×1
jestjs ×1
stack-trace ×1
supertest ×1