Skip to content

Commit 0c1de93

Browse files
authored
fix(test): date timezone (#488)
* test: try process.env.TZ * test: add process.env.TZ for e2e * test: set default timezone for dayjs * test: add timezoneId for playwright
1 parent 8a9d475 commit 0c1de93

File tree

5 files changed

+8
-3
lines changed

5 files changed

+8
-3
lines changed

demo/yun/components/test/TestFormatDate.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const formattedDate = computed(() => {
1313
return formatDate(props.date, {
1414
template: props.template,
1515
timezone: props.timezone,
16-
keepLocalTime: props.keepLocalTime,
1716
})
1817
})
1918
</script>

e2e/theme-yun/time.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ test.use({
77
})
88

99
test.beforeEach(async ({ page }) => {
10+
process.env.TZ = 'Asia/Shanghai'
11+
1012
await page.goto('/posts/date')
1113
})
1214

packages/valaxy/client/composables/global.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import dayjs from 'dayjs'
21
import { useSiteConfig } from 'valaxy'
32
import { onBeforeMount } from 'vue'
3+
import { dayjs } from '../utils/time'
44

55
/**
66
* use timezone

playwright.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export default defineConfig({
2828
reporter: 'html',
2929
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
3030
use: {
31+
locale: 'zh-CN',
32+
// set timezone for test
33+
timezoneId: 'Asia/Shanghai',
34+
3135
/* Base URL to use in actions like `await page.goto('/')`. */
3236
// baseURL: 'http://127.0.0.1:3000',
3337

test/date.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ it('dayjs date', () => {
88
})
99

1010
describe('dayjs date', () => {
11-
// process.env.TZ = 'Asia/Shanghai'
11+
process.env.TZ = 'Asia/Shanghai'
1212
dayjs.tz.setDefault('Asia/Shanghai')
1313

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

0 commit comments

Comments
 (0)