From 62d3b14837c898c2f5596802f18ea76dc713bfd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?z=C5=8Dng=20y=C7=94?= Date: Fri, 12 Oct 2018 09:58:42 +0800 Subject: [PATCH] fix: avoid experimental warning of http2 (#14) --- lib/client/index.js | 16 ++++++++++++++-- lib/server/index.js | 9 ++++++++- package.json | 2 +- test/client/index.test.js | 14 ++++++++++++++ test/client/require.js | 5 +++++ 5 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 test/client/index.test.js create mode 100644 test/client/require.js diff --git a/lib/client/index.js b/lib/client/index.js index 18ef906..ee6155f 100644 --- a/lib/client/index.js +++ b/lib/client/index.js @@ -6,5 +6,17 @@ exports.RpcConsumer = require('./consumer'); exports.RpcConnection = require('./connection/rpc'); exports.RpcConnectionMgr = require('./connection_mgr'); exports.DynamicConfig = require('./dynamic_config'); -exports.GRpcClient = require('./grpc_client'); -exports.GRpcConnection = require('./connection/grpc'); + +// avoid stderr "ExperimentalWarning: The http2 module is an experimental API." +Object.defineProperty(exports, 'GRpcClient', { + get() { + return require('./grpc_client'); + }, + enumerable: true, +}); +Object.defineProperty(exports, 'GRpcConnection', { + get() { + return require('./connection/grpc'); + }, + enumerable: true, +}); diff --git a/lib/server/index.js b/lib/server/index.js index 5022cfe..d7747a1 100644 --- a/lib/server/index.js +++ b/lib/server/index.js @@ -4,4 +4,11 @@ exports.RpcServer = require('./server'); exports.RpcService = require('./service'); exports.RpcResponse = require('./response'); exports.RpcConnection = require('./connection'); -exports.GRpcServer = require('./grpc/server'); + +// avoid stderr "ExperimentalWarning: The http2 module is an experimental API." +Object.defineProperty(exports, 'GRpcServer', { + get() { + return require('./grpc/server'); + }, + enumerable: true, +}); diff --git a/package.json b/package.json index cc83f8d..430cf66 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "await-first": "^1.0.0", "byte": "^2.0.0", "cluster-client": "^2.1.1", - "debug": "^4.0.1", + "debug": "^4.1.0", "easy-table": "^1.1.1", "graceful": "^1.0.1", "is-type-of": "^1.2.1", diff --git a/test/client/index.test.js b/test/client/index.test.js new file mode 100644 index 0000000..2d2c55d --- /dev/null +++ b/test/client/index.test.js @@ -0,0 +1,14 @@ +'use strict'; + +const path = require('path'); +const coffee = require('coffee'); + +describe('test/client/index.test.js', () => { + it('should not have stderr', done => { + coffee.fork(path.join(__dirname, 'require.js'), []) + .expect('stdout', 'hello world\n') + .expect('stderr', '') + .expect('code', 0) + .end(done); + }); +}); diff --git a/test/client/require.js b/test/client/require.js new file mode 100644 index 0000000..f5e245d --- /dev/null +++ b/test/client/require.js @@ -0,0 +1,5 @@ +'use strict'; + +require('../..'); + +console.log('hello world');