watson / mode-s-aircraft-store

A utility library for keeping track of active aircrafts and their position based on their Mode S messages
MIT License
10 stars 5 forks source link

Decouple AircraftStore from the system time #1

Open Pietro210 opened 6 years ago

Pietro210 commented 6 years ago

AircraftStore.addMessage() and AircraftStore.getAircrafts() now accept an extra argument to set the reference time instead of the current system time.

This is useful if we need to add messages in a different order or process a stream of messages received in the past when we know the original times when the messages were received. It adds flexibility and simplifies some of the tests because we can avoid monkey-patching Date.now and waiting a few milliseconds with setTimeout.

Pietro210 commented 6 years ago

I didn't think about that, but by using setTimeout we'd end up waiting 10+ seconds for the test to finish.

I think it would be better to mock Date.now just like you did before.

watson commented 6 years ago

@Pietro210 feel free to mock Date.now 😃

Pietro210 commented 6 years ago

Done :smiley:

digitalica commented 5 years ago

sounds like a good idea to me, and looks finished... can it be merged?