-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(calendar): refactor demo to show selected date in UTC, ensure consistent snapshot #2972
test(calendar): refactor demo to show selected date in UTC, ensure consistent snapshot #2972
Conversation
…nsistent snapshot
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
select: {{value}} | ||
<a-space direction="vertical" fill> | ||
<a-calendar v-model="value" /> | ||
<div>Selected date in UTC: {{ value.toISOString() }}</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Summer-Shen 这样是可以保证这一处的快照一致,但没有根本上解决时间相关的测试问题。 在 Demo 中使用toISOString()
可能会增加用户理解成本。建议arco-vue-scripts
中优化 Jest 配置,统一处理日期时间模拟,以确保测试结果在不同环境下的一致性和可靠性。😊👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LIjiAngChen8 尝试了一些方案:
- 向
packages/arco-vue-scripts/src/configs/jest.config.ts
的globals
增加TZ
- 向
package.json
引入globalSetup
但是在我的 Windows 机器上似乎都不 work,我倾向于还是暂时使用之前修改的 toISOString
,不知道您这边有什么想法,感谢!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LIjiAngChen8 我还尝试了一下给这个测试用例单独加 MockDate
,但是始终无法绕开不同机器显示时区不同的问题;如果配置 Jest,在 Windows 上想要暂时取代系统时区也非常困难。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我本地重新 yarn install
之后,首先在 init
和测试过程中需要额外安装 @babel/helper-environment-visitor 和 @babel/helper-string-parser 才可以运行测试。
测试后,许多 snapshot 好像都和之前不是完全一样,有细微的差别。我应该更新这些 snapshot 吗?
Test Suites: 36 failed, 84 passed, 120 total
Tests: 187 failed, 501 passed, 688 total
Snapshots: 189 failed, 375 passed, 564 total
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LIjiAngChen8 尝试了一些方案:
- 向 的 增加
packages/arco-vue-scripts/src/configs/jest.config.ts``globals``TZ
- 向
package.json
引入globalSetup
但是在我的 Windows 机器上似乎都不 work,我倾向于还是暂时使用之前修改的 ,不知道您这边有什么想法,感谢!
toISOString
变更 scripts 没生效的话有尝试重新 build 吗。jest 测试变动关联的内容比较多,因此建议将此项工作交由 maintainer 进行变动。
📌 按计划年后可能会对该仓库的 ci 进行一次完善优化。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LIjiAngChen8
变更 scripts 没生效的话有尝试重新 build 吗
没有;向 packages/arco-vue-scripts/src/configs/jest.config.ts 的 globals 增加 TZ 的方案应该在 Windows 上不可行,后续 向 package.json 引入 globalSetup 值得一试。
jest 测试变动关联的内容比较多,因此建议将此项工作交由 maintainer 进行变动。
了解,也感谢您对这个 PR 的关心和帮助🤝!
…te date format for consistency
Types of changes
Background and context
#2971
Solution
The Calendar demo test fails because if we use
new Date('YYYY-MM-DD')
to instantiate theDate
object, we get a UTC time set at '00:00:00'. The object will give us the corresponding time in our system time zone when accessed. By usingtoISOString
, we get the same representation wherever we run the tests.Calendar demo 不通过的原因是,使用
new Date('YYYY-MM-DD')
实例化Date
对象时,系统会自动设置一个时刻为 '00:00:00' 的 UTC 时间,并在用户访问时,返回系统时区的对应时间。通过使用toISOString
,无论在哪里运行测试,都能得到相同的表示。How is the change tested?
Changelog
Checklist:
npm run test
)feature
branch and othersshould be submitted to
main
branch)Other information
Reference 参考