Skip to content

Commit

Permalink
fix(test): date timezone (#488)
Browse files Browse the repository at this point in the history
* test: try process.env.TZ

* test: add process.env.TZ for e2e

* test: set default timezone for dayjs

* test: add timezoneId for playwright
  • Loading branch information
YunYouJun authored Dec 17, 2024
1 parent 8a9d475 commit 0c1de93
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.
1 change: 0 additions & 1 deletion demo/yun/components/test/TestFormatDate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const formattedDate = computed(() => {
return formatDate(props.date, {
template: props.template,
timezone: props.timezone,
keepLocalTime: props.keepLocalTime,
})
})
</script>
Expand Down
2 changes: 2 additions & 0 deletions e2e/theme-yun/time.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ test.use({
})

test.beforeEach(async ({ page }) => {
process.env.TZ = 'Asia/Shanghai'

await page.goto('/posts/date')
})

Expand Down
2 changes: 1 addition & 1 deletion packages/valaxy/client/composables/global.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dayjs from 'dayjs'
import { useSiteConfig } from 'valaxy'
import { onBeforeMount } from 'vue'
import { dayjs } from '../utils/time'

/**
* use timezone
Expand Down
4 changes: 4 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export default defineConfig({
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
locale: 'zh-CN',
// set timezone for test
timezoneId: 'Asia/Shanghai',

/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

Expand Down
2 changes: 1 addition & 1 deletion test/date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ it('dayjs date', () => {
})

describe('dayjs date', () => {
// process.env.TZ = 'Asia/Shanghai'
process.env.TZ = 'Asia/Shanghai'
dayjs.tz.setDefault('Asia/Shanghai')

for (let i = 0; i < dateExamples.length; i++) {
Expand Down

1 comment on commit 0c1de93

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://yun.valaxy.site as production
🚀 Deployed on https://6761c497d19439111a2285b3--valaxy.netlify.app

Please sign in to comment.