Skip to content

infra: add vitest workspaces and TestContainer#1478

Merged
Shinigami92 merged 31 commits into
salsita:mainfrom
brenoepics:refactor-tests
Jul 26, 2025
Merged

infra: add vitest workspaces and TestContainer#1478
Shinigami92 merged 31 commits into
salsita:mainfrom
brenoepics:refactor-tests

Conversation

@brenoepics

Copy link
Copy Markdown
Collaborator

Follow up on #1390

Locally, it will run on pg 17 only (you can set environment variables), but it is quick enough to run everything locally, taking about 56 seconds to run 5 pg versions.

running all versions

image

running preflight with pg 17 only

image

@brenoepics
brenoepics requested a review from Shinigami92 as a code owner July 22, 2025 14:28
@github-actions

github-actions Bot commented Jul 22, 2025

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 92.53% (🎯 90%)
🟰 ±0%
3272 / 3536
🟢 Statements 92.53% (🎯 90%)
🟰 ±0%
3272 / 3536
🟢 Functions 96.66% (🎯 90%)
🟰 ±0%
261 / 270
🟢 Branches 91.18% (🎯 85%)
🟰 ±0%
869 / 953
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Unchanged Files
src/db.ts 83.18% 88.88% 87.5% 83.18% 90-92, 122, 125-137, 177-179
src/index.ts 100% 100% 100% 100%
src/logger.ts 100% 100% 100% 100%
src/migration.ts 76.07% 86.76% 68.75% 76.07% 149-152, 173-189, 231-237, 296-337, 402-403, 429-431, 439-440, 457-460, 489-490
src/migrationBuilder.ts 96.19% 93.33% 100% 96.19% 833-837, 976-981
src/migrationOptions.ts 100% 100% 100% 100%
src/pgType.ts 100% 100% 100% 100%
src/runner.ts 80.33% 67.79% 100% 80.33% 189, 208-217, 229-230, 282-283, 325-328, 337-341, 354, 366-369, 392, 403, 433-446, 449-452, 472-474, 483, 485-494
src/sqlMigration.ts 85.36% 100% 80% 85.36% 54-60
src/operations/sql.ts 100% 100% 100% 100%
src/operations/casts/createCast.ts 100% 100% 100% 100%
src/operations/casts/dropCast.ts 100% 100% 100% 100%
src/operations/casts/index.ts 100% 100% 100% 100%
src/operations/domains/alterDomain.ts 100% 100% 100% 100%
src/operations/domains/createDomain.ts 100% 100% 100% 100%
src/operations/domains/dropDomain.ts 100% 100% 100% 100%
src/operations/domains/index.ts 100% 100% 100% 100%
src/operations/domains/renameDomain.ts 100% 100% 100% 100%
src/operations/domains/shared.ts 100% 100% 100% 100%
src/operations/extensions/createExtension.ts 100% 100% 100% 100%
src/operations/extensions/dropExtension.ts 100% 100% 100% 100%
src/operations/extensions/index.ts 100% 100% 100% 100%
src/operations/extensions/shared.ts 100% 100% 100% 100%
src/operations/functions/createFunction.ts 95.52% 94.44% 100% 95.52% 71-73
src/operations/functions/dropFunction.ts 100% 100% 100% 100%
src/operations/functions/index.ts 100% 100% 100% 100%
src/operations/functions/renameFunction.ts 100% 100% 100% 100%
src/operations/functions/shared.ts 100% 100% 100% 100%
src/operations/grants/grantOnSchemas.ts 100% 100% 100% 100%
src/operations/grants/grantOnTables.ts 100% 100% 100% 100%
src/operations/grants/grantRoles.ts 100% 100% 100% 100%
src/operations/grants/index.ts 100% 100% 100% 100%
src/operations/grants/revokeOnSchemas.ts 100% 100% 100% 100%
src/operations/grants/revokeOnTables.ts 100% 100% 100% 100%
src/operations/grants/revokeRoles.ts 100% 100% 100% 100%
src/operations/grants/shared.ts 95.45% 85.71% 100% 95.45% 71
src/operations/indexes/createIndex.ts 100% 100% 100% 100%
src/operations/indexes/dropIndex.ts 100% 100% 100% 100%
src/operations/indexes/index.ts 100% 100% 100% 100%
src/operations/indexes/shared.ts 88% 86.95% 100% 88% 23, 33-36, 48
src/operations/materializedViews/alterMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/createMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/dropMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/index.ts 100% 100% 100% 100%
src/operations/materializedViews/refreshMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/renameMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/renameMaterializedViewColumn.ts 100% 100% 100% 100%
src/operations/materializedViews/shared.ts 100% 87.5% 100% 100%
src/operations/operators/addToOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/createOperator.ts 100% 100% 100% 100%
src/operations/operators/createOperatorClass.ts 100% 83.33% 100% 100%
src/operations/operators/createOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/dropOperator.ts 100% 100% 100% 100%
src/operations/operators/dropOperatorClass.ts 100% 100% 100% 100%
src/operations/operators/dropOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/index.ts 100% 100% 100% 100%
src/operations/operators/removeFromOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/renameOperatorClass.ts 100% 100% 100% 100%
src/operations/operators/renameOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/shared.ts 85% 75% 100% 85% 24-25, 38
src/operations/policies/alterPolicy.ts 100% 100% 100% 100%
src/operations/policies/createPolicy.ts 100% 100% 100% 100%
src/operations/policies/dropPolicy.ts 100% 100% 100% 100%
src/operations/policies/index.ts 100% 100% 100% 100%
src/operations/policies/renamePolicy.ts 100% 100% 100% 100%
src/operations/policies/shared.ts 100% 100% 100% 100%
src/operations/roles/alterRole.ts 100% 100% 100% 100%
src/operations/roles/createRole.ts 100% 75% 100% 100%
src/operations/roles/dropRole.ts 100% 100% 100% 100%
src/operations/roles/index.ts 100% 100% 100% 100%
src/operations/roles/renameRole.ts 100% 100% 100% 100%
src/operations/roles/shared.ts 98.07% 76.92% 100% 98.07% 78
src/operations/schemas/createSchema.ts 100% 100% 100% 100%
src/operations/schemas/dropSchema.ts 100% 100% 100% 100%
src/operations/schemas/index.ts 100% 100% 100% 100%
src/operations/schemas/renameSchema.ts 100% 100% 100% 100%
src/operations/sequences/alterSequence.ts 94.73% 80% 100% 94.73% 23
src/operations/sequences/createSequence.ts 100% 100% 100% 100%
src/operations/sequences/dropSequence.ts 100% 100% 100% 100%
src/operations/sequences/index.ts 100% 100% 100% 100%
src/operations/sequences/renameSequence.ts 100% 100% 100% 100%
src/operations/sequences/shared.ts 78.57% 68.75% 100% 78.57% 41, 43-44, 49-50, 63-64, 69-70
src/operations/tables/addColumns.ts 100% 80% 100% 100%
src/operations/tables/addConstraint.ts 100% 100% 100% 100%
src/operations/tables/alterColumn.ts 89.33% 76.47% 100% 89.33% 69, 76-83
src/operations/tables/alterTable.ts 100% 100% 100% 100%
src/operations/tables/createTable.ts 89.39% 77.27% 100% 89.39% 51-55, 92-93
src/operations/tables/dropColumns.ts 100% 100% 100% 100%
src/operations/tables/dropConstraint.ts 100% 100% 100% 100%
src/operations/tables/dropTable.ts 100% 100% 100% 100%
src/operations/tables/index.ts 100% 100% 100% 100%
src/operations/tables/renameColumn.ts 100% 100% 100% 100%
src/operations/tables/renameConstraint.ts 100% 100% 100% 100%
src/operations/tables/renameTable.ts 100% 100% 100% 100%
src/operations/tables/shared.ts 83.15% 81.81% 80% 83.15% 157-158, 211-215, 241-242, 261-262, 287-288, 291-298, 301-302, 439-464
src/operations/triggers/createTrigger.ts 86.25% 68.18% 100% 86.25% 53-54, 66-67, 70-71, 74-77, 113
src/operations/triggers/dropTrigger.ts 100% 100% 100% 100%
src/operations/triggers/index.ts 100% 100% 100% 100%
src/operations/triggers/renameTrigger.ts 100% 100% 100% 100%
src/operations/triggers/shared.ts 100% 100% 100% 100%
src/operations/types/addTypeAttribute.ts 100% 100% 100% 100%
src/operations/types/addTypeValue.ts 100% 100% 100% 100%
src/operations/types/createType.ts 100% 100% 100% 100%
src/operations/types/dropType.ts 100% 100% 100% 100%
src/operations/types/dropTypeAttribute.ts 100% 100% 100% 100%
src/operations/types/index.ts 100% 100% 100% 100%
src/operations/types/renameType.ts 100% 100% 100% 100%
src/operations/types/renameTypeAttribute.ts 100% 100% 100% 100%
src/operations/types/renameTypeValue.ts 100% 100% 100% 100%
src/operations/types/setTypeAttribute.ts 100% 100% 100% 100%
src/operations/views/alterView.ts 100% 100% 100% 100%
src/operations/views/alterViewColumn.ts 100% 100% 100% 100%
src/operations/views/createView.ts 100% 100% 100% 100%
src/operations/views/dropView.ts 100% 100% 100% 100%
src/operations/views/index.ts 100% 100% 100% 100%
src/operations/views/renameView.ts 100% 100% 100% 100%
src/operations/views/shared.ts 100% 66.66% 100% 100%
src/utils/PgLiteral.ts 90.47% 100% 80% 90.47% 44-45
src/utils/createSchemalize.ts 100% 100% 100% 100%
src/utils/createTransformer.ts 100% 100% 100% 100%
src/utils/decamelize.ts 100% 100% 100% 100%
src/utils/escapeValue.ts 100% 100% 100% 100%
src/utils/formatLines.ts 100% 100% 100% 100%
src/utils/formatParams.ts 100% 100% 100% 100%
src/utils/formatPartitionColumns.ts 100% 100% 100% 100%
src/utils/getMigrationTableSchema.ts 100% 100% 100% 100%
src/utils/getSchemas.ts 100% 100% 100% 100%
src/utils/identity.ts 100% 100% 100% 100%
src/utils/index.ts 100% 100% 100% 100%
src/utils/intersection.ts 100% 100% 100% 100%
src/utils/makeComment.ts 100% 100% 100% 100%
src/utils/quote.ts 100% 100% 100% 100%
src/utils/stringIdGenerator.ts 100% 100% 100% 100%
src/utils/toArray.ts 100% 100% 100% 100%
src/utils/types.ts 100% 100% 100% 100%
Generated in workflow #2352 for commit 93638a1 by the Vitest Coverage Report Action

