Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- 'doc/**'
- '.github/workflows/docs.yml'
- 'package.json'
- 'package-lock.json'
- 'pnpm-lock.yaml'
workflow_dispatch:

permissions:
Expand All @@ -24,13 +24,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: pnpm/action-setup@v6
- uses: actions/setup-node@v7
with:
node-version: 22
cache: npm
cache: pnpm
# Native modules (sqlite3) aren't needed to build the docs.
- run: npm ci --ignore-scripts
- run: npm run docs:build
- run: pnpm install --frozen-lockfile --ignore-scripts
- run: pnpm docs:build
- uses: actions/upload-pages-artifact@v5
with:
path: doc/.vitepress/dist
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,29 @@ jobs:
steps:
- uses: actions/checkout@v7

- uses: pnpm/action-setup@v6

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node-version }}
cache: pnpm

- name: Install dependencies
run: npm ci
run: pnpm install --frozen-lockfile

# The generated parsers have to match their grammars. One job is enough.
- name: Check the generated parsers
if: matrix.node-version == '24.x' && matrix.database == 'default'
run: |
npm run build:parsers
pnpm build:parsers
git diff --exit-code lib/queryBuilder/parsers

# The documented minimum TypeScript version has to compile the typings
# and their tests. One job is enough.
- name: Check the typings with TypeScript 5.1
if: matrix.node-version == '24.x' && matrix.database == 'default'
run: npx --yes -p typescript@5.1.6 tsc
run: pnpm dlx --package=typescript@5.1.6 tsc

# Cache the database images, as their registries rate limit anonymous
# pulls. The month in the key picks up updates of their floating tags.
Expand Down Expand Up @@ -95,7 +98,7 @@ jobs:
docker save -o "$IMAGES_PATH" $IMAGES
fi
fi
npm run db:up -- $SERVICES
pnpm db:up $SERVICES

- name: Save database images
if: steps.cache.outcome == 'success' && steps.cache.outputs.cache-hit != 'true'
Expand All @@ -106,12 +109,12 @@ jobs:

- name: Run tests
if: matrix.database == 'default'
run: npm test
run: pnpm test

# The MySQL 5.7 and SQL Server jobs only run the tests of their database,
# the other jobs already lint and check typings.
- name: Run the tests of the database
if: matrix.database != 'default'
env:
DATABASES: ${{ matrix.database == 'mysql-5.7' && 'mysql' || matrix.database == 'mssql' && 'mssql' || '' }}
run: npx vitest run
run: pnpm vitest run
34 changes: 17 additions & 17 deletions doc/guide/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,39 @@ For a pull request to get merged it needs to have the following things:
git clone git@github.com:<your-account>/objection.git
```

3. **Run `npm ci` at the root of the repo**
3. **Run `pnpm install` at the root of the repo**

4. **Run `npm run docs:dev` and go to `http://localhost:5173/objection/` to see the generated documentation site when you change the markdown files in the `doc` folder.**
4. **Run `pnpm docs:dev` and go to `http://localhost:5173/objection/` to see the generated documentation site when you change the markdown files in the `doc` folder.**

## Running the tests

