[英]Date() is different when run local compared to in pipeline
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 computer 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).我正在使用 Jest 进行快照测试,在其中一个测试期间,我正在使用 new Date() 创建一个新日期,问题是当我在计算机上本地运行测试时,日期为德语:2020 年 1 月 20 日星期一 01:00: 00 GMT+0100(Mitteleuropäische Normalzeit),当我使用我的 gitlab 管道运行相同的测试时,文本为英文 Mon Jan 20 2020 00:00:00 GMT+0000(协调世界时)。 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';
我能够使用process.env.TZ = 'UTC';
设置时区is there something similar for the language?语言有类似的东西吗?
To prevent problems related to timezones (eg date formating), you can set node timezone in jest config file.为了防止与时区相关的问题(例如日期格式),您可以在 jest 配置文件中设置节点时区。 Now you are sure all tests are executed on the same timezone no matter where your colleagues or your CI server are.现在,无论您的同事或 CI 服务器在哪里,您都可以确定所有测试都在同一个时区执行。 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 .资源 - https://dev.to/maxpou/how-to-mock-date-with-jest-3k4b 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.