Skip to content

Commit 6be857e

Browse files
committed
chore(pg-connection-string): use tsx for tests
1 parent 9bfc967 commit 6be857e

File tree

11 files changed

+1043
-154
lines changed

11 files changed

+1043
-154
lines changed

packages/pg-connection-string/.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ lib-cov
1212

1313
# Coverage directory used by tools like istanbul
1414
coverage
15+
.nyc_output
1516

1617
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
1718
.grunt
@@ -23,4 +24,7 @@ build/Release
2324
# Deployed apps should consider commenting this line out:
2425
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
2526
node_modules
26-
package-lock.json
27+
package-lock.json
28+
29+
# TypeScript output directory
30+
dist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extension": ["js", "ts"],
3+
"require": "tsx"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"processes":{"7702f7d6-fe80-4107-8fc1-2818e7cb6a88":{"parent":null,"children":[]}},"files":{"/Users/herman/Code/node-postgres/packages/pg-connection-string/index.js":["7702f7d6-fe80-4107-8fc1-2818e7cb6a88"]},"externalIds":{}}

packages/pg-connection-string/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ pg-connection-string
33

44
[![NPM](https://nodei.co/npm/pg-connection-string.png?compact=true)](https://nodei.co/npm/pg-connection-string/)
55

6-
[![Build Status](https://travis-ci.org/iceddev/pg-connection-string.svg?branch=master)](https://travis-ci.org/iceddev/pg-connection-string)
7-
[![Coverage Status](https://coveralls.io/repos/github/iceddev/pg-connection-string/badge.svg?branch=master)](https://coveralls.io/github/iceddev/pg-connection-string?branch=master)
8-
96
Functions for dealing with a PostgresSQL connection string
107

118
`parse` method taken from [node-postgres](https://github.com/brianc/node-postgres.git)

packages/pg-connection-string/index.d.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,29 @@ export interface Options {
77
useLibpqCompat?: boolean
88
}
99

10+
interface SSLConfig {
11+
ca?: string
12+
cert?: string | null
13+
key?: string
14+
rejectUnauthorized?: boolean
15+
}
16+
1017
export interface ConnectionOptions {
1118
host: string | null
1219
password?: string
1320
user?: string
1421
port?: string | null
1522
database: string | null | undefined
1623
client_encoding?: string
17-
ssl?: boolean | string
24+
ssl?: boolean | string | SSLConfig
1825

1926
application_name?: string
2027
fallback_application_name?: string
2128
options?: string
29+
keepalives?: number
30+
31+
// We allow any other options to be passed through
32+
[key: string]: unknown
2233
}
2334

2435
export function toClientConfig(config: ConnectionOptions): ClientConfig

packages/pg-connection-string/index.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,8 @@ function toClientConfig(config) {
169169
if (typeof sslConfig === 'boolean') {
170170
c[key] = sslConfig
171171
}
172-
// else path is taken. multiple tests produce a sslConfig that is an object
173-
// and we can console.log to see that we take this path
174-
//
175-
// see https://github.com/istanbuljs/babel-plugin-istanbul/issues/186#issuecomment-1137765139
176-
// istanbul ignore else
177-
else if (typeof sslConfig === 'object') {
172+
173+
if (typeof sslConfig === 'object') {
178174
c[key] = toConnectionOptions(sslConfig)
179175
}
180176
} else if (value !== undefined && value !== null) {

packages/pg-connection-string/package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
}
1414
},
1515
"scripts": {
16-
"test": "istanbul cover _mocha && npm run check-coverage",
17-
"check-coverage": "istanbul check-coverage --statements 100 --branches 100 --lines 100 --functions 100",
18-
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
16+
"test": "nyc --reporter=lcov mocha && npm run check-coverage",
17+
"check-coverage": "nyc check-coverage --statements 100 --branches 100 --lines 100 --functions 100"
1918
},
2019
"repository": {
2120
"type": "git",
@@ -35,10 +34,14 @@
3534
},
3635
"homepage": "https://github.com/brianc/node-postgres/tree/master/packages/pg-connection-string",
3736
"devDependencies": {
37+
"@types/pg": "^8.12.0",
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+
"nyc": "^15",
43+
"tsx": "^4.19.4",
44+
"typescript": "^4.0.3"
4245
},
4346
"files": [
4447
"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)