Skip to content

test: add integration suite against real PostgreSQL and MySQL#236

Open
Puppo wants to merge 7 commits into
nearform:masterfrom
Puppo:test/integration-pg-mysql
Open

test: add integration suite against real PostgreSQL and MySQL#236
Puppo wants to merge 7 commits into
nearform:masterfrom
Puppo:test/integration-pg-mysql

Conversation

@Puppo

@Puppo Puppo commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

What

Adds a Docker-backed integration test suite that executes queries built by every public API of @nearform/sql against real PostgreSQL and MySQL. The existing tests only assert generated strings without ever running them, so regressions in placeholder numbering, identifier quoting, nested-statement offsets, or injection handling could pass CI while breaking real queries.

Coverage

11 cases × 3 drivers (pg, mysql2, legacy mysql) = 33 tests, all executed end-to-end:

  • Basic parameterized insert/select round-trip
  • Interpolated values stored as literals, not executed (injection)
  • glue — IN clause + batch insert
  • map — IN clause (default & object mapper)
  • quoteIdent — dynamic table/column names + escaping the quote char on a live identifier
  • unsafe — literal fragment interpolation
  • Nested SqlStatement — proves $N placeholder numbering against a live server
  • Deprecated append
  • Null values
  • Special characters / unicode round-trip

Changes

  • integration/ — config + driver adapters (one query/raw/end interface) + a single dialect-aware feature suite shared by all three drivers.
  • docker-compose.yml — add mysql:8.0 service with healthchecks, bump Postgres to 17-alpine.
  • package.json — add mysql/mysql2 devDeps and db:up, db:down, test:integration, test:integration:docker scripts.
  • .github/workflows/ci.yml — add MySQL service + integration test step.
  • README.md — document the new commands.

Notes

  • The legacy mysql driver can't speak MySQL 8's default caching_sha2_password, so the adapter uses a short mysql2 connection to switch the account to mysql_native_password first — works identically locally and in CI without a container command override (unsupported by GitHub service containers).
  • Integration tests run with --test-concurrency=1 because both MySQL drivers share one sqlmap database; the pg suite is isolated in its own DB.

Verification

  • All 33 integration tests pass against live Postgres + MySQL.
  • npm test (unit) still passes and needs no DB; npm run lint clean.
  • Regression check: deliberately broke the $N offset logic → nested-statement pg test failed as intended → reverted.

Run locally with npm run test:integration:docker.

Puppo added 2 commits June 10, 2026 02:09
Executes queries built by every public API (params, glue, map, quoteIdent,
unsafe, nested statements, append, nulls, special chars, injection-as-literal)
against live PostgreSQL and MySQL (both mysql and mysql2 drivers), proving the
generated SQL is valid and that interpolated values are stored as literals.

- docker-compose: add mysql:8.0 service + healthchecks, bump postgres to 17
- package.json: add mysql/mysql2 devDeps and db:up/db:down/test:integration scripts
- ci: add MySQL service and integration test step
- README: document the integration commands
@github-actions

Copy link
Copy Markdown

No linked issues found. Please add the corresponding issues in the pull request description.
Use GitHub automation to close the issue when a PR is merged

Puppo added 5 commits June 10, 2026 02:14
Run pg and mysql integration suites in two independent jobs, each with its own
DB service and matrix, instead of spinning up MySQL for every Postgres version.
Add granular test:integration:pg / test:integration:mysql scripts.
The legacy `mysql` driver only supports mysql_native_password, which is
removed/disabled in MySQL 8.4+/9, so it cannot connect there. Give it its own
connection namespace (MYSQLLEGACY*) pointing at a dedicated MySQL 8.0 server,
and split CI into separate mysql2 (8 & 9 matrix) and legacy mysql (8.0) jobs.
Add a mysql8 service to docker-compose for local runs.
- config: add allowPublicKeyRetrieval to mysql configs (hardens caching_sha2
  auth over non-TLS across MySQL images/versions)
- helpers: extract runFile.js to remove triplicated connection-lifecycle
  boilerplate from the three test files
- featureSuite: add coverage for append({ unsafe: true }) literal interpolation
- docker-compose: drop obsolete `version` key
@Puppo Puppo marked this pull request as ready for review June 10, 2026 00:39
@simoneb simoneb requested a review from Copilot June 10, 2026 22:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a Docker-backed integration test suite that executes SQL built by @nearform/sql against real PostgreSQL and MySQL instances (including both mysql2 and legacy mysql drivers), and wires it into local scripts and CI to catch regressions that string-only unit tests can’t detect.

Changes:

  • Add a shared, dialect-aware integration feature suite plus per-driver test entrypoints and connection adapters.
  • Add Docker Compose services for Postgres + modern MySQL + MySQL 8.0 (legacy auth) and new npm scripts to run the suite locally.
  • Expand GitHub Actions CI to run the new integration suite across multiple Node and database versions.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
README.md Documents new integration and docker helper scripts and environment variables.
package.json Adds DB lifecycle + integration test scripts and MySQL driver devDependencies.
integration/SQL.pg.integration.test.js PostgreSQL integration test entrypoint wiring shared suite + pg adapter.
integration/SQL.mysql2.integration.test.js mysql2 integration test entrypoint wiring shared suite + mysql2 adapter.
integration/SQL.mysql.integration.test.js Legacy mysql integration test entrypoint wiring shared suite + mysql adapter.
integration/shared/featureSuite.js Implements the end-to-end feature matrix executed against live DBs.
integration/helpers/runFile.js Provides shared node:test lifecycle wiring (before/after) for adapters.
integration/helpers/db.js Adds driver adapters and creates the portable users table for tests.
integration/helpers/config.js Defines env-driven connection configuration for pg/mysql/mysql-legacy.
docker-compose.yml Adds MySQL services and healthchecks; bumps Postgres image.
.github/workflows/ci.yml Adds dedicated MySQL integration jobs and a Postgres integration step.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json
"test:integration:pg": "node --test integration/SQL.pg.integration.test.js",
"test:integration:mysql2": "node --test integration/SQL.mysql2.integration.test.js",
"test:integration:mysql": "node --test integration/SQL.mysql.integration.test.js",
"test:integration:docker": "npm run db:up && npm run test:integration; npm run db:down",
Comment thread .github/workflows/ci.yml
Comment on lines 51 to 54
- name: Lint
run: npm run lint
- name: Test
run: npm test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants