cognovi-ai / the-cdj

The Cognitive Distortion Journal (CDJ) is a smart journaling tool that helps remedy distorted thinking. It can feel impossible to follow the CBT technique of labeling and reframing distorted thinking when you've been thinking this way your whole life. The CDJ can help with that 🧠✨ -- v2 is in development!
https://thecdj.app
4 stars 0 forks source link

Let Express set port for test environment. #160

Closed hiyaryan closed 2 months ago

hiyaryan commented 3 months ago

Removes MEMORY environment variable. Uses yargs to pass arguments to the application on launch.

hiyaryan commented 3 months ago

Note that these changes allows the development container to be up. In other words, the development container may be running simultaneously with the test environment because it runs on a different port.

hiyaryan commented 2 months ago

@davidzlu Per your review I have reverted to pre-yargs code and wrote a new utility function to dynamically assign a port based on the PORT in .env called getPort. It does this by incrementing the port by 1 with checks to ensure that the port is available to use using a isPortInUse in the same util file. With that I updated index.ts and it's associated test file to use the getPort function. And I added unit tests for getPort.

What's good about having this function is that we no longer require additional dependencies, it feels like a better or less "dirty" solution than using hardcoded port values, and we can also further enhance the code for convenience to check that the PORT in .env is available in the development environment in a future PR if we're keen.

hiyaryan commented 2 months ago

Great update @davidzlu! 🙌 An elegant and simple solution. I pushed a followup commit that just completely removes the getPort utility function (-1 for the utils directory). Somewhat of a revert with a little refactoring and code clean up.