Skip to content

Commit 9678518

Browse files
committed
Fix: Use valid timestamp for cross-realm date test
1 parent 4ce66f7 commit 9678518

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed
Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
'use strict'
2-
32
const helper = require('../test-helper')
43
const assert = require('assert')
54
const vm = require('vm')
6-
75
const suite = new helper.Suite()
86

97
suite.testAsync('Handle date objects as Date', async () => {
10-
const crossRealmDate = await vm.runInNewContext('new Date()')
8+
// Create a valid date timestamp first
9+
const timestamp = Date.now()
10+
11+
// Create cross-realm date with the valid timestamp
12+
const crossRealmDate = await vm.runInNewContext(`new Date(${timestamp})`)
1113
assert(!(crossRealmDate instanceof Date))
12-
// Check if the cross-realm date is valid before using it
13-
const time = crossRealmDate.getTime()
14-
if (isNaN(time)) {
15-
// Skip test if cross-realm date is invalid
16-
console.log('Skipping test - cross-realm date is invalid')
17-
return
18-
}
19-
const date = new Date(time)
20-
// Verify the date is valid before proceeding
21-
if (isNaN(date.getTime())) {
22-
throw new Error('Created invalid date from cross-realm date')
23-
}
14+
15+
// Create local date with same timestamp
16+
const date = new Date(timestamp)
17+
2418
const client = new helper.pg.Client()
2519
await client.connect()
2620
await client.query('CREATE TEMP TABLE foo(bar timestamptz, bar2 timestamptz)')
@@ -30,4 +24,4 @@ suite.testAsync('Handle date objects as Date', async () => {
3024
assert.deepStrictEqual(row.bar, date)
3125
assert.deepStrictEqual(row.bar2, date)
3226
await client.end()
33-
})
27+
})

0 commit comments

Comments
 (0)