Skip to content

Commit

Permalink
chore!: update supported Slonik version to ≥35.0.0 <38 (#24)
Browse files Browse the repository at this point in the history
* chore(deps): upgrade slonik to v35

* fix: mirror createPool factory logic to slonik

* chore: add slonik v35.2.1, v36.0.0 to test matrix

* chore: test slonik v35 and v36

* chore(deps): update to slonik v37

* chore: add slonik v37.0.1 to test matrix

* chore(deps): update to mocha ^10.2.0 as peerDeps

* docs: update version compatibilty chart

* docs: add the purpose behind mocha-slonik and its intended usage

BREAKING CHANGE: Drops support for Slonik v34 and earlier.
  • Loading branch information
AndrewJo committed Oct 16, 2023
1 parent 9f64508 commit 1830b68
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 129 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ workflows:
parameters:
node-version: ["16.20", "18.18"]
mocha-version: ["10"]
slonik-version: ["34.3.0"]
slonik-version: ["35.2.1", "36.0.0", "37.0.1"]
- release:
context:
- npm
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

## Table of Contents

- [Why does mocha-slonik exist?](#why-does-mocha-slonik-exist)
- [Slonik’s `createMockPool` vs `mocha-slonik`](#sloniks-createmockpool-vs-mocha-slonik)
- [How it works](#how-it-works)
- [Version compatibility](#version-compatibility)
- [Installation](#installation)
Expand All @@ -27,6 +29,23 @@
- [Limitations](#limitations)
- [Lack of `copyFromBinary` support](#lack-of-copyfrombinary-support)

## Why does mocha-slonik exist?

This package exists as a way for developers to **run integration tests against a real database
without having to worry about cleaning up the test data after each test**. Since each test cases
are wrapped in its own transaction that is automatically rolled back, you can ensure that your
tests are isolated from each other: an earlier test that affects a row does not affect subsequent
tests that may depend on the same row.

### Slonik’s `createMockPool` vs `mocha-slonik`

[Slonik][slonik] already provides a way to mock queries against the database by using a combination
of `createMockPool` and `createMockQueryResult`. This is usually sufficient for lightweight unit
testing individual functions that calls Slonik query methods and is great for running tests that
does not need a running instance of PostgreSQL.

See: [Mocking Slonik][slonik-user-content-mocking-slonik]

## How it works

mocha-slonik is a [Root Hook Plugin][root-hook-plugin] for [Mocha][mocha] that utilizes
Expand All @@ -44,6 +63,7 @@ and Mocha versions in your project.

| mocha-slonik | slonik | mocha |
| ------------: | --------------------------------: | ------: |
| ^9.0.0 | >=35.0.0 <38.0.0 | ^10.2.0 |
| ^8.0.0 | >=34.0.0 <35.0.0 | ^10.1.0 |
| ^7.0.0 | >=33.1.1 <34.0.0 | ^10.1.0 |
| ^6.0.0 | >=33.0.0 <33.1.1 | ^10.1.0 |
Expand Down Expand Up @@ -595,6 +615,7 @@ this library.
[root-hook-plugin]: https://mochajs.org/#root-hook-plugins
[ts-mock-imports]: https://github.com/EmandM/ts-mock-imports
[slonik]: https://github.com/gajus/slonik
[slonik-user-content-mocking-slonik]: https://github.com/gajus/slonik#user-content-mocking-slonik
[slonik-query-methods]: https://github.com/gajus/slonik#slonik-query-methods
[slonik-issue-161]: https://github.com/gajus/slonik/issues/161#issuecomment-604770259
[slonik-copy-from-binary]: https://github.com/gajus/slonik/releases/tag/v34.0.0
Expand Down
112 changes: 96 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
},
"homepage": "https://github.com/AndrewJo/mocha-slonik#readme",
"peerDependencies": {
"mocha": "^10.1.0",
"slonik": ">=34.0.0 <35.0.0"
"mocha": "^10.2.0",
"slonik": ">=35.0.0 <38.0.0"
},
"dependencies": {
"sinon": "^15.1.0",
Expand All @@ -68,10 +68,10 @@
"eslint-config-prettier": "^8.3.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"pg": "^8.7.1",
"pg": "^8.11.3",
"prettier": "^2.4.1",
"semantic-release": "^21.0.1",
"slonik": "^34.3.0",
"slonik": ">=35.0.0 <38.0.0",
"ts-node": "^10.9.1",
"ts-patch": "^1.4.5",
"tsconfig-paths": "^4.1.2",
Expand Down
Loading

0 comments on commit 1830b68

Please sign in to comment.