Skip to content

Commit

Permalink
Merge pull request #4 from shelfio/develop
Browse files Browse the repository at this point in the history
V1.0.0
  • Loading branch information
harazdovskiy authored Dec 27, 2022
2 parents 10d7a45 + 7926992 commit 9cd97a0
Show file tree
Hide file tree
Showing 20 changed files with 245 additions and 128 deletions.
10 changes: 6 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
orbs:
node: circleci/[email protected].3
node: circleci/[email protected].2

version: 2.1

parameters:
node_version:
type: string
default: '16.15.1'
default: '16.17.0'

commands:
install_deps:
Expand All @@ -17,16 +17,18 @@ commands:
cache-only-lockfile: true
app-dir: ~/repo
override-ci-command: yarn install --pure-lockfile --no-progress
- run: sudo apt update -q && sudo apt install postgresql-12

jobs:
build:
executor:
name: node/default
tag: << pipeline.parameters.node_version >>
tag: <<pipeline.parameters.node_version>>
working_directory: ~/repo
steps:
- checkout
- install_deps
- run: yarn test
- run: yarn build
- run: sudo yarn test
- run: yarn type-check
- run: yarn lint:ci
Empty file modified .eslintignore
100755 → 100644
Empty file.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"root": true,
"extends": [
"@shelf/eslint-config/typescript"
]
],
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
31 changes: 6 additions & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
.vscode/
.serverless/
.idea/
.idea/aws.xml
coverage/
lib/
node_modules/

*.log
junit.xml
draft.js
*.draft.js
draft.ts
*.draft.ts
lib/
temp
yarn.lock

.env
*.log
.DS_Store

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/shelf

# File-based project format
*.iws

.idea/$CACHE_FILE$
.idea/$PRODUCT_WORKSPACE_FILE$
.idea/.gitignore
globalConfig.json
!.husky/_/husky.sh
3 changes: 1 addition & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn lint-staged --shell "/bin/sh" --verbose

yarn lint-staged
11 changes: 0 additions & 11 deletions .husky/validate-circleci-config.sh

This file was deleted.

30 changes: 0 additions & 30 deletions README.md

This file was deleted.

7 changes: 7 additions & 0 deletions jest-postgres-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import cwd from 'cwd';

module.exports = {
seedPath: `${cwd()}/test/seed.sql`,
version: 12,
port: 5555,
};
3 changes: 3 additions & 0 deletions jest-preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const preset = require('./lib');

