thibaultyou / tradingview-alerts-processor

Minimalist service designed to execute TradingView webhooks and process them to cryptocurrencies exchanges.
MIT License
79 stars 23 forks source link

✅ Adding tests for trading executor #32

Open thibaultyou opened 2 years ago

thibaultyou commented 2 years ago

@mrsegen can I have some feedbacks on this one ?

I have some issues with open handles with Jest since I've played with setInterval function and timers, maybe you have a workaround for it ? (try running npm run test --detectOpenHandles)

leifjones commented 2 years ago

So far I had some success with at least getting it to pass with jest.useFakeTimers(); atop the file. Not sure yet if it's testing/verifying what's needed with that change. (If I'm remembering correctly... I'm away from the computer now and typing from memory.)

If going with it, check the jest documentation for it. I think I put a jest.useRealTimers(); within an afterEach(). That should be enough to get it passing.

Possible next steps, for subsequent iterations, if it makes sense for what's being tested:

thibaultyou commented 2 years ago

@mrsegen thank you for the advices, your contributions are always highly appreciated 🙏

I'll try using statements in afterEach blocks this may fix the warnings. Testing durations may also be better using toHaveBeenCalledWith that using steps in timers, I'll try this out.

leifjones commented 2 years ago

So far, when I went deeper with that, and even making tests of the exchange services, I've been running into a strange errors during testing: Something about node thinking SpotExchangeService is undefined in lines such as: class BinanceExchangeService extends SpotExchangeService

Let me know if you run into that, and/or find a way around it. So far I've explored trying to address apparent circular dependencies. I haven't made much progress yet.