[英]Run or Debug integration test with nodeJs using typescript, Mocha, Chai and SuperTest for async/await node api-functions
I am trying to run(using command npm run test
and to debug i have been used IDE Webstorm
) the integration test developed using node.js written in typescript, mocha, chai and supertest for node application developed using typescript. 我正在尝试运行(使用命令npm run test
进行调试,并调试我已经使用过IDE Webstorm
)使用以打字稿编写的node.js,mocha,chai和supertest开发的集成测试,以使用打字稿开发的节点应用程序。
In before() hook function, we are making a call to the application which actually initiating service and this call are for asynchronous(used async-await) functions(from the app.ts/app.js file of node application). 在before()钩子函数中,我们正在对实际上启动服务的应用程序进行调用,并且此调用是针对异步(使用的async-await)函数的(来自节点应用程序的app.ts / app.js文件)。
But always I am getting an error like ' Error: You are not authorized to access the key in Google KMS ' (ie in service) and plus it said ' Error: Timeout of 60000ms exceeded. 但是,我总是收到类似“ 错误:您无权访问Google KMS中的密钥 ”(即在使用中)的错误 ,并显示“ 错误:超时超过60000ms。 For async tests and hooks, ensure "done()" is called; 对于异步测试和挂钩,请确保调用了“ done()”; if returning a Promise, ensure it resolves. 如果返回承诺,请确保其解决。 ' , but if I ran service/application individually it is working fine. ',但是如果我单独运行服务/应用程序,则可以正常运行。 so that means while running service the async/await code for API/function call is same. 因此,这意味着在运行服务时,用于API /函数调用的异步/等待代码是相同的。
So my point is here does this happen due to timeout the async/await request while initiating service from before() hook function. 所以我的意思是,这是由于从before()挂钩函数启动服务时异步/等待请求超时引起的。
Below are code sample in test.int-test.ts file, 以下是test.int-test.ts文件中的代码示例,
import {expect} from "chai";
const app = require('../app');
const supertest = require('supertest');
describe("Test model", function () {
this.timeout(60000);
before(async () => {
api = supertest(await app);
// app is here a entry point for my service/application which runs actually service/applicaiton.
// This file has async-await function which makes call to third party application
console.log('inside before: ', JSON.stringify(api));
});
describe('get', function () {
it('should respond with 200 Success', async () => {
// call to async function
});
});
});
and under the section script in package.json 并在package.json中的section脚本下
"scripts": {
"test": "nyc --reporter=html --reporter=text --reporter=cobertura node_modules/mocha/bin/_mocha --reporter mocha-multi-reporters --reporter-options configFile=mocha-multi-reporters.config build/test/test.int-test.js"
}
Can anybody face such a situation? 有人可以面对这样的情况吗? that how to initiate async/await service from integration test file. 如何从集成测试文件启动异步/等待服务。
Finally I have found the solution to run and debug integration test, we need to do few changes here. 最后,我找到了运行和调试集成测试的解决方案,我们在这里需要做一些更改。
**this.timeout(0)**
对于超时问题最重要的是,我们必须将超时设置为0,即**this.timeout(0)**
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.