module.exports = preset;
77 changes: 47 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,61 +1,78 @@
{
"name": "@shelf/xxxxxx",
"version": "0.0.0",
"description": "xxxxxx",
"name": "@shelf/jest-postgres",
"version": "1.0.0",
"private": false,
"description": "Run your tests using Jest & Postgres",
"keywords": [
"jest",
"jest environment",
"jest preset",
"postgres",
"postgres local"
],
"repository": "shelfio/jest-postgres",
"license": "MIT",
"author": {
"name": "Vlad Holubiev",
"email": "vlad@shelf.io",
"url": "https://shelf.io"
"name": "Dmytro Harazdovskyi",
"email": "dmytro.harazdovskyi@shelf.io",
"url": "shelf.io"
},
"main": "lib",
"types": "lib/index.d.ts",
"files": [
"lib"
"jest-preset.js",
"lib/"
],
"scripts": {
"build": "rm -rf lib/ && yarn build:types && yarn build:code",
"build:code": "babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts' && find ./lib -name '*.test.d.ts' -delete",
"build": "rm -rf lib/ && yarn build:types && babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts'",
"build:types": "tsc --emitDeclarationOnly --declaration --isolatedModules false --declarationDir lib",
"coverage": "yarn test --coverage",
"lint": "yarn lint:ci --fix",
"lint": "eslint . --ext .js,.ts,.json --fix",
"lint:ci": "eslint . --ext .js,.ts,.json",
"prepack": "yarn build",
"test": "TZ=UTC jest src",
"test": "jest",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch"
},
"lint-staged": {
"*.{html,md,yml}": [
"prettier --write"
],
"*.{js,ts,json}": [
"*.{ts,js,json}": [
"eslint --fix"
],
".circleci/config.yml": [
".husky/validate-circleci-config.sh"
]
},
"babel": {
"extends": "@shelf/babel-config/backend"
},
"prettier": "@shelf/prettier-config",
"dependencies": {},
"jest": {
"preset": "./jest-preset.js"
},
"dependencies": {
"@shelf/postgres-local": "1.0.3",
"cwd": "0.10.0"
},
"devDependencies": {
"@babel/cli": "7.19.3",
"@babel/core": "7.20.5",
"@babel/cli": "7.20.7",
"@babel/core": "7.20.7",
"@shelf/babel-config": "1.2.0",
"@shelf/eslint-config": "2.26.0",
"@shelf/eslint-config": "2.22.3",
"@shelf/prettier-config": "1.0.0",
"@shelf/tsconfig": "0.0.9",
"@types/jest": "29.2.4",
"@shelf/tsconfig": "0.0.8",
"@types/cwd": "0.10.0",
"@types/jest": "29.2.0",
"@types/node": "16",
"eslint": "8.29.0",
"husky": "8.0.2",
"jest": "29.3.1",
"lint-staged": "13.1.0",
"prettier": "2.8.1",
"typescript": "4.9.4"
"cwd": "0.10.0",
"eslint": "8.30.0",
"husky": "8.0.1",
"jest": "29.2.1",
"knex": "2.3.0",
"lint-staged": "13.0.3",
"pg": "8.8.0",
"prettier": "2.7.1",
"typescript": "4.8.4"
},
"peerDependencies": {
"jest-environment-node": "27.x.x || 28.x || 29.x",
"pg": "*"
},
"engines": {
"node": ">=16"
Expand Down
56 changes: 56 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# jest-postgres [![CircleCI](https://circleci.com/gh/shelfio/jest-postgres/tree/master.svg?style=svg)](https://circleci.com/gh/shelfio/jest-postgres/tree/master) ![](https://img.shields.io/badge/code_style-prettier-ff69b4.svg) [![npm (scoped)](https://img.shields.io/npm/v/@shelf/jest-postgres.svg)](https://www.npmjs.com/package/@shelf/jest-postgres)

> Jest preset to run Postgres server
## Usage

### 0. Install

```
$ yarn add @shelf/jest-postgres --dev
```

### 1. Create `jest.config.js`

```js
module.exports = {
preset: '@shelf/jest-postgres'
};
```

If you have a custom `jest.config.js` make sure you remove `testEnvironment` property, otherwise it will conflict with the preset.

### 2. Create `jest-postgres-config.js`

```js
import cwd from 'cwd';

module.exports = {
seedPath: `${cwd()}/test/seed.sql`,
version: 14,
port: 5555,
};
```
Find `seed.sql` example in `./test` folder of this repo
### 4. PROFIT! Write tests

```js
it();
```

## See Also

- [jest-dynamodb](https://github.com/shelfio/jest-dynamodb)

## Publish

```sh
$ git checkout master
$ yarn version
$ yarn publish
$ git push origin master --tags
```

## License

MIT © [Shelf](https://shelf.io)
6 changes: 1 addition & 5 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"extends": ["config:base"],
"labels": ["dependencies", "backend"],
"ignoreDeps": [
"cimg/node",
"@types/node"
]
"labels": ["dependencies", "backend"]
}
5 changes: 0 additions & 5 deletions src/index.test.ts

This file was deleted.

9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export function getFoo(): string {
return 'bar';
}
import {resolve} from 'path';

module.exports = {
globalSetup: resolve(__dirname, './setup.js'),
globalTeardown: resolve(__dirname, './teardown.js'),
};
10 changes: 10 additions & 0 deletions src/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {start} from '@shelf/postgres-local';
import cwd from 'cwd';

const config = require(`${cwd()}/jest-postgres-config.js`);

module.exports = async function startPostgres() {
await start(config);

return true;
};
8 changes: 8 additions & 0 deletions src/teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {stop} from '@shelf/postgres-local';
import cwd from 'cwd';

const config = require(`${cwd()}/jest-postgres-config.js`);

module.exports = async function stopPostgres() {
await stop(config);
};
35 changes: 35 additions & 0 deletions test/client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {closeConnection, getClient} from './client';

describe('#getClient', () => {
const client = getClient({
host: 'localhost',
port: 5555,
username: '',
password: '',
database: 'postgres',
});

it('should use 5555 port and insert records', async () => {
await client.withSchema('test').table('model1').insert({
id: 'unique',
type: 'some text',
text: 'should be text',
});

const res = await client.withSchema('test').table('model1').select('*').where({id: 'unique'});

expect(res).toEqual([
{
id: 'unique',
json: null,
somebool: null,
text: 'should be text',
type: 'some text',
updated_at: null,
vector: null,
},
]);

await closeConnection();
});
});
Loading

0 comments on commit 9cd97a0

Please sign in to comment.