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';
2
2
import * as Sentry from '@sentry/node' ;
3
3
import express from 'express' ;
4
4
5
- const PORT = 3333 ;
6
-
7
5
function startMockAnthropicServer ( ) {
8
6
const app = express ( ) ;
9
7
app . use ( express . json ( ) ) ;
@@ -50,16 +48,21 @@ function startMockAnthropicServer() {
50
48
} ,
51
49
} ) ;
52
50
} ) ;
53
- return app . listen ( PORT ) ;
51
+
52
+ return new Promise ( resolve => {
53
+ const server = app . listen ( 0 , ( ) => {
54
+ resolve ( server ) ;
55
+ } ) ;
56
+ } ) ;
54
57
}
55
58
56
59
async function run ( ) {
57
- const server = startMockAnthropicServer ( ) ;
60
+ const server = await startMockAnthropicServer ( ) ;
58
61
59
62
await Sentry . startSpan ( { op : 'function' , name : 'main' } , async ( ) => {
60
63
const client = new Anthropic ( {
61
64
apiKey : 'mock-api-key' ,
62
- baseURL : `http://localhost:${ PORT } /anthropic` ,
65
+ baseURL : `http://localhost:${ server . address ( ) . port } /anthropic` ,
63
66
} ) ;
64
67
65
68
// First test: basic message completion
Original file line number Diff line number Diff line change @@ -2,8 +2,6 @@ import { GoogleGenAI } from '@google/genai';
2
2
import * as Sentry from '@sentry/node' ;
3
3
import express from 'express' ;
4
4
5
- const PORT = 3333 ;
6
-
7
5
function startMockGoogleGenAIServer ( ) {
8
6
const app = express ( ) ;
9
7
app . use ( express . json ( ) ) ;
@@ -39,16 +37,20 @@ function startMockGoogleGenAIServer() {
39
37
} ) ;
40
38
} ) ;
41
39
42
- return app . listen ( PORT ) ;
40
+ return new Promise ( resolve => {
41
+ const server = app . listen ( 0 , ( ) => {
42
+ resolve ( server ) ;
43
+ } ) ;
44
+ } ) ;
43
45
}
44
46
45
47
async function run ( ) {
46
- const server = startMockGoogleGenAIServer ( ) ;
48
+ const server = await startMockGoogleGenAIServer ( ) ;
47
49
48
50
await Sentry . startSpan ( { op : 'function' , name : 'main' } , async ( ) => {
49
51
const client = new GoogleGenAI ( {
50
52
apiKey : 'mock-api-key' ,
51
- httpOptions : { baseUrl : `http://localhost:${ PORT } ` } ,
53
+ httpOptions : { baseUrl : `http://localhost:${ server . address ( ) . port } ` } ,
52
54
} ) ;
53
55
54
56
// Test 1: chats.create and sendMessage flow
Original file line number Diff line number Diff line change 1
1
import express from 'express' ;
2
2
import OpenAI from 'openai' ;
3
3
4
- const PORT = 3333 ;
5
-
6
4
function startMockOpenAiServer ( ) {
7
5
const app = express ( ) ;
8
6
app . use ( express . json ( ) ) ;
@@ -31,14 +29,18 @@ function startMockOpenAiServer() {
31
29
} ,
32
30
} ) ;
33
31
} ) ;
34
- return app . listen ( PORT ) ;
32
+ return new Promise ( resolve => {
33
+ const server = app . listen ( 0 , ( ) => {
34
+ resolve ( server ) ;
35
+ } ) ;
36
+ } ) ;
35
37
}
36
38
37
39
async function run ( ) {
38
- const server = startMockOpenAiServer ( ) ;
40
+ const server = await startMockOpenAiServer ( ) ;
39
41
40
42
const client = new OpenAI ( {
41
- baseURL : `http://localhost:${ PORT } /openai` ,
43
+ baseURL : `http://localhost:${ server . address ( ) . port } /openai` ,
42
44
apiKey : 'mock-api-key' ,
43
45
} ) ;
44
46
You can’t perform that action at this time.
0 commit comments