@Shinigami92 Shinigami92 changed the title refactor: add vitest workspaces and TestContainer infra: add vitest workspaces and TestContainer Jul 22, 2025
@Shinigami92

Copy link
Copy Markdown
Collaborator

🤯 I need more time and energy to review a 95 file changes 😆

Is it possible to split the vitest worksoaces and the TestContainer into separate PRs?

However I will try to run GitHub Copilot Review against this PR for now. Maybe it can help already a bit.

@Shinigami92
Shinigami92 requested a review from Copilot July 22, 2025 17:43

This comment was marked as outdated.

@Shinigami92

Copy link
Copy Markdown
Collaborator

@brenoepics looks like Copilot has the same energy as I have right now 🤣

@brenoepics

Copy link
Copy Markdown
Collaborator Author

🤯 I need more time and energy to review a 95 file changes 😆

Is it possible to split the vitest worksoaces and the TestContainer into separate PRs?

However I will try to run GitHub Copilot Review against this PR for now. Maybe it can help already a bit.

No worries and yeah, I can separate it, most of the changes are log snapshots since they were all local before so I generated snapshots for pg 13, 14, 15, 16, 17

Comment thread test/integration/utils.ts
Comment thread test/integration/utils.ts Outdated
Comment thread test/integration/postgres-it.spec.ts Outdated
@Shinigami92

