Reputation: 1290
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.
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).
But always I am getting an error like 'Error: You are not authorized to access the key in Google KMS' (i.e. in service) and plus it said 'Error: Timeout of 60000ms exceeded. For async tests and hooks, ensure "done()" is called; 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.
So my point is here does this happen due to timeout the async/await request while initiating service from before() hook function.
Below are code sample in test.int-test.ts file,
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
"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.
Upvotes: 0
Views: 1640
Reputation: 1290
Finally I have found the solution to run and debug integration test, we need to do few changes here.
**this.timeout(0)**
Upvotes: 0