-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a **BREAKING** change that: - adds tests against the [upstream `sharedb` DB test suite][1] - adds a CI build for the tests against current Node.js and Postgres versions - breaks the API to conform to the upstream tests, including adding metadata support The breaks are: - Dropping non-null constraints on `snapshots.doc_type` and `snapshots.data` - Adding a new `snapshots.metadata` `json` column - Respecting `options.metadata` and `fields.$submit`, which were previously ignored on `getOps()`, and useless on `getSnapshot()` (which didn't store metadata) - `snapshot.m` is now `undefined` if not present, or `null` if unrequested (inline with the spec) On top of this it also makes some bugfixes to conform to the spec: - Ignore unique key validations when committing, since this may happen during concurrent commits - `JSON.stringify()` JSON fields, which [break][2] if passed a raw array - Default `from = 0` if unset in `getOps()` [1]: https://github.com/share/sharedb/blob/7abe65049add9b58e1df638aa34e7ca2c0a1fcfa/test/db.js#L25 [2]: brianc/node-postgres#442
- Loading branch information
1 parent
4b5b537
commit 48f1221
Showing
8 changed files
with
2,350 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- setup-ci # TODO: Remove | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
name: Node.js ${{ matrix.node }} + PostgreSQL ${{ matrix.postgres }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node: | ||
- 16 | ||
- 18 | ||
- 20 | ||
postgres: | ||
- 13 | ||
- 14 | ||
- 15 | ||
- 16 | ||
services: | ||
postgres: | ||
image: postgres:${{ matrix.postgres }} | ||
env: | ||
POSTGRES_HOST_AUTH_METHOD: trust | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
ports: | ||
- 5432:5432 | ||
timeout-minutes: 10 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- name: Install | ||
run: npm install | ||
- name: Test | ||
run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
timeout: 5_000, | ||
file: './test/setup.js', | ||
spec: '**/*.spec.js', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const PostgresDB = require('.'); | ||
const {Pool} = require('pg'); | ||
const fs = require('node:fs'); | ||
|
||
const DB_NAME = 'sharedbtest'; | ||
|
||
function create(callback) { | ||
var db = new PostgresDB({database: DB_NAME}); | ||
callback(null, db); | ||
}; | ||
|
||
describe('PostgresDB', function() { | ||
let pool; | ||
let client; | ||
|
||
beforeEach(async () => { | ||
pool = new Pool({database: 'postgres'}); | ||
client = await pool.connect(); | ||
await client.query(`DROP DATABASE IF EXISTS ${DB_NAME}`); | ||
await client.query(`CREATE DATABASE ${DB_NAME}`); | ||
|
||
const testPool = new Pool({database: DB_NAME}); | ||
const testClient = await testPool.connect(); | ||
const structure = fs.readFileSync('./structure.sql', 'utf8'); | ||
await testClient.query(structure); | ||
await testClient.release(true); | ||
await testPool.end(); | ||
}); | ||
|
||
afterEach(async function() { | ||
await client.query(`DROP DATABASE IF EXISTS ${DB_NAME}`); | ||
await client.release(true); | ||
await pool.end(); | ||
}); | ||
|
||
require('sharedb/test/db')({create: create}); | ||
}); |
Oops, something went wrong.