Copy link
Copy Markdown
Collaborator

... @brenoepics I'm a bit sorry to ask for that..., but could you for now just move the name: 'Postgres Test: pg-${{ matrix.postgres_version }}, node-${{ matrix.node_version }}, ubuntu-latest' into containered tests?
So the other stuff like config-1, config-2, dotenv-expand and so on should stay as is for now.

One of the things is also that the Postgres Test: pg-x, ... run for different nodejs versions, I think we lost that now, due to the integration workspace only runs with the node on your localhost

@brenoepics

Copy link
Copy Markdown
Collaborator Author

... @brenoepics I'm a bit sorry to ask for that..., but could you for now just move the name: 'Postgres Test: pg-${{ matrix.postgres_version }}, node-${{ matrix.node_version }}, ubuntu-latest' into containered tests? So the other stuff like config-1, config-2, dotenv-expand and so on should stay as is for now.

Yeah, I agree that way would be better, those real config tests stay via actions and non config related integration tests go to containers so we can run locally.

One of the things is also that the Postgres Test: pg-x, ... run for different nodejs versions, I think we lost that now, due to the integration workspace only runs with the node on your localhost

I think it still works, since I kept the node-version matrix (but removed pg version one)

@Shinigami92

Copy link
Copy Markdown
Collaborator

