Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start Keploy server from Typescript-SDK #62

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

frey0-0
Copy link

@frey0-0 frey0-0 commented Mar 9, 2023

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

@re-Tick
Copy link
Contributor

re-Tick commented Mar 10, 2023

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.

@frey0-0
Copy link
Author

frey0-0 commented Mar 10, 2023

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
Copy link
Author

frey0-0 commented Mar 10, 2023

@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

@re-Tick
Copy link
Contributor

re-Tick commented Mar 12, 2023

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

@frey0-0
Copy link
Author

frey0-0 commented Mar 12, 2023

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

@re-Tick
Copy link
Contributor

re-Tick commented Mar 13, 2023

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.

@frey0-0
Copy link
Author

frey0-0 commented Mar 13, 2023

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
Copy link
Author

frey0-0 commented Mar 13, 2023

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?

@re-Tick re-Tick requested a review from Sarthak160 March 15, 2023 11:36
src/keploy.ts Outdated
} else {
exec("lsof -i:6789", (error, stdout, stderr) => {
if (!stdout) {
spawn("keploy");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, run the Keploy binary with KEPLOY_PORT=6789 env variable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I should use the command export KEPLOY_PORT=6789 before spawning the keploy binary right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this export cmd can be run with keploy using && in the exec method

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done the changes please have a look ✨

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please rebase your commit messages for the github action to pass

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the changes to commit messages. I didn't know there was a specific way to write the commit messages. Thank you for being so patient 😅

frey0-0 and others added 8 commits March 23, 2023 00:00
* fix: stores correct http response for unique test-ids

Signed-off-by: re-Tick <[email protected]>

* feat(mongoose): adds hooks for mocking/stubbing mongoose methods

Signed-off-by: re-Tick <[email protected]>

* docs: updates the docs for mongoose and refactors

Signed-off-by: re-Tick <[email protected]>

* docs: refactors readme for e2e and mocks-lib docs

Signed-off-by: re-Tick <[email protected]>

* docs: adds require stmt in docs code snippet

Signed-off-by: re-Tick <[email protected]>

---------

Signed-off-by: re-Tick <[email protected]>
Signed-off-by: Tanmay Bajaj <[email protected]>
the executionContext was getting undefined for mocking dependency call outputs

Signed-off-by: re-Tick <[email protected]>
Signed-off-by: Tanmay Bajaj <[email protected]>
@re-Tick
Copy link
Contributor

re-Tick commented Mar 26, 2023

LGTM. Please add the link in GSOC task list

@re-Tick re-Tick added Don't Merge Not to be merged until gsoc results Accepted PR is reviewed and Accepted labels Mar 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted PR is reviewed and Accepted Don't Merge Not to be merged until gsoc results
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature]: start Keploy server from Typescript-SDK
2 participants