Skip to content

Commit b433821

Browse files
authored
test(node): Run Prisma docker containers via test runner (#15402)
Migrates the prisma tests to use the `withDockerCompose` option on the test runner. This means: - Docker is only required if you're running tests that actually use docker - Containers are automatically cleaned up after tests complete
1 parent bfe7bfa commit b433821

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

dev-packages/node-integration-tests/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
"build:types": "tsc -p tsconfig.types.json",
1717
"clean": "rimraf -g **/node_modules && run-p clean:script",
1818
"clean:script": "node scripts/clean.js",
19-
"prisma-v5:init": "cd suites/tracing/prisma-orm-v5 && yarn && yarn setup",
20-
"prisma-v6:init": "cd suites/tracing/prisma-orm-v6 && yarn && yarn setup",
2119
"lint": "eslint . --format stylish",
2220
"fix": "eslint . --format stylish --fix",
2321
"type-check": "tsc",
24-
"pretest": "run-s --silent prisma-v5:init prisma-v6:init",
2522
"test": "jest --config ./jest.config.js",
2623
"test:watch": "yarn test --watch"
2724
},

dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
"node": ">=18"
88
},
99
"scripts": {
10-
"db-up": "docker compose up -d",
1110
"generate": "prisma generate",
1211
"migrate": "prisma migrate dev -n sentry-test",
13-
"setup": "run-s --silent db-up generate migrate"
12+
"setup": "run-s --silent generate migrate"
1413
},
1514
"keywords": [],
1615
"author": "",

dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
import { createRunner } from '../../../utils/runner';
1+
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
22

3-
describe('Prisma ORM Tests', () => {
3+
afterAll(() => {
4+
cleanupChildProcesses();
5+
});
6+
7+
describe('Prisma ORM v5 Tests', () => {
48
test('CJS - should instrument PostgreSQL queries from Prisma ORM', done => {
59
createRunner(__dirname, 'scenario.js')
10+
.withDockerCompose({
11+
workingDirectory: [__dirname],
12+
readyMatches: ['port 5432'],
13+
setupCommand: 'yarn && yarn setup',
14+
})
615
.expect({
716
transaction: transaction => {
817
expect(transaction.transaction).toBe('Test Transaction');

dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
"node": ">=18"
88
},
99
"scripts": {
10-
"db-up": "docker compose up -d",
1110
"generate": "prisma generate",
1211
"migrate": "prisma migrate dev -n sentry-test",
13-
"setup": "run-s --silent db-up generate migrate"
12+
"setup": "run-s --silent generate migrate"
1413
},
1514
"keywords": [],
1615
"author": "",

dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/test.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import type { SpanJSON } from '@sentry/core';
2-
import { createRunner } from '../../../utils/runner';
2+
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
33

4-
describe('Prisma ORM Tests', () => {
4+
afterAll(() => {
5+
cleanupChildProcesses();
6+
});
7+
8+
describe('Prisma ORM v6 Tests', () => {
59
test('CJS - should instrument PostgreSQL queries from Prisma ORM', done => {
610
createRunner(__dirname, 'scenario.js')
11+
.withDockerCompose({
12+
workingDirectory: [__dirname],
13+
readyMatches: ['port 5432'],
14+
setupCommand: 'yarn && yarn setup',
15+
})
716
.expect({
817
transaction: transaction => {
918
expect(transaction.transaction).toBe('Test Transaction');

dev-packages/node-integration-tests/utils/runner.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-lines */
2-
import { spawn, spawnSync } from 'child_process';
2+
import { execSync, spawn, spawnSync } from 'child_process';
33
import { existsSync } from 'fs';
44
import { join } from 'path';
55
import { normalize } from '@sentry/core';
@@ -60,6 +60,10 @@ interface DockerOptions {
6060
* The strings to look for in the output to know that the docker compose is ready for the test to be run
6161
*/
6262
readyMatches: string[];
63+
/**
64+
* The command to run after docker compose is up
65+
*/
66+
setupCommand?: string;
6367
}
6468

6569
/**
@@ -96,6 +100,9 @@ async function runDockerCompose(options: DockerOptions): Promise<VoidFunction> {
96100
if (text.includes(match)) {
97101
child.stdout.removeAllListeners();
98102
clearTimeout(timeout);
103+
if (options.setupCommand) {
104+
execSync(options.setupCommand, { cwd, stdio: 'inherit' });
105+
}
99106
resolve(close);
100107
}
101108
}

0 commit comments

Comments
 (0)