admin管理员组文章数量:1296490
I am doing snapshot tests with Jest and during one of those tests i am creating a new Date using new Date() the problem is when i run the tests locally on my puter the date is in german: Mon Jan 20 2020 01:00:00 GMT+0100 (Mitteleuropäische Normalzeit) and when i run the same test with my gitlab pipeline the text is in english Mon Jan 20 2020 00:00:00 GMT+0000 (Coordinated Universal Time). This results in my pipeline failing. Is there an option for globally setting my language for jest. I was able to set the timezone using process.env.TZ = 'UTC';
is there something similar for the language?
I am doing snapshot tests with Jest and during one of those tests i am creating a new Date using new Date() the problem is when i run the tests locally on my puter the date is in german: Mon Jan 20 2020 01:00:00 GMT+0100 (Mitteleuropäische Normalzeit) and when i run the same test with my gitlab pipeline the text is in english Mon Jan 20 2020 00:00:00 GMT+0000 (Coordinated Universal Time). This results in my pipeline failing. Is there an option for globally setting my language for jest. I was able to set the timezone using process.env.TZ = 'UTC';
is there something similar for the language?
- Can you update all the tests to use UTC dates for consistency across all environments? If so, check: get UTC date (not UTC string) in javascript – Metro Smurf Commented Oct 27, 2021 at 12:09
- does this help? stackoverflow./questions/15141762/… But I would consider refactor the test itself to make it not depend on timezone. – spiritwalker Commented Oct 27, 2021 at 12:09
- Can you use this answer: reactjs - How do I set a timezone in my Jest config? - Stack Overflow – chrwahl Commented Oct 27, 2021 at 12:27
- Does this answer your question? get UTC date (not UTC string) in javascript – Michael Freidgeim Commented Jan 9, 2022 at 3:10
1 Answer
Reset to default 11To prevent problems related to timezones (e.g. date formating), you can set node timezone in the jest config file. Now you are sure all tests are executed at the same timezone no matter where your colleagues or your CI server are.
Please, adjust your jest config file:
// jest.config.js
process.env.TZ = 'GMT';
module.exports = {
// ...
}
Resource - https://dev.to/maxpou/how-to-mock-date-with-jest-3k4b.
本文标签: javascriptDate() is different when run local compared to in pipelineStack Overflow
版权声明:本文标题:javascript - Date() is different when run local compared to in pipeline - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741632655a2389455.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论