This change is inspired by Parker's changes in fec2de30 to unify the reading and writing of state to/from disk (which commit was moved when we force-pushed).
Similar to the other version, this one moves the JSON file to ~/.mob-timer/state.json which should address the issue in #12 where sometimes the state was lost (due to the OS cleaning up the temp directory). I also added a check for the old state file so that teams migrating to the newer version of the mob timer don't lose all their settings. This could be removed in some future version.
Some things I did differently:
I don't think the thing that reads/writes to file should know what the default configuration is. Making it responsible for that means that adding new features to timer-state would require changes to the state-persister as well, and that felt wrong.
I didn't create an init() function because that adds temporal coupling -- if init() isn't called before trying to write, it would cause problems. Also if we check for the directory every time we write, we can catch edge cases where the directory was deleted while the app is running.
I did not pull in chai or sinon-chai (yet) because it seemed unnecessary that this point. If we want to use those libraries, better to do it in a separate commit.
Finally, I removed the integration tests along with write-state.specs.js. Since the regular unit tests use sinon to test all of the persister's logic, it felt like an integration test would just be testing Node's fs module, and we don't need to be testing that. Plus the code is simpler without having to move the file location for testing.
This change is inspired by Parker's changes in fec2de30 to unify the reading and writing of state to/from disk (which commit was moved when we force-pushed).
Similar to the other version, this one moves the JSON file to
~/.mob-timer/state.json
which should address the issue in #12 where sometimes the state was lost (due to the OS cleaning up the temp directory). I also added a check for the old state file so that teams migrating to the newer version of the mob timer don't lose all their settings. This could be removed in some future version.Some things I did differently:
timer-state
would require changes to thestate-persister
as well, and that felt wrong.init()
function because that adds temporal coupling -- ifinit()
isn't called before trying to write, it would cause problems. Also if we check for the directory every time we write, we can catch edge cases where the directory was deleted while the app is running.chai
orsinon-chai
(yet) because it seemed unnecessary that this point. If we want to use those libraries, better to do it in a separate commit.Finally, I removed the integration tests along with
write-state.specs.js
. Since the regular unit tests use sinon to test all of the persister's logic, it felt like an integration test would just be testing Node'sfs
module, and we don't need to be testing that. Plus the code is simpler without having to move the file location for testing.