From 26933fe0cbcff858af0760e3c102faacad80e11d Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Tue, 24 Mar 2020 13:40:17 -0700 Subject: [PATCH] feat(deps): update gts to v2 (#340) * update gts in template * update baseline * update generator dependency GTS to v2 * merge * tests pass * clean up * final work * fix test application * feedback * rerun gts fix * no bracketSpacing * fix tests * drop eslint related dependency * update gts to latest version and rerun gts fix * remove .prettierre.json * remove process.exit(1) * clean up --- .eslintignore | 7 ++ .eslintrc.json | 3 + .prettierignore | 5 ++ .prettierrc.js | 17 ++++ package.json | 2 +- test-fixtures/test-application-js/server.js | 4 +- .../test-application-ts/src/index.ts | 13 ++-- .../src/integration-test.ts | 2 +- .../test-application-ts/src/server.ts | 6 +- .../test-application-ts/webpack.config.js | 78 +++++++++---------- typescript/src/bundle.ts | 2 +- typescript/src/cli.ts | 10 +-- typescript/src/generator.ts | 10 +-- typescript/src/schema/api.ts | 6 +- typescript/src/schema/comments.ts | 2 +- typescript/src/schema/naming.ts | 6 +- typescript/src/schema/proto.ts | 12 +-- typescript/src/schema/resource-database.ts | 6 +- typescript/src/start-script.ts | 60 ++++++-------- typescript/src/templater.ts | 6 +- typescript/src/util.ts | 20 ++--- typescript/test/test-application/test-js.ts | 12 +-- typescript/test/test-application/test-ts.ts | 18 ++--- typescript/test/unit/api.ts | 5 +- typescript/test/unit/baselines.ts | 4 +- typescript/test/unit/naming.ts | 10 ++- typescript/test/unit/proto.ts | 8 +- typescript/test/unit/resource-database.ts | 4 +- typescript/test/unit/retryable-code-map.ts | 20 ++--- typescript/test/unit/util.ts | 4 +- typescript/test/util.ts | 6 +- typescript/tools/update-baselines.ts | 6 +- 32 files changed, 199 insertions(+), 175 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc.json create mode 100644 .prettierignore create mode 100644 .prettierrc.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..652b9d119 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,7 @@ +**/node_modules +**/.coverage +build/ +docs/ +protos/ +test-fixtures/ +pbjs-genfiles/ diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 000000000..eb23147be --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "./node_modules/gts" +} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..a4ac7b375 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +**/node_modules +**/.coverage +build/ +docs/ +protos/ diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 000000000..21df10709 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,17 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +module.exports = { + ...require('gts/.prettierrc.json') +} diff --git a/package.json b/package.json index f413a6145..8fc2c0044 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "c8": "^7.1.0", "codecov": "^3.6.5", "espower-typescript": "^9.0.2", - "gts": "^1.1.2", + "gts": "next", "mocha": "^7.1.1", "ncp": "^2.0.0", "rimraf": "^3.0.2", diff --git a/test-fixtures/test-application-js/server.js b/test-fixtures/test-application-js/server.js index 95a28e5db..0fc10f258 100644 --- a/test-fixtures/test-application-js/server.js +++ b/test-fixtures/test-application-js/server.js @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. const fs = require('fs-extra'); -const { spawn } = require('child_process'); -var kill = require('tree-kill'); +const {spawn} = require('child_process'); +const kill = require('tree-kill'); const path = require('path'); const SHOWCASE_SERVER = path.join( __dirname, diff --git a/test-fixtures/test-application-ts/src/index.ts b/test-fixtures/test-application-ts/src/index.ts index f4b94860f..54698a70f 100644 --- a/test-fixtures/test-application-ts/src/index.ts +++ b/test-fixtures/test-application-ts/src/index.ts @@ -18,12 +18,12 @@ import * as showcase from 'showcase'; import * as grpc from '@grpc/grpc-js'; // to create credentials for local Showcase server interface ClientOptions{ - [name: string] : Object, - servicePath: string, - port: number + [name: string]: Object; + servicePath: string; + port: number; } -interface Options{ - [name: string] : Object +interface Options { + [name: string]: Object; } // Fake auth client for fallback const authStub = { @@ -115,7 +115,7 @@ function testExpand(client: showcase.v1beta1.EchoClient) { }; const result = await new Promise((resolve, reject) => { const stream = client.expand(request); - const result:string[] = []; + const result: string[] = []; stream.on('data', response => { result.push(response.content); }); @@ -211,4 +211,3 @@ function testWait(client: showcase.v1beta1.EchoClient) { assert.deepStrictEqual(response.content, request.success.content); }); } - diff --git a/test-fixtures/test-application-ts/src/integration-test.ts b/test-fixtures/test-application-ts/src/integration-test.ts index d80e5d3bc..09933d04b 100644 --- a/test-fixtures/test-application-ts/src/integration-test.ts +++ b/test-fixtures/test-application-ts/src/integration-test.ts @@ -18,7 +18,7 @@ import * as path from 'path'; import * as fs from 'fs-extra'; import {Server} from './server'; const exec = util.promisify(child_process.exec); -const SHOWCASE_SERVER = path.join(__dirname,'..', '..', 'showcase-server'); +const SHOWCASE_SERVER = path.join(__dirname, '..', '..', 'showcase-server'); const SHOWCASE_SERVER_TAR = path.join( SHOWCASE_SERVER, 'gapic-showcase-server.tar.gz' diff --git a/test-fixtures/test-application-ts/src/server.ts b/test-fixtures/test-application-ts/src/server.ts index 993fcb3a0..c027d7c7e 100644 --- a/test-fixtures/test-application-ts/src/server.ts +++ b/test-fixtures/test-application-ts/src/server.ts @@ -22,10 +22,10 @@ const SHOWCASE_SERVER = path.join( 'gapic-showcase' ); -export class Server{ +export class Server { pid: number = -1; constrcutor() {} - run(){ + run() { if (!fs.existsSync(SHOWCASE_SERVER)) { console.warn( 'gapic showcase server does not exist, please download it first.' @@ -36,4 +36,4 @@ export class Server{ kill() { process.kill(this.pid); } -}; +} diff --git a/test-fixtures/test-application-ts/webpack.config.js b/test-fixtures/test-application-ts/webpack.config.js index 29ee8cbe8..24aa6a786 100644 --- a/test-fixtures/test-application-ts/webpack.config.js +++ b/test-fixtures/test-application-ts/webpack.config.js @@ -1,42 +1,42 @@ const path = require('path'); module.exports = { - entry: './build/src/index.js', - output: { - library: "showcaseTest", - filename: "./main.js" - }, - node: { - child_process: 'empty', - fs: 'empty', - crypto: 'empty', - }, - resolve: { - extensions: ['.js', '.json'] - }, - module: { - rules: [ - { - test: /node_modules[\\\/]@grpc[\\\/]grpc-js/, - use: 'null-loader' - }, - { - test: /node_modules[\\\/]grpc/, - use: 'null-loader' - }, - { - test: /node_modules[\\\/]retry-request/, - use: 'null-loader' - }, - { - test: /node_modules[\\\/]https-proxy-agent/, - use: 'null-loader' - }, - { - test: /node_modules[\\\/]gtoken/, - use: 'null-loader' - }, - ] - }, - mode: 'production' -} + entry: './build/src/index.js', + output: { + library: 'showcaseTest', + filename: './main.js', + }, + node: { + child_process: 'empty', + fs: 'empty', + crypto: 'empty', + }, + resolve: { + extensions: ['.js', '.json'], + }, + module: { + rules: [ + { + test: /node_modules[\\\/]@grpc[\\\/]grpc-js/, + use: 'null-loader', + }, + { + test: /node_modules[\\\/]grpc/, + use: 'null-loader', + }, + { + test: /node_modules[\\\/]retry-request/, + use: 'null-loader', + }, + { + test: /node_modules[\\\/]https-proxy-agent/, + use: 'null-loader', + }, + { + test: /node_modules[\\\/]gtoken/, + use: 'null-loader', + }, + ], + }, + mode: 'production', +}; diff --git a/typescript/src/bundle.ts b/typescript/src/bundle.ts index cdb8192d3..9d46d0201 100644 --- a/typescript/src/bundle.ts +++ b/typescript/src/bundle.ts @@ -19,7 +19,7 @@ export interface BundleConfig { export class BundleConfigClient { bundleConfigs: BundleConfig[] = []; - // tslint:disable-next-line no-any + /* eslint-disable @typescript-eslint/no-explicit-any */ fromObject(yaml: any) { // construct meaning Object from GAPIC v2 file. const interfaces = yaml['interfaces']; diff --git a/typescript/src/cli.ts b/typescript/src/cli.ts index a2ef3bfce..320819236 100644 --- a/typescript/src/cli.ts +++ b/typescript/src/cli.ts @@ -15,14 +15,13 @@ // limitations under the License. import * as yargs from 'yargs'; -import { Generator } from './generator'; +import {Generator} from './generator'; async function main() { const argv = yargs.argv; if (argv.descriptor) { - console.error('Descriptor option is not yet supported.'); - process.exit(1); + throw new Error('Descriptor option is not yet supported.'); } const generator = new Generator(); @@ -30,7 +29,4 @@ async function main() { await generator.generate(); } -main().catch(err => { - console.error(err); - process.exit(1); -}); +main(); diff --git a/typescript/src/generator.ts b/typescript/src/generator.ts index 37a927dcf..7a751f70f 100644 --- a/typescript/src/generator.ts +++ b/typescript/src/generator.ts @@ -20,10 +20,10 @@ import * as yaml from 'js-yaml'; import * as plugin from '../../pbjs-genfiles/plugin'; -import { API } from './schema/api'; -import { processTemplates } from './templater'; -import { BundleConfigClient, BundleConfig } from './bundle'; -import { commonPrefix, duration } from './util'; +import {API} from './schema/api'; +import {processTemplates} from './templater'; +import {BundleConfigClient, BundleConfig} from './bundle'; +import {commonPrefix, duration} from './util'; export interface OptionsMap { [name: string]: string; @@ -57,7 +57,7 @@ export class Generator { // Fixes gRPC service config to replace string google.protobuf.Duration // to a proper Duration message, since protobufjs does not support // string Durations such as "30s". - private static updateDuration(obj: { [key: string]: {} }) { + private static updateDuration(obj: {[key: string]: {}}) { const fieldNames = [ 'timeout', 'initialBackoff', diff --git a/typescript/src/schema/api.ts b/typescript/src/schema/api.ts index d3007e51c..56fd32d47 100644 --- a/typescript/src/schema/api.ts +++ b/typescript/src/schema/api.ts @@ -14,9 +14,9 @@ import * as plugin from '../../../pbjs-genfiles/plugin'; -import { Naming, Options as namingOptions } from './naming'; -import { Proto } from './proto'; -import { ResourceDatabase, ResourceDescriptor } from './resource-database'; +import {Naming, Options as namingOptions} from './naming'; +import {Proto} from './proto'; +import {ResourceDatabase, ResourceDescriptor} from './resource-database'; export interface ProtosMap { [filename: string]: Proto; diff --git a/typescript/src/schema/comments.ts b/typescript/src/schema/comments.ts index 8aebcbc51..b02d264a0 100644 --- a/typescript/src/schema/comments.ts +++ b/typescript/src/schema/comments.ts @@ -157,6 +157,6 @@ export class CommentsMap { } getParamComments(messageName: string, fieldName: string): Comment { const key = messageName + ':' + fieldName; - return this.comments[key] ?? { paramName: '', paramType: '', comments: [] }; + return this.comments[key] ?? {paramName: '', paramType: '', comments: []}; } } diff --git a/typescript/src/schema/naming.ts b/typescript/src/schema/naming.ts index 892603852..537604bee 100644 --- a/typescript/src/schema/naming.ts +++ b/typescript/src/schema/naming.ts @@ -13,9 +13,9 @@ // limitations under the License. import * as plugin from '../../../pbjs-genfiles/plugin'; -import { commonPrefix } from '../util'; -import { API } from './api'; -import { BundleConfig } from 'src/bundle'; +import {commonPrefix} from '../util'; +import {API} from './api'; +import {BundleConfig} from 'src/bundle'; export interface Options { grpcServiceConfig: plugin.grpc.service_config.ServiceConfig; diff --git a/typescript/src/schema/proto.ts b/typescript/src/schema/proto.ts index eb6af6515..3ba925bde 100644 --- a/typescript/src/schema/proto.ts +++ b/typescript/src/schema/proto.ts @@ -13,16 +13,16 @@ // limitations under the License. import * as plugin from '../../../pbjs-genfiles/plugin'; -import { CommentsMap, Comment } from './comments'; -import { milliseconds } from '../util'; -import { ResourceDescriptor, ResourceDatabase } from './resource-database'; +import {CommentsMap, Comment} from './comments'; +import {milliseconds} from '../util'; +import {ResourceDescriptor, ResourceDatabase} from './resource-database'; import { RetryableCodeMap, defaultParametersName, defaultNonIdempotentRetryCodesName, defaultParameters, } from './retryable-code-map'; -import { BundleConfig } from 'src/bundle'; +import {BundleConfig} from 'src/bundle'; interface MethodDescriptorProto extends plugin.google.protobuf.IMethodDescriptorProto { @@ -359,7 +359,7 @@ function augmentMethod( } if (method.methodConfig.retryPolicy) { // converting retry parameters to the syntax google-gax supports - const retryParams: { [key: string]: number } = {}; + const retryParams: {[key: string]: number} = {}; if (method.methodConfig.retryPolicy.initialBackoff) { retryParams.initial_retry_delay_millis = milliseconds( method.methodConfig.retryPolicy.initialBackoff @@ -499,7 +499,7 @@ function augmentService( // allResourceDatabase: resources that defined by `google.api.resource` // resourceDatabase: all resources defined by `google.api.resource` or `google.api.resource_definition` - const uniqueResources: { [name: string]: ResourceDescriptor } = {}; + const uniqueResources: {[name: string]: ResourceDescriptor} = {}; // Copy all resources in resourceDatabase to uniqueResources const allPatterns = resourceDatabase.patterns; for (const pattern of Object.keys(allPatterns)) { diff --git a/typescript/src/schema/resource-database.ts b/typescript/src/schema/resource-database.ts index 08f7943e8..684111435 100644 --- a/typescript/src/schema/resource-database.ts +++ b/typescript/src/schema/resource-database.ts @@ -13,7 +13,7 @@ // limitations under the License. import * as plugin from '../../../pbjs-genfiles/plugin'; -import { getResourceNameByPattern } from '../util'; +import {getResourceNameByPattern} from '../util'; export interface ResourceDescriptor extends plugin.google.api.IResourceDescriptor { @@ -22,8 +22,8 @@ export interface ResourceDescriptor } export class ResourceDatabase { - patterns: { [pattern: string]: ResourceDescriptor }; - types: { [type: string]: ResourceDescriptor }; + patterns: {[pattern: string]: ResourceDescriptor}; + types: {[type: string]: ResourceDescriptor}; constructor() { this.patterns = {}; diff --git a/typescript/src/start-script.ts b/typescript/src/start-script.ts index 3b9108cc4..6ff37e821 100755 --- a/typescript/src/start-script.ts +++ b/typescript/src/start-script.ts @@ -14,11 +14,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { execFileSync } from 'child_process'; +import {execFileSync} from 'child_process'; import * as path from 'path'; import * as yargs from 'yargs'; import * as fs from 'fs-extra'; -const fileSystem = require('file-system'); +const fileSystem = require('file-system'); // eslint-disable-line const googleGaxPath = path.dirname(require.resolve('google-gax')); // ...../google-gax/build/src const googleGaxProtosDir = path.join(googleGaxPath, '..', '..', 'protos'); @@ -107,38 +107,28 @@ if (template) { protocCommand.push(...protoDirsArg); protocCommand.push(...protoFiles); protocCommand.push(`-I${commonProtoPath}`); -try { - execFileSync(`protoc`, protocCommand, { stdio: 'inherit' }); -} catch (err) { - console.error(err.toString()); - process.exit(1); -} +execFileSync(`protoc`, protocCommand, {stdio: 'inherit'}); -try { - // create protos folder to copy proto file - const copyProtoDir = path.join(outputDir, 'protos'); - if (!fs.existsSync(copyProtoDir)) { - fs.mkdirSync(copyProtoDir); - } - // copy proto file to generated folder - const protoList = path.join(outputDir, 'proto.list'); - const protoFilesSet = new Set(protoFiles); - fs.readFileSync(protoList) - .toString() - .split('\n') - .forEach(proto => { - protoDirs.forEach(dir => { - const protoFile = path.join(dir, proto); - if ( - (protoFilesSet.has(protoFile) || - !fs.existsSync(path.join(googleGaxProtosDir, proto))) && - fs.existsSync(protoFile) - ) { - fileSystem.copyFileSync(protoFile, path.join(copyProtoDir, proto)); - } - }); - }); -} catch (err) { - console.error(err.toString()); - process.exit(1); +// create protos folder to copy proto file +const copyProtoDir = path.join(outputDir, 'protos'); +if (!fs.existsSync(copyProtoDir)) { + fs.mkdirSync(copyProtoDir); } +// copy proto file to generated folder +const protoList = path.join(outputDir, 'proto.list'); +const protoFilesSet = new Set(protoFiles); +fs.readFileSync(protoList) + .toString() + .split('\n') + .forEach(proto => { + protoDirs.forEach(dir => { + const protoFile = path.join(dir, proto); + if ( + (protoFilesSet.has(protoFile) || + !fs.existsSync(path.join(googleGaxProtosDir, proto))) && + fs.existsSync(protoFile) + ) { + fileSystem.copyFileSync(protoFile, path.join(copyProtoDir, proto)); + } + }); + }); diff --git a/typescript/src/templater.ts b/typescript/src/templater.ts index 0d319f93f..d00df9364 100644 --- a/typescript/src/templater.ts +++ b/typescript/src/templater.ts @@ -19,9 +19,9 @@ import * as util from 'util'; import * as plugin from '../../pbjs-genfiles/plugin'; -import { API } from './schema/api'; +import {API} from './schema/api'; -const commonParameters: { [name: string]: string } = { +const commonParameters: {[name: string]: string} = { copyrightYear: new Date().getFullYear().toString(), }; @@ -95,7 +95,7 @@ function processOneTemplate( renderFile( outputFilename.replace(/\$service/, service.name!.toSnakeCase()), relativeTemplateName, - { api, commonParameters, service } + {api, commonParameters, service} ) ); } diff --git a/typescript/src/util.ts b/typescript/src/util.ts index ec547afb4..2539377e6 100644 --- a/typescript/src/util.ts +++ b/typescript/src/util.ts @@ -34,7 +34,7 @@ export function commonPrefix(strings: string[]): string { // Convert a string Duration, e.g. "600s", to a proper protobuf type since // protobufjs does not support it at this moment. export function duration(text: string): plugin.google.protobuf.Duration { - const multipliers: { [suffix: string]: number } = { + const multipliers: {[suffix: string]: number} = { s: 1, m: 60, h: 60 * 60, @@ -71,21 +71,21 @@ export function milliseconds( ); } -String.prototype.capitalize = function(this: string): string { +String.prototype.capitalize = function (this: string): string { if (this.length === 0) { return this; } return this[0].toUpperCase() + this.slice(1); }; -String.prototype.words = function(this: string): string[] { +String.prototype.words = function (this: string): string[] { // split on spaces, non-alphanumeric, or capital letters return this.split(/(?=[A-Z])|[\s\W_]+/) .filter(w => w.length > 0) .map(w => w.toLowerCase()); }; -String.prototype.toCamelCase = function(this: string): string { +String.prototype.toCamelCase = function (this: string): string { const words = this.words(); if (words.length === 0) { return this; @@ -95,7 +95,7 @@ String.prototype.toCamelCase = function(this: string): string { return result.join(''); }; -String.prototype.toPascalCase = function(this: string): string { +String.prototype.toPascalCase = function (this: string): string { const words = this.words(); if (words.length === 0) { return this; @@ -104,7 +104,7 @@ String.prototype.toPascalCase = function(this: string): string { return result.join(''); }; -String.prototype.toKebabCase = function(this: string): string { +String.prototype.toKebabCase = function (this: string): string { const words = this.words(); if (words.length === 0) { return this; @@ -112,7 +112,7 @@ String.prototype.toKebabCase = function(this: string): string { return words.join('-'); }; -String.prototype.toSnakeCase = function(this: string): string { +String.prototype.toSnakeCase = function (this: string): string { const words = this.words(); if (words.length === 0) { return this; @@ -120,7 +120,7 @@ String.prototype.toSnakeCase = function(this: string): string { return words.join('_'); }; -String.prototype.replaceAll = function( +String.prototype.replaceAll = function ( this: string, search: string, replacement: string @@ -128,14 +128,14 @@ String.prototype.replaceAll = function( return this.split(search).join(replacement); }; -Array.prototype.toCamelCaseString = function( +Array.prototype.toCamelCaseString = function ( this: string[], joiner: string ): string { return this.map(part => part.toCamelCase()).join(joiner); }; -Array.prototype.toSnakeCaseString = function( +Array.prototype.toSnakeCaseString = function ( this: string[], joiner: string ): string { diff --git a/typescript/test/test-application/test-js.ts b/typescript/test/test-application/test-js.ts index 9a0fbffb0..86cd50f96 100644 --- a/typescript/test/test-application/test-js.ts +++ b/typescript/test/test-application/test-js.ts @@ -16,7 +16,7 @@ import * as util from 'util'; import * as child_process from 'child_process'; import * as fs from 'fs-extra'; import * as path from 'path'; -import { describe, it } from 'mocha'; +import {describe, it} from 'mocha'; const exec = util.promisify(child_process.exec); const SHOWCASE_LIB = path.join( __dirname, @@ -51,7 +51,7 @@ const JS_TEST_APPLICATION = path.join( 'test-application-js' ); describe('Test application for JavaScript users', () => { - it('npm install showcase', async function() { + it('npm install showcase', async function () { this.timeout(60000); // copy protos to generated client library and copy test application to local. fs.copySync(PROTOS, path.join(SHOWCASE_LIB, 'protos')); @@ -59,21 +59,21 @@ describe('Test application for JavaScript users', () => { process.chdir(SHOWCASE_LIB); await exec(`npm install`); }); - it('npm pack showcase library and copy it to test application', async function() { + it('npm pack showcase library and copy it to test application', async function () { this.timeout(60000); await exec(`npm pack`); process.chdir(LOCAL_JS_APPLICATION); fs.copySync(PACKED_LIB_PATH, path.join(LOCAL_JS_APPLICATION, PACKED_LIB)); }); - it('npm install showcase library in test application', async function() { + it('npm install showcase library in test application', async function () { this.timeout(60000); await exec(`npm install`); }); - it('run integration in test application', async function() { + it('run integration in test application', async function () { this.timeout(60000); await exec(`npm test`); }); - it('run browser test in application', async function() { + it('run browser test in application', async function () { this.timeout(120000); await exec(`npm run browser-test`); }); diff --git a/typescript/test/test-application/test-ts.ts b/typescript/test/test-application/test-ts.ts index 770b3928f..0fdfa8070 100644 --- a/typescript/test/test-application/test-ts.ts +++ b/typescript/test/test-application/test-ts.ts @@ -16,7 +16,7 @@ import * as util from 'util'; import * as child_process from 'child_process'; import * as fs from 'fs-extra'; import * as path from 'path'; -import { describe, it } from 'mocha'; +import {describe, it} from 'mocha'; const exec = util.promisify(child_process.exec); const SHOWCASE_LIB = path.join( __dirname, @@ -51,8 +51,8 @@ const TS_TEST_APPLICATION = path.join( 'test-application-ts' ); describe('Test application for TypeScript users', () => { - it('npm install showcase', async function() { - this.timeout(60000); + it('npm install showcase', async function () { + this.timeout(120000); // copy protos to generated client library and copy test application to local. if (!fs.existsSync(path.join(SHOWCASE_LIB, 'protos'))) { fs.copySync(PROTOS, path.join(SHOWCASE_LIB, 'protos')); @@ -63,21 +63,21 @@ describe('Test application for TypeScript users', () => { process.chdir(SHOWCASE_LIB); await exec(`npm install`); }); - it('npm pack showcase library and copy it to test application', async function() { - this.timeout(60000); + it('npm pack showcase library and copy it to test application', async function () { + this.timeout(120000); await exec(`npm pack`); process.chdir(LOCAL_TS_APPLICATION); fs.copySync(PACKED_LIB_PATH, path.join(LOCAL_TS_APPLICATION, PACKED_LIB)); }); - it('npm install showcase library in test application', async function() { - this.timeout(60000); + it('npm install showcase library in test application', async function () { + this.timeout(120000); await exec(`npm install`); }); - it('run integration in test application', async function() { + it('run integration in test application', async function () { this.timeout(120000); await exec(`npm test`); }); - it('run browser test in application', async function() { + it('run browser test in application', async function () { this.timeout(120000); await exec(`npm run browser-test`); }); diff --git a/typescript/test/unit/api.ts b/typescript/test/unit/api.ts index f78c03680..0750dab2e 100644 --- a/typescript/test/unit/api.ts +++ b/typescript/test/unit/api.ts @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { API } from '../../src/schema/api'; +import {API} from '../../src/schema/api'; import * as plugin from '../../../pbjs-genfiles/plugin'; import * as assert from 'assert'; -import { describe, it } from 'mocha'; +import {describe, it} from 'mocha'; describe('src/schema/api.ts', () => { it('should construct an API object and return list of protos', () => { @@ -154,6 +154,7 @@ describe('src/schema/api.ts', () => { const api = new API([fd], 'google.cloud.test.v1', { grpcServiceConfig: new plugin.grpc.service_config.ServiceConfig(), }); + assert(api); }); }); }); diff --git a/typescript/test/unit/baselines.ts b/typescript/test/unit/baselines.ts index 1db5cd40e..155e6d61f 100644 --- a/typescript/test/unit/baselines.ts +++ b/typescript/test/unit/baselines.ts @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { describe } from 'mocha'; -import { runBaselineTest, initBaselineTest } from '../util'; +import {describe} from 'mocha'; +import {runBaselineTest, initBaselineTest} from '../util'; describe('Baseline tests', () => { initBaselineTest(); diff --git a/typescript/test/unit/naming.ts b/typescript/test/unit/naming.ts index 3d063492f..240f7d87e 100644 --- a/typescript/test/unit/naming.ts +++ b/typescript/test/unit/naming.ts @@ -13,9 +13,9 @@ // limitations under the License. import * as assert from 'assert'; -import { describe, it } from 'mocha'; +import {describe, it} from 'mocha'; import * as plugin from '../../../pbjs-genfiles/plugin'; -import { Naming, Options } from '../../src/schema/naming'; +import {Naming, Options} from '../../src/schema/naming'; describe('src/schema/naming.ts', () => { it('parses name correctly', () => { @@ -92,6 +92,7 @@ describe('src/schema/naming.ts', () => { descriptor.service = [new plugin.google.protobuf.ServiceDescriptorProto()]; assert.throws(() => { const naming = new Naming([descriptor]); + assert(naming); }); }); @@ -101,6 +102,7 @@ describe('src/schema/naming.ts', () => { descriptor.service = [new plugin.google.protobuf.ServiceDescriptorProto()]; assert.throws(() => { const naming = new Naming([descriptor]); + assert(naming); }); }); @@ -110,6 +112,7 @@ describe('src/schema/naming.ts', () => { descriptor.service = [new plugin.google.protobuf.ServiceDescriptorProto()]; assert.throws(() => { const naming = new Naming([descriptor]); + assert(naming); }); }); @@ -122,6 +125,7 @@ describe('src/schema/naming.ts', () => { descriptor2.service = [new plugin.google.protobuf.ServiceDescriptorProto()]; assert.throws(() => { const naming = new Naming([descriptor1, descriptor2]); + assert(naming); }); }); @@ -156,6 +160,7 @@ describe('src/schema/naming.ts', () => { descriptor2.service = [new plugin.google.protobuf.ServiceDescriptorProto()]; assert.throws(() => { const naming = new Naming([descriptor1, descriptor2]); + assert(naming); }); }); @@ -168,6 +173,7 @@ describe('src/schema/naming.ts', () => { descriptor2.service = [new plugin.google.protobuf.ServiceDescriptorProto()]; assert.throws(() => { const naming = new Naming([descriptor1, descriptor2]); + assert(naming); }); }); }); diff --git a/typescript/test/unit/proto.ts b/typescript/test/unit/proto.ts index 6bb465a72..2fac02e2b 100644 --- a/typescript/test/unit/proto.ts +++ b/typescript/test/unit/proto.ts @@ -13,11 +13,11 @@ // limitations under the License. import * as assert from 'assert'; -import { describe, it } from 'mocha'; +import {describe, it} from 'mocha'; import * as plugin from '../../../pbjs-genfiles/plugin'; -import { getHeaderRequestParams } from '../../src/schema/proto'; -import { Proto } from '../../src/schema/proto'; -import { ResourceDatabase } from '../../src/schema/resource-database'; +import {getHeaderRequestParams} from '../../src/schema/proto'; +import {Proto} from '../../src/schema/proto'; +import {ResourceDatabase} from '../../src/schema/resource-database'; describe('src/schema/proto.ts', () => { describe('should get header parameters from http rule', () => { diff --git a/typescript/test/unit/resource-database.ts b/typescript/test/unit/resource-database.ts index 07ee70a62..47b65835f 100644 --- a/typescript/test/unit/resource-database.ts +++ b/typescript/test/unit/resource-database.ts @@ -13,8 +13,8 @@ // limitations under the License. import * as plugin from '../../../pbjs-genfiles/plugin'; -import { ResourceDatabase } from '../../src/schema/resource-database'; -import { describe, it, beforeEach, afterEach } from 'mocha'; +import {ResourceDatabase} from '../../src/schema/resource-database'; +import {describe, it, beforeEach, afterEach} from 'mocha'; import * as assert from 'assert'; describe('src/schema/resource-database.ts', () => { diff --git a/typescript/test/unit/retryable-code-map.ts b/typescript/test/unit/retryable-code-map.ts index 82f36f70d..105ef96f0 100644 --- a/typescript/test/unit/retryable-code-map.ts +++ b/typescript/test/unit/retryable-code-map.ts @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { RetryableCodeMap } from '../../src/schema/retryable-code-map'; +import {RetryableCodeMap} from '../../src/schema/retryable-code-map'; import * as plugin from '../../../pbjs-genfiles/plugin'; import * as assert from 'assert'; -import { describe, it } from 'mocha'; +import {describe, it} from 'mocha'; const Code = plugin.google.rpc.Code; @@ -126,8 +126,8 @@ describe('src/schema/retryable-code-map.ts', () => { it('generates the same name for the same set of options', () => { const map = new RetryableCodeMap(); - const name1 = map.getParamsName({ a: 10, b: 20 }); - const name2 = map.getParamsName({ b: 20.0, a: 10.0 }); + const name1 = map.getParamsName({a: 10, b: 20}); + const name2 = map.getParamsName({b: 20.0, a: 10.0}); assert.strictEqual(name1, name2); assert.notStrictEqual(name1, 'default'); assert.notStrictEqual(name2, 'default'); @@ -135,8 +135,8 @@ describe('src/schema/retryable-code-map.ts', () => { it('generates different names for different sets of parameters', () => { const map = new RetryableCodeMap(); - const name1 = map.getParamsName({ a: 1 }); - const name2 = map.getParamsName({ a: 2 }); + const name1 = map.getParamsName({a: 1}); + const name2 = map.getParamsName({a: 2}); assert.notStrictEqual(name1, name2); assert.notStrictEqual(name1, 'default'); assert.notStrictEqual(name2, 'default'); @@ -144,8 +144,8 @@ describe('src/schema/retryable-code-map.ts', () => { it('returns list of all names', () => { const map = new RetryableCodeMap(); - const name1 = map.getParamsName({ a: 1 }); - const name2 = map.getParamsName({ a: 2 }); + const name1 = map.getParamsName({a: 1}); + const name2 = map.getParamsName({a: 2}); const names = map.getPrettyParamsNames(); assert.strictEqual(names.length, 3); assert.notStrictEqual(name1, name2); @@ -158,13 +158,13 @@ describe('src/schema/retryable-code-map.ts', () => { it('allows to suggest a name', () => { const map = new RetryableCodeMap(); - const name = map.getParamsName({ a: 1 }, 'suggested_name'); + const name = map.getParamsName({a: 1}, 'suggested_name'); assert.strictEqual(name, 'suggested_name'); }); it('returns valid JSON object of parameters by name', () => { const map = new RetryableCodeMap(); - const param = { a: 1, b: 2 }; + const param = {a: 1, b: 2}; const name = map.getParamsName(param); const jsonString = map.getParamsJSON(name); const json = JSON.parse(jsonString); diff --git a/typescript/test/unit/util.ts b/typescript/test/unit/util.ts index 171ef54a0..c3df49014 100644 --- a/typescript/test/unit/util.ts +++ b/typescript/test/unit/util.ts @@ -13,8 +13,8 @@ // limitations under the License. import * as assert from 'assert'; -import { describe, it } from 'mocha'; -import { commonPrefix, duration, seconds, milliseconds } from '../../src/util'; +import {describe, it} from 'mocha'; +import {commonPrefix, duration, seconds, milliseconds} from '../../src/util'; import * as plugin from '../../../pbjs-genfiles/plugin'; describe('src/util.ts', () => { diff --git a/typescript/test/util.ts b/typescript/test/util.ts index 0ff2686b6..4ed8cfaf8 100644 --- a/typescript/test/util.ts +++ b/typescript/test/util.ts @@ -14,9 +14,9 @@ import * as fs from 'fs-extra'; import * as path from 'path'; -import { before, it } from 'mocha'; +import {before, it} from 'mocha'; import * as rimraf from 'rimraf'; -import { execSync } from 'child_process'; +import {execSync} from 'child_process'; import * as assert from 'assert'; const NO_OUTPUT_FILE = 0; @@ -89,7 +89,7 @@ export function runBaselineTest(options: BaselineOptions) { const bundleConfig = options.bundleConfig ? path.join(protosDirRoot, options.bundleConfig.split('/').join(path.sep)) : undefined; - it(options.baselineName, function() { + it(options.baselineName, function () { this.timeout(60000); if (fs.existsSync(outputDir)) { rimraf.sync(outputDir); diff --git a/typescript/tools/update-baselines.ts b/typescript/tools/update-baselines.ts index f1ba22da1..3fb42b90c 100644 --- a/typescript/tools/update-baselines.ts +++ b/typescript/tools/update-baselines.ts @@ -18,13 +18,13 @@ // needs to be propagated to all baselines. // Usage: node build/tools/update-baselines.js -import { exec } from 'child_process'; +import {exec} from 'child_process'; import * as util from 'util'; import * as fs from 'fs'; import * as path from 'path'; import * as rimraf from 'rimraf'; -import { promisify } from 'util'; -import { readdir, mkdir, existsSync } from 'fs'; +import {promisify} from 'util'; +import {readdir, mkdir, existsSync} from 'fs'; import * as ncp from 'ncp'; const rmrf = promisify(rimraf);