From a1b11388e836f4f670d0cebf1d50836a973d1e2c Mon Sep 17 00:00:00 2001 From: ace-n Date: Sun, 2 Jun 2019 23:16:11 -0700 Subject: [PATCH] Apply ESLint (Node 8) + use delay package --- endpoints/getting-started-grpc/client.js | 7 ++++--- endpoints/getting-started-grpc/package.json | 1 + endpoints/getting-started-grpc/server.js | 7 ++++--- .../system-test/endpoints.test.js | 19 ++++++------------- endpoints/getting-started/app.js | 2 +- endpoints/getting-started/test/app.test.js | 2 +- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/endpoints/getting-started-grpc/client.js b/endpoints/getting-started-grpc/client.js index 2acfc722ae..a4f32ee591 100644 --- a/endpoints/getting-started-grpc/client.js +++ b/endpoints/getting-started-grpc/client.js @@ -54,7 +54,7 @@ function makeGrpcRequest(JWT_AUTH_TOKEN, API_KEY, HOST, GREETEE) { } // The command-line program -const argv = require('yargs') +const {argv} = require('yargs') .usage( 'Usage: node $0 {-k YOUR_API_KEY>, <-j YOUR_JWT_AUTH_TOKEN} [-h YOUR_ENDPOINTS_HOST] [-g GREETEE_NAME]' ) @@ -92,7 +92,8 @@ const argv = require('yargs') .wrap(120) .help() .strict() - .epilogue(`For more information, see https://cloud.google.com/endpoints/docs`) - .argv; + .epilogue( + `For more information, see https://cloud.google.com/endpoints/docs` + ); makeGrpcRequest(argv.jwtAuthToken, argv.apiKey, argv.host, argv.greetee); diff --git a/endpoints/getting-started-grpc/package.json b/endpoints/getting-started-grpc/package.json index 08662fa494..a87479d3cc 100644 --- a/endpoints/getting-started-grpc/package.json +++ b/endpoints/getting-started-grpc/package.json @@ -24,6 +24,7 @@ }, "devDependencies": { "@google-cloud/nodejs-repo-tools": "^3.3.0", + "delay": "^4.2.0", "mocha": "^6.0.0" }, "cloud-repo-tools": { diff --git a/endpoints/getting-started-grpc/server.js b/endpoints/getting-started-grpc/server.js index 5c8e20988e..b4d4a53b55 100644 --- a/endpoints/getting-started-grpc/server.js +++ b/endpoints/getting-started-grpc/server.js @@ -35,7 +35,7 @@ function startServer(PORT) { } // The command-line program -const argv = require('yargs') +const {argv} = require('yargs') .usage('Usage: node $0 [-p PORT]') .option('port', { alias: 'p', @@ -44,7 +44,8 @@ const argv = require('yargs') global: true, }) .wrap(120) - .epilogue(`For more information, see https://cloud.google.com/endpoints/docs`) - .argv; + .epilogue( + `For more information, see https://cloud.google.com/endpoints/docs` + ); startServer(argv.port); diff --git a/endpoints/getting-started-grpc/system-test/endpoints.test.js b/endpoints/getting-started-grpc/system-test/endpoints.test.js index 630e9abb8d..3ad2871a0a 100644 --- a/endpoints/getting-started-grpc/system-test/endpoints.test.js +++ b/endpoints/getting-started-grpc/system-test/endpoints.test.js @@ -21,6 +21,7 @@ const assert = require('assert'); const fs = require(`fs`); const jwt = require('jsonwebtoken'); const tools = require('@google-cloud/nodejs-repo-tools'); +const delay = require('delay'); const clientCmd = `node client.js`; const serverCmd = `node server.js`; @@ -71,10 +72,6 @@ const JWT_AUTH_TOKEN = jwt.sign( {algorithm: 'RS256'} ); -const delay = mSec => { - return new Promise(resolve => setTimeout(resolve, mSec)); -}; - // API key it(`should request a greeting from a remote Compute Engine instance using an API key`, async () => { const output = await tools.runAsync( @@ -136,14 +133,10 @@ it(`should request and handle a greeting locally using a JWT Auth Token`, async }); // Misc -it('should require either an API key or a JWT Auth Token', done => { - tools.runAsync(`${clientCmd} -h ${GCE_HOST}`, cwd).then( - () => {}, - error => { - assert.ok( - error.message.includes('One of API_KEY or JWT_AUTH_TOKEN must be set') - ); - done(); - } +it('should require either an API key or a JWT Auth Token', async () => { + const {stderr} = await tools.runAsyncWithIO( + `${clientCmd} -h ${GCE_HOST}`, + cwd ); + assert.ok(stderr.includes('One of API_KEY or JWT_AUTH_TOKEN must be set')); }); diff --git a/endpoints/getting-started/app.js b/endpoints/getting-started/app.js index 396dbd1702..c37ba8f622 100644 --- a/endpoints/getting-started/app.js +++ b/endpoints/getting-started/app.js @@ -19,7 +19,7 @@ // [START setup] const express = require('express'); const bodyParser = require('body-parser'); -const Buffer = require('safe-buffer').Buffer; +const {Buffer} = require('safe-buffer'); const app = express(); diff --git a/endpoints/getting-started/test/app.test.js b/endpoints/getting-started/test/app.test.js index 1cfd5526d5..889c62f0d4 100644 --- a/endpoints/getting-started/test/app.test.js +++ b/endpoints/getting-started/test/app.test.js @@ -15,7 +15,7 @@ 'use strict'; -const Buffer = require('safe-buffer').Buffer; +const {Buffer} = require('safe-buffer'); const express = require('express'); const path = require('path'); const proxyquire = require('proxyquire').noPreserveCache();