From 44a11f1c6749d6de5aa2c2579ba6f57c9602faf8 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 13 Feb 2025 13:52:38 +0100 Subject: [PATCH 1/3] test(node): Run Prisma docker containers via test runner --- dev-packages/node-integration-tests/package.json | 3 --- .../suites/tracing/prisma-orm-v5/package.json | 3 +-- .../suites/tracing/prisma-orm-v5/test.ts | 13 +++++++++++-- .../suites/tracing/prisma-orm-v6/package.json | 3 +-- .../suites/tracing/prisma-orm-v6/test.ts | 13 +++++++++++-- dev-packages/node-integration-tests/utils/runner.ts | 9 ++++++++- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/dev-packages/node-integration-tests/package.json b/dev-packages/node-integration-tests/package.json index c98722e16a0b..01deaadcc7de 100644 --- a/dev-packages/node-integration-tests/package.json +++ b/dev-packages/node-integration-tests/package.json @@ -16,12 +16,9 @@ "build:types": "tsc -p tsconfig.types.json", "clean": "rimraf -g **/node_modules && run-p clean:script", "clean:script": "node scripts/clean.js", - "prisma-v5:init": "cd suites/tracing/prisma-orm-v5 && yarn && yarn setup", - "prisma-v6:init": "cd suites/tracing/prisma-orm-v6 && yarn && yarn setup", "lint": "eslint . --format stylish", "fix": "eslint . --format stylish --fix", "type-check": "tsc", - "pretest": "run-s --silent prisma-v5:init prisma-v6:init", "test": "jest --config ./jest.config.js", "test:watch": "yarn test --watch" }, diff --git a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/package.json b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/package.json index b8721038c83b..d3dcaf9d1328 100644 --- a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/package.json +++ b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/package.json @@ -7,10 +7,9 @@ "node": ">=18" }, "scripts": { - "db-up": "docker compose up -d", "generate": "prisma generate", "migrate": "prisma migrate dev -n sentry-test", - "setup": "run-s --silent db-up generate migrate" + "setup": "run-s --silent generate migrate" }, "keywords": [], "author": "", diff --git a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts index 0ece02f2f1cb..4292e37b0671 100644 --- a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts @@ -1,8 +1,17 @@ -import { createRunner } from '../../../utils/runner'; +import { createRunner, cleanupChildProcesses } from '../../../utils/runner'; -describe('Prisma ORM Tests', () => { +afterAll(() => { + cleanupChildProcesses(); +}); + +describe('Prisma ORM v5 Tests', () => { test('CJS - should instrument PostgreSQL queries from Prisma ORM', done => { createRunner(__dirname, 'scenario.js') + .withDockerCompose({ + workingDirectory: [__dirname], + readyMatches: ['port 5432'], + setupCommand: 'yarn setup', + }) .expect({ transaction: transaction => { expect(transaction.transaction).toBe('Test Transaction'); diff --git a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/package.json b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/package.json index a0b24c52e319..dc062f1b9e3b 100644 --- a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/package.json +++ b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/package.json @@ -7,10 +7,9 @@ "node": ">=18" }, "scripts": { - "db-up": "docker compose up -d", "generate": "prisma generate", "migrate": "prisma migrate dev -n sentry-test", - "setup": "run-s --silent db-up generate migrate" + "setup": "run-s --silent generate migrate" }, "keywords": [], "author": "", diff --git a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/test.ts b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/test.ts index 70d2fda9cbe0..26f76e7d0292 100644 --- a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/test.ts @@ -1,9 +1,18 @@ import type { SpanJSON } from '@sentry/core'; -import { createRunner } from '../../../utils/runner'; +import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; -describe('Prisma ORM Tests', () => { +afterAll(() => { + cleanupChildProcesses(); +}); + +describe('Prisma ORM v6 Tests', () => { test('CJS - should instrument PostgreSQL queries from Prisma ORM', done => { createRunner(__dirname, 'scenario.js') + .withDockerCompose({ + workingDirectory: [__dirname], + readyMatches: ['port 5432'], + setupCommand: 'yarn setup', + }) .expect({ transaction: transaction => { expect(transaction.transaction).toBe('Test Transaction'); diff --git a/dev-packages/node-integration-tests/utils/runner.ts b/dev-packages/node-integration-tests/utils/runner.ts index a5fc8df38825..152160f7118b 100644 --- a/dev-packages/node-integration-tests/utils/runner.ts +++ b/dev-packages/node-integration-tests/utils/runner.ts @@ -1,5 +1,5 @@ /* eslint-disable max-lines */ -import { spawn, spawnSync } from 'child_process'; +import { execSync, spawn, spawnSync } from 'child_process'; import { existsSync } from 'fs'; import { join } from 'path'; import { normalize } from '@sentry/core'; @@ -60,6 +60,10 @@ interface DockerOptions { * The strings to look for in the output to know that the docker compose is ready for the test to be run */ readyMatches: string[]; + /** + * The command to run after docker compose is up + */ + setupCommand?: string; } /** @@ -96,6 +100,9 @@ async function runDockerCompose(options: DockerOptions): Promise { if (text.includes(match)) { child.stdout.removeAllListeners(); clearTimeout(timeout); + if (options.setupCommand) { + execSync(options.setupCommand, { cwd, stdio: 'inherit' }); + } resolve(close); } } From 49a23984f20e9f2bfb1103f8666ae45a7fd9efbd Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 13 Feb 2025 13:58:48 +0100 Subject: [PATCH 2/3] Lint --- .../node-integration-tests/suites/tracing/prisma-orm-v5/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts index 4292e37b0671..4795fa64fb4c 100644 --- a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts @@ -1,4 +1,4 @@ -import { createRunner, cleanupChildProcesses } from '../../../utils/runner'; +import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; afterAll(() => { cleanupChildProcesses(); From c91ec1c2da912a6ce2cc5994b188c65421a3d31b Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 13 Feb 2025 14:17:46 +0100 Subject: [PATCH 3/3] Also install --- .../node-integration-tests/suites/tracing/prisma-orm-v5/test.ts | 2 +- .../node-integration-tests/suites/tracing/prisma-orm-v6/test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts index 4795fa64fb4c..6f51fe329bbc 100644 --- a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts @@ -10,7 +10,7 @@ describe('Prisma ORM v5 Tests', () => { .withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['port 5432'], - setupCommand: 'yarn setup', + setupCommand: 'yarn && yarn setup', }) .expect({ transaction: transaction => { diff --git a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/test.ts b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/test.ts index 26f76e7d0292..34214858d8ff 100644 --- a/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/test.ts @@ -11,7 +11,7 @@ describe('Prisma ORM v6 Tests', () => { .withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['port 5432'], - setupCommand: 'yarn setup', + setupCommand: 'yarn && yarn setup', }) .expect({ transaction: transaction => {