You need Node.js `^20.19.0 || >=22.12.0`. [Docker](https://www.docker.com/) is optional, but the easiest way to run the tests against all supported databases:
You need Node.js `^20.19.0 || >=22.12.0` and [pnpm](https://pnpm.io/). [Docker](https://www.docker.com/) is optional, but the easiest way to run the tests against all supported databases:

```bash
npm ci
npm run db:up # Start the PostgreSQL and MySQL test databases.
npm test
npm run db:down # Stop the test databases and delete their data.
pnpm install
pnpm db:up # Start the PostgreSQL and MySQL test databases.
pnpm test
pnpm db:down # Stop the test databases and delete their data.
```

Docker only runs the two database servers, PostgreSQL 17 and MySQL 8.4, as defined in `docker-compose.yml`, which needs Docker Compose 2.23.1 or newer. The tests themselves run on your machine with your Node.js, and SQLite runs inside the test process. The containers create the `objection` user and the `objection_test` database on their own, so there is nothing else to set up.

`npm run db:up` returns once both databases accept connections. They listen on the ports 55432 (PostgreSQL) and 33306 (MySQL), so they don't collide with databases that you may have installed locally. The data isn't kept: `npm run db:down` removes the containers together with their data, and the next `npm run db:up` starts from scratch.
`pnpm db:up` returns once both databases accept connections. They listen on the ports 55432 (PostgreSQL) and 33306 (MySQL), so they don't collide with databases that you may have installed locally. The data isn't kept: `pnpm db:down` removes the containers together with their data, and the next `pnpm db:up` starts from scratch.

CI also runs the tests on MySQL 5.7. To do that locally, add its override file: `COMPOSE_FILE=docker-compose.yml:docker-compose.mysql57.yml npm run db:up`.
CI also runs the tests on MySQL 5.7. To do that locally, add its override file: `COMPOSE_FILE=docker-compose.yml:docker-compose.mysql57.yml pnpm db:up`.

CI also runs the tests on SQL Server 2022. Its image is large and runs emulated on arm64, so `npm run db:up` doesn't start it, and `npm test` only runs its tests when they are requested:
CI also runs the tests on SQL Server 2022. Its image is large and runs emulated on arm64, so `pnpm db:up` doesn't start it, and `pnpm test` only runs its tests when they are requested:

```bash
npm run db:up -- mssql # Start SQL Server, on the port 51433.
DATABASES=mssql npm run test:fast
pnpm db:up mssql # Start SQL Server, on the port 51433.
DATABASES=mssql pnpm test:fast
```

You can run the tests on a subset of databases by setting the `DATABASES` env variable. SQLite needs no setup, so this works without Docker:

```bash
DATABASES=sqlite3 npm test
DATABASES=postgres npm test
DATABASES=sqlite3 pnpm test
DATABASES=postgres pnpm test
```

To use your own databases instead, set the `OBJECTION_TEST_POSTGRES_*`, `OBJECTION_TEST_MYSQL_*` and `OBJECTION_TEST_MSSQL_*` env variables. The PostgreSQL user needs to own the database or be a superuser, as the tests create schemas in it. The MySQL user needs to be able to create databases and to use the `mysql_native_password` authentication plugin. The SQL Server user needs to be able to create tables and sequences.
Expand All @@ -86,10 +86,10 @@ To use your own databases instead, set the `OBJECTION_TEST_POSTGRES_*`, `OBJECTI

The SQLite tests use a new database file in the system's temporary directory for each run, which is deleted afterwards. Set `OBJECTION_TEST_SQLITE_FILE` to use a file of your choice, which is kept.

The tests are run with [vitest](https://vitest.dev/). `npm test` also lints the code and checks the typings. Use `npm run test:fast` to only run the tests, stopping at the first failure, or `npm run test:watch` to rerun them whenever files change.
The tests are run with [vitest](https://vitest.dev/). `pnpm test` also lints the code and checks the typings. Use `pnpm test:fast` to only run the tests, stopping at the first failure, or `pnpm test:watch` to rerun them whenever files change.

SQL Server can't insert explicit values into auto-incrementing (identity) columns. Tests that insert rows with explicit ids create their tables with `session.createTable()` instead of `knex.schema.createTable()`, and their id columns with the `increments()` it passes to the callback.

[prettier](https://prettier.io/) is used to format the code. Remember to run `npm run prettier` before committing code.
[prettier](https://prettier.io/) is used to format the code. Remember to run `pnpm prettier` before committing code.

The parsers of relation expressions and JSON field expressions in `lib/queryBuilder/parsers` are generated from the `.pegjs` grammars next to them with [Peggy](https://peggyjs.org/). After changing a grammar, run `npm run build:parsers` (Peggy 5 needs Node 20 or newer) and commit the generated files with it. CI checks that they match the grammars.
The parsers of relation expressions and JSON field expressions in `lib/queryBuilder/parsers` are generated from the `.pegjs` grammars next to them with [Peggy](https://peggyjs.org/). After changing a grammar, run `pnpm build:parsers` (Peggy 5 needs Node 20 or newer) and commit the generated files with it. CI checks that they match the grammars.
2 changes: 1 addition & 1 deletion docker-compose.mysql57.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Runs the MySQL tests on MySQL 5.7, used by its own CI job:
# COMPOSE_FILE=docker-compose.yml:docker-compose.mysql57.yml npm run db:up
# COMPOSE_FILE=docker-compose.yml:docker-compose.mysql57.yml pnpm db:up
services:
mysql:
image: 'mysql:5.7'
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ services:
image: 'mcr.microsoft.com/mssql/server:2022-latest'
# There is no arm64 image of SQL Server.
platform: linux/amd64
# Only started on request, e.g. `npm run db:up -- mssql`, as the image is
# Only started on request, e.g. `pnpm db:up mssql`, as the image is
# large and runs emulated on arm64.
profiles: [mssql]
ports:
Expand Down
Loading
Loading