I think it still works, since I kept the node-version matrix (but removed pg version one)

Oh, I see, because the tests just moved from Postgres Test to the ci.yml -> integration-test 👍

@Shinigami92

Copy link
Copy Markdown
Collaborator

@brenoepics please delete the snapshots and regenerate them. That will delete a lot of stale snapshot files and make the file changes finally smaller.

@Shinigami92

Copy link
Copy Markdown
Collaborator

@brenoepics updated the PR with my preferences

you got me wrong about the snapshot files 🥲
we should have snapshot files for the positive successful stdout logs, so we can detect if something suddenly got changed.
but we only need one combined for stderr (as you correctly did now 👍)

so please bring back the snapshot check for the successful stdout with the related pg-version
the can be stored in

  • test/integration/__snapshots__/db-config-it.spec.ts.snap.d/migrations-up.pg-17.stdout.log
  • test/integration/__snapshots__/db-config-it.spec.ts.snap.d/migrations-down.pg-17.stdout.log
    (and then also 13-17)

accordingly we can store the error logs in

  • test/integration/__snapshots__/db-config-it.spec.ts.snap.d/migrations-up.stderr.log
  • test/integration/__snapshots__/db-config-it.spec.ts.snap.d/migrations-down.stderr.log

@brenoepics

Copy link
Copy Markdown
Collaborator Author

I think migrations-down.pg-xx.stdout.log will always match the result

@Shinigami92

Copy link
Copy Markdown
Collaborator

I think migrations-down.pg-xx.stdout.log will always match the result

except for pg-17 -> #1478 (comment)

@brenoepics

Copy link
Copy Markdown
Collaborator Author

down always matches since the create table etc. shouldn't make noise at err (if any version does, there is likely something wrong?) but up will be different yeah

@Shinigami92

Copy link
Copy Markdown
Collaborator

down always matches since the create table etc. shouldn't make noise at err (if any version does, there is likely something wrong?) but up will be different yeah

😮 you talked about down
I did not got that, sorry 🙏
you are absolutely right 🚀

Shinigami92
Shinigami92 previously approved these changes Jul 26, 2025
@Shinigami92
Shinigami92 requested a review from Copilot July 26, 2025 17:56

This comment was marked as outdated.

@Shinigami92
Shinigami92 requested a review from Copilot July 26, 2025 18:01

This comment was marked as outdated.

@Shinigami92
Shinigami92 requested a review from Copilot July 26, 2025 18:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 introduces Vitest workspaces and TestContainer setup for improved integration testing infrastructure. It replaces the existing GitHub Actions PostgreSQL service-based testing with a containerized approach that supports testing against multiple PostgreSQL versions locally and in CI.

  • Migrates from spawnSync-based integration tests to TestContainer-powered tests using real PostgreSQL instances
  • Adds comprehensive database cleanup utilities for test isolation
  • Implements configurable PostgreSQL version testing through environment variables

Reviewed Changes

Copilot reviewed 6 out of 20 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/integration/utils.ts New utility module providing TestContainer setup, database cleanup, and test configuration helpers
test/integration/db-config-it.spec.ts Replaces db-config.spec.ts with TestContainer-based integration tests that run against multiple PostgreSQL versions
test/integration/db-config.spec.ts Removed old spawnSync-based integration test file
package.json Added @testcontainers/postgresql and testcontainers dependencies for containerized testing
.github/workflows/postgres-test.yml Removed old PostgreSQL service-based test job in favor of TestContainer approach
.github/workflows/ci.yml Added PGM_VERSIONS environment variable to configure PostgreSQL versions for CI testing
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Comment thread test/integration/utils.ts
Comment thread test/integration/utils.ts
Comment thread test/integration/db-config-it.spec.ts
Comment thread test/integration/db-config-it.spec.ts
Comment thread test/integration/db-config-it.spec.ts
@Shinigami92
Shinigami92 added this pull request to the merge queue Jul 26, 2025
Merged via the queue into salsita:main with commit 6ff8669 Jul 26, 2025
28 checks passed
@brenoepics
brenoepics deleted the refactor-tests branch July 26, 2025 18:30
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.

3 participants