Skip to content

Commit 9131b48

Browse files
committed
chore(pg-connection-string): use tsx for tests
1 parent ee489bf commit 9131b48

File tree

8 files changed

+715
-470
lines changed

8 files changed

+715
-470
lines changed

packages/pg-connection-string/.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ build/Release
2323
# Deployed apps should consider commenting this line out:
2424
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
2525
node_modules
26-
package-lock.json
26+
package-lock.json
27+
28+
# TypeScript output directory
29+
dist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extension": ["js", "ts"],
3+
"require": "tsx"
4+
}

packages/pg-connection-string/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
"chai": "^4.1.1",
3939
"coveralls": "^3.0.4",
4040
"istanbul": "^0.4.5",
41-
"mocha": "^10.5.2"
41+
"mocha": "^10.5.2",
42+
"tsx": "^4.19.3",
43+
"typescript": "^4.0.3"
4244
},
4345
"files": [
4446
"index.js",
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
'use strict'
2-
3-
const chai = require('chai')
1+
import chai from 'chai'
42
const expect = chai.expect
53
chai.should()
64

7-
const { parse, toClientConfig, parseIntoClientConfig } = require('../')
5+
import { parse, toClientConfig, parseIntoClientConfig } from '../'
86

97
describe('toClientConfig', function () {
108
it('converts connection info', function () {
119
const config = parse('postgres://brian:pw@boom:381/lala')
1210
const clientConfig = toClientConfig(config)
1311

14-
clientConfig.user.should.equal('brian')
15-
clientConfig.password.should.equal('pw')
16-
clientConfig.host.should.equal('boom')
17-
clientConfig.port.should.equal(381)
18-
clientConfig.database.should.equal('lala')
12+
clientConfig.user?.should.equal('brian')
13+
clientConfig.password?.should.equal('pw')
14+
clientConfig.host?.should.equal('boom')
15+
clientConfig.port?.should.equal(381)
16+
clientConfig.database?.should.equal('lala')
1917
})
2018

2119
it('converts query params', function () {
@@ -24,45 +22,47 @@ describe('toClientConfig', function () {
2422
)
2523
const clientConfig = toClientConfig(config)
2624

27-
clientConfig.application_name.should.equal('TheApp')
28-
clientConfig.fallback_application_name.should.equal('TheAppFallback')
29-
clientConfig.client_encoding.should.equal('utf8')
30-
clientConfig.options.should.equal('-c geqo=off')
25+
clientConfig.application_name?.should.equal('TheApp')
26+
clientConfig.fallback_application_name?.should.equal('TheAppFallback')
27+
clientConfig.client_encoding?.should.equal('utf8')
28+
clientConfig.options?.should.equal('-c geqo=off')
3129
})
3230

3331
it('converts SSL boolean', function () {
3432
const config = parse('pg:///?ssl=true')
3533
const clientConfig = toClientConfig(config)
3634

37-
clientConfig.ssl.should.equal(true)
35+
clientConfig.ssl?.should.equal(true)
3836
})
3937

4038
it('converts sslmode=disable', function () {
4139
const config = parse('pg:///?sslmode=disable')
4240
const clientConfig = toClientConfig(config)
4341

44-
clientConfig.ssl.should.equal(false)
42+
clientConfig.ssl?.should.equal(false)
4543
})
4644

4745
it('converts sslmode=noverify', function () {
4846
const config = parse('pg:///?sslmode=no-verify')
4947
const clientConfig = toClientConfig(config)
5048

51-
clientConfig.ssl.rejectUnauthorized.should.equal(false)
49+
clientConfig.ssl?.should.deep.equal({
50+
rejectUnauthorized: false,
51+
})
5252
})
5353

5454
it('converts other sslmode options', function () {
5555
const config = parse('pg:///?sslmode=verify-ca')
5656
const clientConfig = toClientConfig(config)
5757

58-
clientConfig.ssl.should.deep.equal({})
58+
clientConfig.ssl?.should.deep.equal({})
5959
})
6060

6161
it('converts other sslmode options', function () {
6262
const config = parse('pg:///?sslmode=verify-ca')
6363
const clientConfig = toClientConfig(config)
6464

65-
clientConfig.ssl.should.deep.equal({})
65+
clientConfig.ssl?.should.deep.equal({})
6666
})
6767

6868
it('converts ssl cert options', function () {
@@ -77,7 +77,7 @@ describe('toClientConfig', function () {
7777
const config = parse(connectionString)
7878
const clientConfig = toClientConfig(config)
7979

80-
clientConfig.ssl.should.deep.equal({
80+
clientConfig.ssl?.should.deep.equal({
8181
ca: 'example ca\n',
8282
cert: 'example cert\n',
8383
key: 'example key\n',
@@ -87,9 +87,9 @@ describe('toClientConfig', function () {
8787
it('converts unix domain sockets', function () {
8888
const config = parse('socket:/some path/?db=my[db]&encoding=utf8&client_encoding=bogus')
8989
const clientConfig = toClientConfig(config)
90-
clientConfig.host.should.equal('/some path/')
91-
clientConfig.database.should.equal('my[db]', 'must to be escaped and unescaped through "my%5Bdb%5D"')
92-
clientConfig.client_encoding.should.equal('utf8')
90+
clientConfig.host?.should.equal('/some path/')
91+
clientConfig.database?.should.equal('my[db]', 'must to be escaped and unescaped through "my%5Bdb%5D"')
92+
clientConfig.client_encoding?.should.equal('utf8')
9393
})
9494

9595
it('handles invalid port', function () {
@@ -106,20 +106,20 @@ describe('toClientConfig', function () {
106106

107107
const clientConfig = toClientConfig(config)
108108

109-
clientConfig.host.should.equal('boom')
110-
clientConfig.database.should.equal('lala')
111-
clientConfig.ssl.should.deep.equal({})
109+
clientConfig.host?.should.equal('boom')
110+
clientConfig.database?.should.equal('lala')
111+
clientConfig.ssl?.should.deep.equal({})
112112
})
113113
})
114114

115115
describe('parseIntoClientConfig', function () {
116116
it('converts url', function () {
117117
const clientConfig = parseIntoClientConfig('postgres://brian:pw@boom:381/lala')
118118

119-
clientConfig.user.should.equal('brian')
120-
clientConfig.password.should.equal('pw')
121-
clientConfig.host.should.equal('boom')
122-
clientConfig.port.should.equal(381)
123-
clientConfig.database.should.equal('lala')
119+
clientConfig.user?.should.equal('brian')
120+
clientConfig.password?.should.equal('pw')
121+
clientConfig.host?.should.equal('boom')
122+
clientConfig.port?.should.equal(381)
123+
clientConfig.database?.should.equal('lala')
124124
})
125125
})

0 commit comments

Comments
 (0)