From 9f1c166629a45330670048a829615ba0237f426d Mon Sep 17 00:00:00 2001 From: Bojan Date: Sun, 31 Jan 2021 19:03:39 -0400 Subject: [PATCH] fixing tests --- package.json | 2 +- test/app.test.js | 119 +++++++++++++++++++++------------------------ test/utils.test.js | 1 - 3 files changed, 57 insertions(+), 65 deletions(-) diff --git a/package.json b/package.json index 97c44b2..7e814ba 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "lib/app.js", "scripts": { "lint": "standard | snazzy", - "linttest": "ava -v", + "linttest": "npm run lint && ava -v", "test": "nyc npm run linttest", "coverage": "nyc report --reporter=text-lcov > ./coverage/lcov.info", "apidocs": "jsdoc2md lib/*.js > api2.md", diff --git a/test/app.test.js b/test/app.test.js index 33c76a3..f31a309 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -48,7 +48,7 @@ test('app.inspect should return app properties', t => { t.is('{ ports: [],\n context: Context {},\n env: \'development\',\n name: \'Greeter\',\n foo: \'bar\' }'.replace(/\s/g, ''), str.replace(/\s/g, '')) }) -test.cb('app.start() with a default port from OS when no params given', t => { +test('app.start() with a default port from OS when no params given', async t => { t.plan(5) const PROTO_PATH = path.resolve(__dirname, './protos/helloworld.proto') @@ -59,17 +59,16 @@ test.cb('app.start() with a default port from OS when no params given', t => { const app = new Mali(PROTO_PATH, 'Greeter') t.truthy(app) app.use({ sayHello }) - app.start().then(server => { - t.truthy(server) - const ports = app.ports - t.truthy(ports) - t.is(ports.length, 1) - t.true(typeof ports[0] === 'number') - app.close().then(() => t.end()) - }) + const server = await app.start() + t.truthy(server) + const ports = app.ports + t.truthy(ports) + t.is(ports.length, 1) + t.true(typeof ports[0] === 'number') + await app.close() }) -test.cb('app.start() should start and not throw with incomplete API', t => { +test('app.start() should start and not throw with incomplete API', async t => { t.plan(5) const PROTO_PATH = path.resolve(__dirname, './protos/transform.proto') @@ -80,17 +79,16 @@ test.cb('app.start() should start and not throw with incomplete API', t => { const app = new Mali(PROTO_PATH, 'TransformService') t.truthy(app) app.use({ upper }) - app.start().then(server => { - t.truthy(server) - const ports = app.ports - t.truthy(ports) - t.is(ports.length, 1) - t.true(typeof ports[0] === 'number') - app.close().then(() => t.end()) - }) + const server = await app.start() + t.truthy(server) + const ports = app.ports + t.truthy(ports) + t.is(ports.length, 1) + t.true(typeof ports[0] === 'number') + await app.close() }) -test.cb('app.start() with a default port from OS with object param', t => { +test('app.start() with a default port from OS with object param', async t => { t.plan(5) const PROTO_PATH = path.resolve(__dirname, './protos/helloworld.proto') @@ -101,17 +99,16 @@ test.cb('app.start() with a default port from OS with object param', t => { const app = new Mali(PROTO_PATH, 'Greeter') t.truthy(app) app.use({ sayHello }) - app.start(grpc.ServerCredentials.createInsecure()).then(server => { - t.truthy(server) - const ports = app.ports - t.truthy(ports) - t.is(ports.length, 1) - t.true(typeof ports[0] === 'number') - app.close().then(() => t.end()) - }) + const server = await app.start(grpc.ServerCredentials.createInsecure()) + t.truthy(server) + const ports = app.ports + t.truthy(ports) + t.is(ports.length, 1) + t.true(typeof ports[0] === 'number') + await app.close() }) -test.cb('app.start() with a default port from OS with "127.0.0.1:0"', t => { +test('app.start() with a default port from OS with "127.0.0.1:0"', async t => { t.plan(5) const PROTO_PATH = path.resolve(__dirname, './protos/helloworld.proto') @@ -122,17 +119,16 @@ test.cb('app.start() with a default port from OS with "127.0.0.1:0"', t => { const app = new Mali(PROTO_PATH, 'Greeter') t.truthy(app) app.use({ sayHello }) - app.start('127.0.0.1:0').then(server => { - t.truthy(server) - const ports = app.ports - t.truthy(ports) - t.is(ports.length, 1) - t.true(typeof ports[0] === 'number') - app.close().then(() => t.end()) - }) + const server = await app.start('127.0.0.1:0') + t.truthy(server) + const ports = app.ports + t.truthy(ports) + t.is(ports.length, 1) + t.true(typeof ports[0] === 'number') + await app.close() }) -test.cb('app.start() with a default port from OS with ""', t => { +test('app.start() with a default port from OS with ""', async t => { t.plan(5) const PROTO_PATH = path.resolve(__dirname, './protos/helloworld.proto') @@ -143,17 +139,16 @@ test.cb('app.start() with a default port from OS with ""', t => { const app = new Mali(PROTO_PATH, 'Greeter') t.truthy(app) app.use({ sayHello }) - app.start('').then(server => { - t.truthy(server) - const ports = app.ports - t.truthy(ports) - t.is(ports.length, 1) - t.true(typeof ports[0] === 'number') - app.close().then(() => t.end()) - }) + const server = await app.start('') + t.truthy(server) + const ports = app.ports + t.truthy(ports) + t.is(ports.length, 1) + t.true(typeof ports[0] === 'number') + await app.close() }) -test.cb('app.start() with param', t => { +test('app.start() with param', async t => { t.plan(5) const PORT = tu.getPort() const PROTO_PATH = path.resolve(__dirname, './protos/helloworld.proto') @@ -165,17 +160,16 @@ test.cb('app.start() with param', t => { const app = new Mali(PROTO_PATH, 'Greeter') t.truthy(app) app.use({ sayHello }) - app.start(`127.0.0.1:0${PORT}`).then(server => { - t.truthy(server) - const ports = app.ports - t.truthy(ports) - t.is(ports.length, 1) - t.is(ports[0], PORT) - app.close().then(() => t.end()) - }) + const server = await app.start(`127.0.0.1:0${PORT}`) + t.truthy(server) + const ports = app.ports + t.truthy(ports) + t.is(ports.length, 1) + t.is(ports[0], PORT) + await app.close() }) -test.cb('app.start() with port param and invalid creds', t => { +test('app.start() with port param and invalid creds', async t => { t.plan(5) const PORT = tu.getPort() const PROTO_PATH = path.resolve(__dirname, './protos/helloworld.proto') @@ -187,14 +181,13 @@ test.cb('app.start() with port param and invalid creds', t => { const app = new Mali(PROTO_PATH, 'Greeter') t.truthy(app) app.use({ sayHello }) - app.start(`127.0.0.1:0${PORT}`, 'foo').then(server => { - t.truthy(server) - const ports = app.ports - t.truthy(ports) - t.is(ports.length, 1) - t.is(ports[0], PORT) - app.close().then(() => t.end()) - }) + const server = await app.start(`127.0.0.1:0${PORT}`, 'foo') + t.truthy(server) + const ports = app.ports + t.truthy(ports) + t.is(ports.length, 1) + t.is(ports[0], PORT) + await app.close() }) test.cb('app.start() should throw when binding to taken port', t => { diff --git a/test/utils.test.js b/test/utils.test.js index a525a2f..ed75821 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -189,7 +189,6 @@ test.cb('getCallTypeFromCall() should get call type from REQUEST_STREAM call', t const app = new Mali(PROTO_PATH, 'ArgService') app.use({ writeStuff }) app.start(APP_HOST).then(server => { - const pd = pl.loadSync(PROTO_PATH) const proto = grpc.loadPackageDefinition(pd).argservice const client = new proto.ArgService(APP_HOST, grpc.credentials.createInsecure())