我试图运行(使用命令npm run test
并调试我已使用IDE Webstorm
)使用节点开发的集成测试.js用打字稿,摩卡,chai和supertest编写,用于使用打字机开发的节点应用程序。使用typecript,Mocha,Chai和SuperTest进行异步/等待节点api-functions的运行或调试集成测试nodeJs
在before()钩子函数中,我们正在调用实际启动服务的应用程序,并且此调用用于异步(使用async-await)函数(来自节点应用程序的app.ts/app.js文件)。
但始终我得到这样的错误“错误:您无权访问密钥在谷歌KMS”(即服务),并加上它说:“错误:60000毫秒的超时超标。对于异步测试和钩子,确保调用“done()”;如果返回Promise,请确保解决。',但如果我单独运行服务/应用程序,它工作正常。所以这意味着在运行服务时,API /函数调用的异步/等待代码是相同的。
所以我的观点是,这是因为从before()挂钩函数启动服务时,由于超时异步/等待请求而发生这种情况。
下面是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
});
});
});
和的package.json板块脚本下
"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"
}
任何人都可以面对这样的情况呢?如何从集成测试文件启动异步/等待服务。