Skip to content

Commit

Permalink
chore: fix actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ppati000 committed Sep 21, 2023
1 parent 9881cc5 commit 50ca316
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 74 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"browser": true,
"es2021": true
},
"extends": [
"standard-with-typescript",
"prettier"
],
"extends": ["standard-with-typescript", "prettier"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
Expand Down
29 changes: 22 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,38 @@ on:
push: {}

jobs:
build:
test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres
env:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker
uses: docker/setup-docker-action@v1
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Install dependencies
run: npm install
run: npm ci

- name: Run tests
run: npm run test

- name: Run build
run: npm run build
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5433:5432"
- '5432:5432'
2 changes: 1 addition & 1 deletion lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PGBounceGuardError } from "./error";
import { PGBounceGuardError } from './error'

export type Action = 'warn' | 'error'
export type ActionOrIgnore = Action | 'ignore'
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
"description": "Debug tool for pg (node-postgres) that blocks/logs queries that are incompatible with PgBouncer's transaction pooling mode.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"engines": {
"node": ">=18.0.0"
},
"scripts": {
"prepublish": "tsc --project tsconfig.build.json",
"build": "tsc --project tsconfig.build.json",
"prepublish": "npm run build",
"lint": "eslint",
"format:check": "prettier . --check",
"format": "prettier . --write",
"pretest": "docker compose up -d && sleep 5",
"test": "tape -r ts-node/register test/*.ts",
"posttest": "docker compose down"
"test:docker": "docker compose up -d && sleep 5 && tape -r ts-node/register test/*.ts; docker compose down"
},
"keywords": [],
"author": "",
Expand Down
10 changes: 5 additions & 5 deletions test/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import test from 'tape'
import { PGBounceGuard } from '../lib/pgBounceGuard'
import { Client } from 'pg'
import type { PGBounceGuardError } from "../lib/error";
import type { PGBounceGuardError } from '../lib/error'

test('config options', async (t) => {
const unwrapped = new Client({
host: 'localhost',
port: 5433,
host: process.env.POSTGRES_HOST ?? 'localhost',
port: 5432,
database: 'postgres',
user: 'postgres',
password: 'postgres',
Expand All @@ -21,7 +21,7 @@ test('config options', async (t) => {
},
logFn: (err) => {
lastError = err
}
},
})

await client.connect()
Expand All @@ -33,7 +33,7 @@ test('config options', async (t) => {
})

t.test('should warn on set', async (t) => {
await client.query('SET statement_timeout = \'30s\'')
await client.query("SET statement_timeout = '30s'")
t.ok(lastError?.message.includes('SET statement'))
})
})
38 changes: 19 additions & 19 deletions test/errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,61 @@ test('errors', async (t) => {
const testCases = [
{
query: 'select * from generate_series(1, 1)',
error: null
error: null,
},
{
query: 'SET lock_timeout TO \'2s\'',
error: 'SET/RESET statement'
query: "SET lock_timeout TO '2s'",
error: 'SET/RESET statement',
},
{
query: 'RESET lock_timeout',
error: 'SET/RESET statement'
error: 'SET/RESET statement',
},
{
query: 'SET LOCAL lock_timeout TO \'2s\'',
error: null
query: "SET LOCAL lock_timeout TO '2s'",
error: null,
},
{
query: 'LISTEN foo',
error: 'LISTEN statement'
error: 'LISTEN statement',
},
{
query: 'DECLARE test_cursor SCROLL CURSOR WITH HOLD FOR SELECT * FROM generate_series(1, 1000000)',
error: 'CURSOR WITH HOLD statement'
error: 'CURSOR WITH HOLD statement',
},
{
query: 'DECLARE test_cursor SCROLL CURSOR FOR SELECT * FROM generate_series(1, 1000000)',
error: 'DECLARE CURSOR can only be used in transaction blocks' // Postgres error.
error: 'DECLARE CURSOR can only be used in transaction blocks', // Postgres error.
},
{
query: 'CREATE TEMP TABLE foo (id int)',
error: 'CREATE TEMP TABLE statement'
error: 'CREATE TEMP TABLE statement',
},
{
query: 'CREATE TEMP TABLE foo (id int) ON COMMIT DROP',
error: null
error: null,
},
{
query: 'LOAD \'test\'',
error: 'LOAD statement'
query: "LOAD 'test'",
error: 'LOAD statement',
},
{
query: 'SELECT pg_advisory_lock(1)',
error: 'pg_advisory_lock call'
error: 'pg_advisory_lock call',
},
{
query: 'SELECT * from foo where bar = pg_advisory_lock(1)',
error: 'pg_advisory_lock call'
error: 'pg_advisory_lock call',
},
{
query: 'SELECT pg_advisory_xact_lock(1)',
error: null
}
error: null,
},
]

const unwrapped = new Client({
host: 'localhost',
port: 5433,
host: process.env.POSTGRES_HOST ?? 'localhost',
port: 5432,
database: 'postgres',
user: 'postgres',
password: 'postgres',
Expand Down
14 changes: 4 additions & 10 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"compilerOptions": {
"target": "es2016",
"lib": [
"es2021"
],
"target": "es2022",
"lib": ["ES2022"],
"module": "commonjs",
"rootDir": "./lib",
"typeRoots": [
"./types"
],
"typeRoots": ["./types"],
"declaration": true,
"sourceMap": true,
"outDir": "./dist",
Expand All @@ -19,7 +15,5 @@
"alwaysStrict": true,
"skipLibCheck": true
},
"include": [
"./lib/**/*"
]
"include": ["./lib/**/*"]
}
26 changes: 2 additions & 24 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
{
"compilerOptions": {
"target": "es2016",
"lib": [
"es2021"
],
"module": "commonjs",
"rootDir": "./lib",
"typeRoots": [
"./types"
],
"declaration": true,
"sourceMap": true,
"outDir": "./dist",
"sourceRoot": ".",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"alwaysStrict": true,
"skipLibCheck": true
},
"include": [
"./lib/**/*",
"./test/**/*"
]
"extends": "./tsconfig.build.json",
"include": ["./lib/**/*", "./test/**/*"]
}

0 comments on commit 50ca316

Please sign in to comment.