Skip to content

Commit 82373a1

Browse files
Copilotcharmander
andauthored
Simplify invalid date deprecation warning test
Co-authored-by: charmander <1889843+charmander@users.noreply.github.com>
1 parent c9985a0 commit 82373a1

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

packages/pg/lib/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict'
22

33
const defaults = require('./defaults')
4-
const { deprecate, types } = require('util')
4+
const nodeUtils = require('util')
55

6-
const { isDate } = types
6+
const { isDate } = require('util/types')
77

8-
const invalidDateDeprecationNotice = deprecate(
8+
const invalidDateDeprecationNotice = nodeUtils.deprecate(
99
() => {},
1010
'Sending an invalid date to Postgres is deprecated and will throw an error in the next major version of pg. Ensure any Date object passed as a query parameter is valid.',
1111
'PG_INVALID_DATE'

packages/pg/test/unit/utils-tests.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,15 @@ test('prepareValues: 1 BC date prepared properly', function () {
8989
helper.resetTimezoneOffset()
9090
})
9191

92-
test('prepareValues: invalid date emits deprecation warning', function () {
93-
const date = new Date(undefined)
94-
92+
test('prepareValue: invalid date emits deprecation warning', function () {
9593
const warningPromise = new Promise((resolve) => {
96-
const onWarning = (warning) => {
97-
if (warning.code === 'PG_INVALID_DATE') {
98-
process.removeListener('warning', onWarning)
99-
resolve(warning)
100-
}
101-
}
102-
process.on('warning', onWarning)
94+
process.once('warning', (warning) => {
95+
resolve(warning)
96+
})
10397
})
10498

105-
const out = utils.prepareValue(date)
99+
const out = utils.prepareValue(new Date(undefined))
106100

107-
// still serializes (for backwards compatibility) but warns that this is deprecated
108101
assert.strictEqual(out, '0NaN-NaN-NaNTNaN:NaN:NaN.NaN+NaN:NaN')
109102

110103
return warningPromise

0 commit comments

Comments
 (0)