File tree Expand file tree Collapse file tree 3 files changed +22
-15
lines changed
dev-packages/node-integration-tests/suites/tracing Expand file tree Collapse file tree 3 files changed +22
-15
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,6 @@ import Anthropic from '@anthropic-ai/sdk';
22import * as Sentry from '@sentry/node' ;
33import express from 'express' ;
44
5- const PORT = 3333 ;
6-
75function startMockAnthropicServer ( ) {
86 const app = express ( ) ;
97 app . use ( express . json ( ) ) ;
@@ -50,16 +48,21 @@ function startMockAnthropicServer() {
5048 } ,
5149 } ) ;
5250 } ) ;
53- return app . listen ( PORT ) ;
51+
52+ return new Promise ( resolve => {
53+ const server = app . listen ( 0 , ( ) => {
54+ resolve ( server ) ;
55+ } ) ;
56+ } ) ;
5457}
5558
5659async function run ( ) {
57- const server = startMockAnthropicServer ( ) ;
60+ const server = await startMockAnthropicServer ( ) ;
5861
5962 await Sentry . startSpan ( { op : 'function' , name : 'main' } , async ( ) => {
6063 const client = new Anthropic ( {
6164 apiKey : 'mock-api-key' ,
62- baseURL : `http://localhost:${ PORT } /anthropic` ,
65+ baseURL : `http://localhost:${ server . address ( ) . port } /anthropic` ,
6366 } ) ;
6467
6568 // First test: basic message completion
Original file line number Diff line number Diff line change @@ -2,8 +2,6 @@ import { GoogleGenAI } from '@google/genai';
22import * as Sentry from '@sentry/node' ;
33import express from 'express' ;
44
5- const PORT = 3333 ;
6-
75function startMockGoogleGenAIServer ( ) {
86 const app = express ( ) ;
97 app . use ( express . json ( ) ) ;
@@ -39,16 +37,20 @@ function startMockGoogleGenAIServer() {
3937 } ) ;
4038 } ) ;
4139
42- return app . listen ( PORT ) ;
40+ return new Promise ( resolve => {
41+ const server = app . listen ( 0 , ( ) => {
42+ resolve ( server ) ;
43+ } ) ;
44+ } ) ;
4345}
4446
4547async function run ( ) {
46- const server = startMockGoogleGenAIServer ( ) ;
48+ const server = await startMockGoogleGenAIServer ( ) ;
4749
4850 await Sentry . startSpan ( { op : 'function' , name : 'main' } , async ( ) => {
4951 const client = new GoogleGenAI ( {
5052 apiKey : 'mock-api-key' ,
51- httpOptions : { baseUrl : `http://localhost:${ PORT } ` } ,
53+ httpOptions : { baseUrl : `http://localhost:${ server . address ( ) . port } ` } ,
5254 } ) ;
5355
5456 // Test 1: chats.create and sendMessage flow
Original file line number Diff line number Diff line change 11import express from 'express' ;
22import OpenAI from 'openai' ;
33
4- const PORT = 3333 ;
5-
64function startMockOpenAiServer ( ) {
75 const app = express ( ) ;
86 app . use ( express . json ( ) ) ;
@@ -31,14 +29,18 @@ function startMockOpenAiServer() {
3129 } ,
3230 } ) ;
3331 } ) ;
34- return app . listen ( PORT ) ;
32+ return new Promise ( resolve => {
33+ const server = app . listen ( 0 , ( ) => {
34+ resolve ( server ) ;
35+ } ) ;
36+ } ) ;
3537}
3638
3739async function run ( ) {
38- const server = startMockOpenAiServer ( ) ;
40+ const server = await startMockOpenAiServer ( ) ;
3941
4042 const client = new OpenAI ( {
41- baseURL : `http://localhost:${ PORT } /openai` ,
43+ baseURL : `http://localhost:${ server . address ( ) . port } /openai` ,
4244 apiKey : 'mock-api-key' ,
4345 } ) ;
4446
You can’t perform that action at this time.
0 commit comments