Testing Tips - icykoneko/ff14-fish-tracker-app GitHub Wiki
Please forgive the blatant lack of testing for this project. There's a TON of code, and it's literally holding itself together. Until a better solution is implemented, I'm recording here some tips and tricks for verifying the behavior of the site.
Time Travel
This tracker is effectively a function of the current time at its core. By using the following snippet, you can adjust the current date to some base time, optionally allowing time to resume forward from there. Please note, choosing a time in the past will corrupt the WeatherService cache, so make sure to use the correct code snippet.
First, create an alias of the original Date.now()
function. Only do this once!
let origDateNow = Date.now;
To test behavior of time changes using a future date:
// Generate a date offset relative to some date in the future.
dateOffset = new Date(2042,8,14,23,59,45) - origDateNow();
// Override the Date.now() function so it gives times in the future.
Date.now = () => { return origDateNow() + dateOffset };
To test behavior of time changes using a past date:
// First, clear out the existing weather data.
weatherService.__weatherData = [];
// Next, clear out the catchable ranges for ALL fish!
_(Fishes).each(fish => {
fish.catchableRanges = [];
});
// Generate an offset relative to a date in the past.
// NOTE: This doesn't have to be near a weather change.
dateOffset = origDateNow() - new Date(2017,8,14,23,59,45);
// Before resetting the Date.now() function, we need to insert the
// previous period forecast. The events are still wired up!
prevPeriod = startOfPeriod(dateFns.utc.subHours(eorzeaTime.toEorzea(new Date(2017,8,14,23,59,45)), 8));
weatherService.insertForecast(prevPeriod, weatherService.calculateForecastTarget(eorzeaTime.toEarth(prevPeriod)));
// Finally, override the Date.now() function. This will immediately force an update to catchable ranges
// and weather forecasts.
Date.now = () => { return origDateNow() - dateOffset };
Time Travel (Easy Method)
So, I ended up actually including this in the site. You still have to use the dev console though.
// Use EARTH date.
CarbyUtils.timeTravel(Date.UTC(2021,0,18,0,0,0));
// Or, convert Eorzea date.
CarbyUtils.timeTravel(eorzeaTime.toEarth(Date.UTC(3017,1,26,23,45,0)));
// After you're done playing Jojo, fix everything.
CarbyUtils.restoreTime();