typescript-sdk icon indicating copy to clipboard operation
typescript-sdk copied to clipboard

Start Keploy server from Typescript-SDK

Open frey0-0 opened this issue 1 year ago • 9 comments

Fixes #352 If the keploy mode is record and test then it will check if keploy is running on port 6789 and if it isn't then it will start an asynchronously process to start the keploy server and the server won't keeping running, it will stop the server as soon as the main app server stops

frey0-0 avatar Mar 09 '23 21:03 frey0-0

Hi @Frey0-0, we should start the Keploy server from Keploy class constructor in src/keploy.ts because middleware is called on API call only. But we should check for Keploy binary during user API server setup.

re-Tick avatar Mar 10 '23 07:03 re-Tick

Yes that makes sense @re-Tick cause it may be possible the binary is not even present. I will look into this and mention if I have any issues here only. Thanks for the review 😄

frey0-0 avatar Mar 10 '23 16:03 frey0-0

@re-Tick I have made the changes now we check if the keploy binary is present or not and next if it is running on port 6789 and if it is present and not running then it will spawn a process to start the server

frey0-0 avatar Mar 10 '23 21:03 frey0-0

Hi @Frey0-0, I have tried these changes in my local but the keploy binary do not run from the spawn method call.

re-Tick avatar Mar 12 '23 17:03 re-Tick

the spawn method call will run the binary as long as the node server is running and it will be terminated if the node server is stopped because the parent process has stopped. Please have a look at this video below.

This is on my system which has the keploy binary installed Screen Recording

This is a system which doesn't have the keploy binary Screenshot from 2023-03-13 02-52-04

The keploy server stops if we stop the node server and can be started from the command again Screen Recording

frey0-0 avatar Mar 12 '23 21:03 frey0-0

I have found an interesting issue due to which Keploy binary is trying to run on the same port as the sample API server. This is because Keploy runs on port defined by PORT env variable or 6789 (default).

So, we can solve this by changing the env variable name in keploy to "KPORT"

You can repklicate this by:

  1. Use node-fetch sample of samples/typescript.
  2. Add export PORT=8080 in the .env file of node-fetch.
  3. Now, Change the env varibale name from KEPLOY_APP_PORT to PORT in this line of app.listen
  4. Try recording some testcases. Error will be thrown failed to post testcase to keploy server.

re-Tick avatar Mar 13 '23 06:03 re-Tick

Oh yes! I faced the same error and we should change the name of the Keploy Port. Should I add an issue and then raise a PR for this or directly raise a PR for this describing the issue for the variable name change?

frey0-0 avatar Mar 13 '23 14:03 frey0-0

I have created an issue and also linked a PR for it. @re-Tick Please review it :) and are there any more changes that need to be done on this PR?

frey0-0 avatar Mar 13 '23 15:03 frey0-0

LGTM. Please add the link in GSOC task list

re-Tick avatar Mar 26 '23 17:03 re-Tick