Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(node): Run Prisma docker containers via test runner #15402

Merged
merged 3 commits into from
Feb 13, 2025
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
3 changes: 0 additions & 3 deletions dev-packages/node-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { createRunner } from '../../../utils/runner';
import { cleanupChildProcesses, createRunner } 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 && yarn setup',
})
.expect({
transaction: transaction => {
expect(transaction.transaction).toBe('Test Transaction');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -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 && yarn setup',
})
.expect({
transaction: transaction => {
expect(transaction.transaction).toBe('Test Transaction');
Expand Down
9 changes: 8 additions & 1 deletion dev-packages/node-integration-tests/utils/runner.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -96,6 +100,9 @@ async function runDockerCompose(options: DockerOptions): Promise<VoidFunction> {
if (text.includes(match)) {
child.stdout.removeAllListeners();
clearTimeout(timeout);
if (options.setupCommand) {
execSync(options.setupCommand, { cwd, stdio: 'inherit' });
}
resolve(close);
}
}
Expand Down
Loading