diff --git a/packages/app/src/__tests__/app.test.ts b/packages/app/src/__tests__/app.test.ts index ac88200..a29139b 100644 --- a/packages/app/src/__tests__/app.test.ts +++ b/packages/app/src/__tests__/app.test.ts @@ -3,6 +3,9 @@ import supertest from 'supertest'; import { describe, expect, it } from 'vitest'; import { createApp, AppServer } from '../index'; +const from = 15000; +const range = 100; +const port = from + ~~(Math.random() * range); describe('app', async () => { const rpc: AppServer = createApp({ @@ -88,7 +91,7 @@ describe('app', async () => { const request = supertest(rpc.callback()); it('should start === rpc.callback', async () => { - const request2 = supertest(rpc.start(30001)); + const request2 = supertest(rpc.start(port)); const res = await request2.get('/api/a?$p=["hello"]'); expect(res.type).toEqual('application/json'); expect(res.status).toEqual(200); diff --git a/packages/client/src/__tests__/index.test.ts b/packages/client/src/__tests__/index.test.ts index 7fcd8a6..3df4a41 100644 --- a/packages/client/src/__tests__/index.test.ts +++ b/packages/client/src/__tests__/index.test.ts @@ -4,6 +4,10 @@ import { describe, expect, it } from 'vitest'; import { createClient } from '..'; +const from = 15000; +const range = 100; +const port = from + ~~(Math.random() * range); + describe('lib', () => { const rpc = createServer({ fn: { @@ -42,11 +46,11 @@ describe('lib', () => { }); it('should GET return json', async () => { - rpc.start(30001); + rpc.start(port); const client = createClient({ host: '127.0.0.1', - port: 30001, + port: port, }); // console.dir(client); @@ -55,7 +59,7 @@ describe('lib', () => { expect(res1['a']).toBe('hello'); - const res = await fetch('http://127.0.0.1:30001/api/a?$p=["hello"]'); + const res = await fetch(`http://127.0.0.1:${port}/api/a?$p=["hello"]`); const s = await res.json(); // console.dir(s); expect(s['a']).toBe('hello'); diff --git a/packages/core/src/__tests__/app.test.ts b/packages/core/src/__tests__/app.test.ts index 0e378e2..d65579c 100644 --- a/packages/core/src/__tests__/app.test.ts +++ b/packages/core/src/__tests__/app.test.ts @@ -3,6 +3,10 @@ import { describe, expect, it } from 'vitest'; import { createServer } from '../index'; +const from = 15000; +const range = 100; +const port = from + ~~(Math.random() * range); + describe('app', async () => { const rpc = createServer({ fn: { @@ -40,7 +44,7 @@ describe('app', async () => { const request = supertest(rpc.callback()); it('should start === rpc.callback', async () => { - const request2 = supertest(rpc.start(30001)); + const request2 = supertest(rpc.start(port)); const res = await request2.get('/api/a?$p=["hello"]'); expect(res.type).toEqual('application/json'); expect(res.status).toEqual(200);