Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the timezone in jest config in Create React App?

I wrote some tests in my Create React App application that passed locally but failed in CI due to differences in timezone. So I need a way to set the timezone to UTC for all tests in my application. I tried the suggestions on this question, but they didn't work, likely due to Create React App:

Things that I have tried:

  • changing test script from react-scripts test to TZ=UTC && react-scripts test
  • Adding the following snippet to setupTests.js:
module.exports = async () => {
    process.env.TZ = 'UTC';
};
like image 354
Keith Murgic Avatar asked Sep 06 '25 03:09

Keith Murgic


1 Answers

It should be "test": "TZ=UTC react-scripts test", (without &&).

Note that it's working only when you run it from the terminal (because I'm running sometimes tests from IDE and then you have to change it separate in IDE tests config).

like image 181
Alan Wołejko Avatar answered Sep 07 '25 19:09

Alan Wołejko