{"_id":"@021.is/spine-testing","_rev":"2-5858c5ebbb6c5010c9b9af705472fdb5","name":"@021.is/spine-testing","dist-tags":{"latest":"0.4.3"},"versions":{"0.4.0":{"name":"@021.is/spine-testing","version":"0.4.0","license":"MIT","_id":"@021.is/spine-testing@0.4.0","maintainers":[{"name":"edvone","email":"edvard@edvone.dev"}],"homepage":"https://github.com/021is/spine-ts#readme","bugs":{"url":"https://github.com/021is/spine-ts/issues"},"dist":{"shasum":"705a9dfe48aa063b708401b47c65b821fa194a03","tarball":"https://registry.npmjs.org/@021.is/spine-testing/-/spine-testing-0.4.0.tgz","fileCount":18,"integrity":"sha512-Prf9SqrsPZVav9Ne+TvfqXV4B7dtFWFR9jFKIVbQ/eSKvWOL6QJTmUgOmGo7vfxaIbbhRwKSoajR8gWMXaocCg==","signatures":[{"sig":"MEUCIH5dbVOZbE05WvCKqAw3tONDe9ofCFRx/0rPZ4eAhREqAiEAlqVQGNlYPo18daZxJca/J/aMcNnVsYH9E+NUQXHQkE0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":611678},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./msw":{"types":"./dist/msw.d.ts","import":"./dist/msw.js"},"./jwks":{"types":"./dist/jwks.d.ts","import":"./dist/jwks.js"},"./time":{"types":"./dist/time.d.ts","import":"./dist/time.js"},"./postgres":{"types":"./dist/postgres.d.ts","import":"./dist/postgres.js"}},"gitHead":"e4434c6f59db8f586e0f05ffdb3b88a96e68e67b","scripts":{"build":"tsup src/index.ts src/postgres.ts src/jwks.ts src/msw.ts src/time.ts --format esm --dts --clean","typecheck":"tsc --noEmit"},"_npmUser":{"name":"edvone","email":"edvard@edvone.dev"},"repository":{"url":"git+https://github.com/021is/spine-ts.git","type":"git","directory":"packages/testing"},"_npmVersion":"10.9.4","description":"Shared test helpers: Testcontainers Postgres (worker-shared), Prisma migrator, JWKS mock server, MSW factory, deterministic time + uuid.","directories":{},"_nodeVersion":"22.22.0","dependencies":{"pg":"^8.21.0","msw":"^2.4.11","jose":"^5.9.6","@types/pg":"^8.20.0","testcontainers":"^10.13.2","@testcontainers/postgresql":"^10.13.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/spine-testing_0.4.0_1779981976017_0.9999956442956397","host":"s3://npm-registry-packages-npm-production"}},"0.4.3":{"name":"@021.is/spine-testing","version":"0.4.3","license":"MIT","description":"Shared test helpers: Testcontainers Postgres (worker-shared), Prisma migrator, JWKS mock server, MSW factory, deterministic time + uuid.","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./postgres":{"types":"./dist/postgres.d.ts","import":"./dist/postgres.js"},"./jwks":{"types":"./dist/jwks.d.ts","import":"./dist/jwks.js"},"./msw":{"types":"./dist/msw.d.ts","import":"./dist/msw.js"},"./time":{"types":"./dist/time.d.ts","import":"./dist/time.js"}},"scripts":{"build":"tsup src/index.ts src/postgres.ts src/jwks.ts src/msw.ts src/time.ts --format esm --dts --clean","typecheck":"tsc --noEmit"},"dependencies":{"@testcontainers/postgresql":"^10.13.2","@types/pg":"^8.20.0","jose":"^5.9.6","msw":"^2.4.11","pg":"^8.21.0","testcontainers":"^10.13.2"},"repository":{"type":"git","url":"git+https://github.com/021is/spine-ts.git","directory":"packages/testing"},"publishConfig":{"access":"public"},"_id":"@021.is/spine-testing@0.4.3","gitHead":"b9f9333776fa55686cc2feb05f851aa6000b0e05","bugs":{"url":"https://github.com/021is/spine-ts/issues"},"homepage":"https://github.com/021is/spine-ts#readme","_nodeVersion":"22.22.0","_npmVersion":"10.9.4","dist":{"integrity":"sha512-KyxtpIq65LtkgcK3V5CS55LqMwBjlwUCgp10gULiPUDKNcuxelEIPSJokoJ+Pi/YeEg2jccCpJ95YrqRozX3BQ==","shasum":"c1ffcecab46b75b26c2dcd0e3e24074a8e1713a2","tarball":"https://registry.npmjs.org/@021.is/spine-testing/-/spine-testing-0.4.3.tgz","fileCount":19,"unpackedSize":613769,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIEVqqEsSIK/slkQ3gbiC8hpB1zqGdq1+ye6PpvN89huiAiEAj8V8chAnj8ifSM3sIOj37PMlCqSpYYi4/jPwj82eh48="}]},"_npmUser":{"name":"edvone","email":"edvard@edvone.dev"},"directories":{},"maintainers":[{"name":"edvone","email":"edvard@edvone.dev"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/spine-testing_0.4.3_1779995260428_0.03812989434689795"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-28T15:26:15.860Z","modified":"2026-05-28T19:07:40.678Z","0.4.0":"2026-05-28T15:26:16.161Z","0.4.3":"2026-05-28T19:07:40.568Z"},"bugs":{"url":"https://github.com/021is/spine-ts/issues"},"license":"MIT","homepage":"https://github.com/021is/spine-ts#readme","repository":{"type":"git","url":"git+https://github.com/021is/spine-ts.git","directory":"packages/testing"},"description":"Shared test helpers: Testcontainers Postgres (worker-shared), Prisma migrator, JWKS mock server, MSW factory, deterministic time + uuid.","maintainers":[{"name":"edvone","email":"edvard@edvone.dev"}],"readme":"# @021.is/spine-testing\n\nShared test helpers used by every product. Lets every repo's `tests/setup.ts` look the same.\n\n## What's in the box\n\n| Subpath | Purpose |\n|---|---|\n| `@021.is/spine-testing/postgres` | `startSharedPostgres()` — Testcontainers PG per Vitest worker. `runPrismaMigrate()` — apply your schema once. `truncateAll()` — clean between tests without restart. |\n| `@021.is/spine-testing/jwks` | `startJwksMockServer()` — in-process RS256 JWKS endpoint + `signToken()`. Point your auth middleware at it; no real IdP needed. |\n| `@021.is/spine-testing/msw` | `startMockServer()` — MSW for outbound HTTP. Mock Resend / Stripe / R2 / Google. |\n| `@021.is/spine-testing/time` | `freezeTime()` + `deterministicIds()` — stable timestamps + ids for snapshot + rate-limit tests. |\n\n## Reference setup\n\n```ts\n// tests/setup.ts\nimport { beforeAll, afterAll, afterEach } from \"vitest\";\nimport { startSharedPostgres, runPrismaMigrate, truncateAll } from \"@021.is/spine-testing/postgres\";\nimport { startMockServer } from \"@021.is/spine-testing/msw\";\n\nlet dbUrl: string;\nconst mocks = startMockServer();\n\nbeforeAll(async () => {\n  dbUrl = await startSharedPostgres();\n  process.env.DATABASE_URL = dbUrl;\n  await runPrismaMigrate(dbUrl, { mode: \"push\" }); // fast for tests\n}, 60_000);\n\nafterEach(async () => {\n  await truncateAll(dbUrl);\n  mocks.reset();\n});\n\nafterAll(() => {\n  mocks.stop();\n  // Postgres container is reaped by Testcontainers on process exit.\n});\n```\n\n## Why Testcontainers > mocks\n\nThe rule: \"mocks lie when production diverges.\" A real Postgres runs your real migrations, executes your real SQL, surfaces real index bugs. The cost (~1.5s per worker cold start) is amortized over the whole suite.\n\n## Performance notes\n\n- **Shared container per worker.** `startSharedPostgres()` uses a globalThis slot — one container per Vitest worker process, not per test file.\n- **Migrate once, truncate often.** `runPrismaMigrate()` in `beforeAll`; `truncateAll()` in `afterEach`. ~50ms per test after the first.\n- **`mode: \"push\"` for tests.** Skip the migration table and just `db push` from `schema.prisma`. Much faster than `deploy` when you don't need migration history fidelity.\n- **CI: shard your tests.** `vitest run --shard=1/4` × 4 GH Actions matrix jobs = 4× wall clock.\n","readmeFilename":"README.md"}