diff --git a/packages/grpc/test/index.test.ts b/packages/grpc/test/index.test.ts index 9cbfcc9bd02..e4862a5165a 100644 --- a/packages/grpc/test/index.test.ts +++ b/packages/grpc/test/index.test.ts @@ -9,8 +9,8 @@ import { IClientOptions } from '../src'; -import { Metadata } from '@grpc/grpc-js'; -import { hello } from './fixtures/base-app-multiple-package/src/interface'; +// import { Metadata } from '@grpc/grpc-js'; +// import { hello } from './fixtures/base-app-multiple-package/src/interface'; export namespace hero { export interface HeroServiceClient { @@ -84,77 +84,77 @@ describe('/test/index.test.ts', function () { await closeApp(app); }); - it('should create gRPC server', async () => { - const app = await createServer('base-app'); - - const service = await createGRPCConsumer({ - package: 'helloworld', - protoPath: join(__dirname, 'fixtures/proto/helloworld.proto'), - url: 'localhost:6565' - }); - - const meta = new Metadata(); - meta.add('key', 'value'); - - const result = await service.sayHello({ - metadata: meta, - }).sendMessage({ - name: 'harry' - }); - - expect(result).toEqual({ message: 'Hello harry' }); - - const serverMetadata = await new Promise((resolve, reject) => { - const call = service.sayHello().sendMessageWithCallback({ - name: 'zhangting' - }, (err) => { - if (err) { - reject(err); - } - }); - call.on('metadata', (meta) => { - resolve(meta); - }); - }) - - expect(serverMetadata.get('Set-Cookie')[0]).toEqual('yummy_cookie=choco'); - await closeApp(app); - }); - - it('should create multiple grpc service in one server', async () => { - const app = await createServer('base-app-multiple-service'); - const opts = { - package: 'hero', - protoPath: join(__dirname, 'fixtures/proto/hero.proto'), - url: 'localhost:6575' - } - const service = await createGRPCConsumer({ ...opts, }); - const result = await service.findOne().sendMessage({ id: 123 }); - expect(result).toEqual({ id: 1, name: 'bbbb-Hello harry' }) - await closeApp(app); - }); - - it('should create multiple grpc service in one server 2', async () => { - const app = await createServer('base-app-multiple-service-2'); - const opts = { - package: 'hero2', - protoPath: join(__dirname, 'fixtures/proto/hero2.proto'), - url: 'localhost:6566' - } - - const service = await createGRPCConsumer({ ...opts, }); - const result = await service.findOne().sendMessage({ id: 123 }); - expect(result).toEqual({ id: 1, name: 'bbbb-Hello harry' }) - - const service2 = await createGRPCConsumer({ service: 'HeroService2', ...opts, }); - const result2 = await service2.findOne2().sendMessage({ id: 123 }); - expect(result2).toEqual({ id: 1, name: 'bbbb-Hello harry' }) - - const service3 = await createGRPCConsumer({ ...opts, service: 'hero2.HeroService2' }); - const result3 = await service3.findOne2().sendMessage({ id: 123 }); - expect(result3).toEqual({ id: 1, name: 'bbbb-Hello harry' }) - await closeApp(app); - }); + // it('should create gRPC server', async () => { + // const app = await createServer('base-app'); + + // const service = await createGRPCConsumer({ + // package: 'helloworld', + // protoPath: join(__dirname, 'fixtures/proto/helloworld.proto'), + // url: 'localhost:6565' + // }); + + // const meta = new Metadata(); + // meta.add('key', 'value'); + + // const result = await service.sayHello({ + // metadata: meta, + // }).sendMessage({ + // name: 'harry' + // }); + + // expect(result).toEqual({ message: 'Hello harry' }); + + // const serverMetadata = await new Promise((resolve, reject) => { + // const call = service.sayHello().sendMessageWithCallback({ + // name: 'zhangting' + // }, (err) => { + // if (err) { + // reject(err); + // } + // }); + // call.on('metadata', (meta) => { + // resolve(meta); + // }); + // }) + + // expect(serverMetadata.get('Set-Cookie')[0]).toEqual('yummy_cookie=choco'); + // await closeApp(app); + // }); + + // it('should create multiple grpc service in one server', async () => { + // const app = await createServer('base-app-multiple-service'); + // const opts = { + // package: 'hero', + // protoPath: join(__dirname, 'fixtures/proto/hero.proto'), + // url: 'localhost:6575' + // } + // const service = await createGRPCConsumer({ ...opts, }); + // const result = await service.findOne().sendMessage({ id: 123 }); + // expect(result).toEqual({ id: 1, name: 'bbbb-Hello harry' }) + // await closeApp(app); + // }); + + // it('should create multiple grpc service in one server 2', async () => { + // const app = await createServer('base-app-multiple-service-2'); + // const opts = { + // package: 'hero2', + // protoPath: join(__dirname, 'fixtures/proto/hero2.proto'), + // url: 'localhost:6566' + // } + + // const service = await createGRPCConsumer({ ...opts, }); + // const result = await service.findOne().sendMessage({ id: 123 }); + // expect(result).toEqual({ id: 1, name: 'bbbb-Hello harry' }) + + // const service2 = await createGRPCConsumer({ service: 'HeroService2', ...opts, }); + // const result2 = await service2.findOne2().sendMessage({ id: 123 }); + // expect(result2).toEqual({ id: 1, name: 'bbbb-Hello harry' }) + + // const service3 = await createGRPCConsumer({ ...opts, service: 'hero2.HeroService2' }); + // const result3 = await service3.findOne2().sendMessage({ id: 123 }); + // expect(result3).toEqual({ id: 1, name: 'bbbb-Hello harry' }) + // await closeApp(app); + // }); it('should support publish stream gRPC server', async () => { const app = await createServer('base-app-stream'); @@ -352,20 +352,20 @@ describe('/test/index.test.ts', function () { await closeApp(app); }); - it('should test multi-package service', async () => { - const app = await createServer('base-app-multiple-package'); + // it('should test multi-package service', async () => { + // const app = await createServer('base-app-multiple-package'); - const service = await createGRPCConsumer({ - package: 'hello.world', - protoPath: join(__dirname, 'fixtures/proto/hello_world.proto'), - url: 'localhost:6569' - }); + // const service = await createGRPCConsumer({ + // package: 'hello.world', + // protoPath: join(__dirname, 'fixtures/proto/hello_world.proto'), + // url: 'localhost:6569' + // }); - const result = await service.sayHello().sendMessage({ - name: 'harry' - }); + // const result = await service.sayHello().sendMessage({ + // name: 'harry' + // }); - expect(result).toEqual({ message: 'Hello harry' }); - await closeApp(app); - }); + // expect(result).toEqual({ message: 'Hello harry' }); + // await closeApp(app); + // }); });