Posts

Showing posts with the label unit tests

Running Karma in specific TimeZone

Recently, I had to write some tests related to date and time. In order to tests corner cases, in particular when the UTC date was different from the local date, I had to find a way to set the timezone for my tests. There are countless posts and articles out there that explain how you can set a specific time , but I couldn’t find much about how to actually set the timezone . Many articles references how you could use your browser’s profiles to set it up, etc. But all of it seemed too complicated for my taste. In the end, I came across a gitlab-foss commit by Takuya Nogushi . Simply setting the process.env.TZ variable will do the trick. module . exports = function ( config ) { config . set ( { // your karm configuration } ) ; // Fix the timezone process . env . TZ = 'America/New_York' ; } ; I have not tested with other browsers, but this works with Chrome. The possible values for TZ are available on Wikipedia .