From 128f4af500588be73069858d1465e5ddd5c925aa Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Wed, 30 Oct 2019 22:59:55 -0700 Subject: [PATCH] fix: make generated test more TypeScript-y (#93) * fix: make test more typescripty * update circle * more circle --- .circleci/config.yml | 17 ++++++++++++++--- templates/typescript_gapic/package.json.njk | 1 + .../test/gapic-$service-$version.ts.njk | 11 +++++++---- .../testdata/keymanager/package.json.baseline | 1 + .../gapic-key_management_service-v1.ts.baseline | 9 ++++++--- .../testdata/showcase/package.json.baseline | 1 + .../test/gapic-echo-v1beta1.ts.baseline | 11 +++++++---- .../testdata/texttospeech/package.json.baseline | 1 + .../test/gapic-text_to_speech-v1.ts.baseline | 9 ++++++--- .../testdata/translate/package.json.baseline | 1 + ...apic-translation_service-v3beta1.ts.baseline | 9 ++++++--- 11 files changed, 51 insertions(+), 20 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 80224a400..c375c056b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -45,25 +45,36 @@ jobs: npm install npm test - run: - name: Run unit tests of the generated Showcase library + name: Run unit tests and gts fix of the generated Showcase library command: | cd .test-out-showcase npm install npm test + npm run fix - run: - name: Run unit tests of the generated KMS library + name: Run unit tests and gts fix of the generated KMS library command: | cp -r typescript/test/protos ./.test-out-keymanager cd .test-out-keymanager npm install npm test + npm run fix - run: - name: Run unit tests of the generated Text-to-Speech library + name: Run unit tests and gts fix of the generated Translate library + command: | + cp -r typescript/test/protos ./.test-out-translate + cd .test-out-translate + npm install + npm test + npm run fix + - run: + name: Run unit tests and gts fix of the generated Text-to-Speech library command: | cp -r typescript/test/protos ./.test-out-texttospeech cd .test-out-texttospeech npm install npm test + npm run fix - run: name: Run linting command: | diff --git a/templates/typescript_gapic/package.json.njk b/templates/typescript_gapic/package.json.njk index 09f1f5f17..a4b02f555 100644 --- a/templates/typescript_gapic/package.json.njk +++ b/templates/typescript_gapic/package.json.njk @@ -13,6 +13,7 @@ "google-gax": "^1.7.5" }, "devDependencies": { + "@types/node": "^12.0.0", "@types/mocha": "^5.2.5", "gts": "^0.9.0", "mocha": "^6.0.0", diff --git a/templates/typescript_gapic/test/gapic-$service-$version.ts.njk b/templates/typescript_gapic/test/gapic-$service-$version.ts.njk index 5de1f16b8..cf91bc034 100644 --- a/templates/typescript_gapic/test/gapic-$service-$version.ts.njk +++ b/templates/typescript_gapic/test/gapic-$service-$version.ts.njk @@ -1,24 +1,27 @@ {% import "../_license.njk" as license -%} {% import "../_util.njk" as util -%} {{license.license()}} -'use strict'; import * as protosTypes from '../protos/protos'; -const assert = require('assert'); +import * as assert from 'assert'; const {{ service.name.toLowerCase() }}Module = require('../src'); {% if (service.streaming.length > 0) %} -const {PassThrough} = require('stream'); +import {PassThrough} from 'stream'; {% endif %} const FAKE_STATUS_CODE = 1; class FakeError{ + name: string; + message: string; code: number; constructor(n: number){ + this.name = 'fakeName'; + this.message = 'fake message'; this.code = n; } } const error = new FakeError(FAKE_STATUS_CODE); export interface Callback { - (err: FakeError|null, response?: {} | null): {}; + (err: FakeError|null, response?: {} | null): void; } export class Operation{ diff --git a/typescript/test/testdata/keymanager/package.json.baseline b/typescript/test/testdata/keymanager/package.json.baseline index 7f4ff3296..31b1b661c 100644 --- a/typescript/test/testdata/keymanager/package.json.baseline +++ b/typescript/test/testdata/keymanager/package.json.baseline @@ -13,6 +13,7 @@ "google-gax": "^1.7.5" }, "devDependencies": { + "@types/node": "^12.0.0", "@types/mocha": "^5.2.5", "gts": "^0.9.0", "mocha": "^6.0.0", diff --git a/typescript/test/testdata/keymanager/test/gapic-key_management_service-v1.ts.baseline b/typescript/test/testdata/keymanager/test/gapic-key_management_service-v1.ts.baseline index 46299b643..1f51424e8 100644 --- a/typescript/test/testdata/keymanager/test/gapic-key_management_service-v1.ts.baseline +++ b/typescript/test/testdata/keymanager/test/gapic-key_management_service-v1.ts.baseline @@ -16,22 +16,25 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -'use strict'; import * as protosTypes from '../protos/protos'; -const assert = require('assert'); +import * as assert from 'assert'; const keymanagementserviceModule = require('../src'); const FAKE_STATUS_CODE = 1; class FakeError{ + name: string; + message: string; code: number; constructor(n: number){ + this.name = 'fakeName'; + this.message = 'fake message'; this.code = n; } } const error = new FakeError(FAKE_STATUS_CODE); export interface Callback { - (err: FakeError|null, response?: {} | null): {}; + (err: FakeError|null, response?: {} | null): void; } export class Operation{ diff --git a/typescript/test/testdata/showcase/package.json.baseline b/typescript/test/testdata/showcase/package.json.baseline index 4d4f3c1ad..a0ec01deb 100644 --- a/typescript/test/testdata/showcase/package.json.baseline +++ b/typescript/test/testdata/showcase/package.json.baseline @@ -13,6 +13,7 @@ "google-gax": "^1.7.5" }, "devDependencies": { + "@types/node": "^12.0.0", "@types/mocha": "^5.2.5", "gts": "^0.9.0", "mocha": "^6.0.0", diff --git a/typescript/test/testdata/showcase/test/gapic-echo-v1beta1.ts.baseline b/typescript/test/testdata/showcase/test/gapic-echo-v1beta1.ts.baseline index 704e42eb2..90e1a9d3e 100644 --- a/typescript/test/testdata/showcase/test/gapic-echo-v1beta1.ts.baseline +++ b/typescript/test/testdata/showcase/test/gapic-echo-v1beta1.ts.baseline @@ -16,24 +16,27 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -'use strict'; import * as protosTypes from '../protos/protos'; -const assert = require('assert'); +import * as assert from 'assert'; const echoModule = require('../src'); -const {PassThrough} = require('stream'); +import {PassThrough} from 'stream'; const FAKE_STATUS_CODE = 1; class FakeError{ + name: string; + message: string; code: number; constructor(n: number){ + this.name = 'fakeName'; + this.message = 'fake message'; this.code = n; } } const error = new FakeError(FAKE_STATUS_CODE); export interface Callback { - (err: FakeError|null, response?: {} | null): {}; + (err: FakeError|null, response?: {} | null): void; } export class Operation{ diff --git a/typescript/test/testdata/texttospeech/package.json.baseline b/typescript/test/testdata/texttospeech/package.json.baseline index f472103bd..3e81b973d 100644 --- a/typescript/test/testdata/texttospeech/package.json.baseline +++ b/typescript/test/testdata/texttospeech/package.json.baseline @@ -13,6 +13,7 @@ "google-gax": "^1.7.5" }, "devDependencies": { + "@types/node": "^12.0.0", "@types/mocha": "^5.2.5", "gts": "^0.9.0", "mocha": "^6.0.0", diff --git a/typescript/test/testdata/texttospeech/test/gapic-text_to_speech-v1.ts.baseline b/typescript/test/testdata/texttospeech/test/gapic-text_to_speech-v1.ts.baseline index bcf655cf1..622773d20 100644 --- a/typescript/test/testdata/texttospeech/test/gapic-text_to_speech-v1.ts.baseline +++ b/typescript/test/testdata/texttospeech/test/gapic-text_to_speech-v1.ts.baseline @@ -16,22 +16,25 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -'use strict'; import * as protosTypes from '../protos/protos'; -const assert = require('assert'); +import * as assert from 'assert'; const texttospeechModule = require('../src'); const FAKE_STATUS_CODE = 1; class FakeError{ + name: string; + message: string; code: number; constructor(n: number){ + this.name = 'fakeName'; + this.message = 'fake message'; this.code = n; } } const error = new FakeError(FAKE_STATUS_CODE); export interface Callback { - (err: FakeError|null, response?: {} | null): {}; + (err: FakeError|null, response?: {} | null): void; } export class Operation{ diff --git a/typescript/test/testdata/translate/package.json.baseline b/typescript/test/testdata/translate/package.json.baseline index 9b16c43d2..c1f43321a 100644 --- a/typescript/test/testdata/translate/package.json.baseline +++ b/typescript/test/testdata/translate/package.json.baseline @@ -13,6 +13,7 @@ "google-gax": "^1.7.5" }, "devDependencies": { + "@types/node": "^12.0.0", "@types/mocha": "^5.2.5", "gts": "^0.9.0", "mocha": "^6.0.0", diff --git a/typescript/test/testdata/translate/test/gapic-translation_service-v3beta1.ts.baseline b/typescript/test/testdata/translate/test/gapic-translation_service-v3beta1.ts.baseline index 23c4ec05f..33d9175d9 100644 --- a/typescript/test/testdata/translate/test/gapic-translation_service-v3beta1.ts.baseline +++ b/typescript/test/testdata/translate/test/gapic-translation_service-v3beta1.ts.baseline @@ -16,22 +16,25 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -'use strict'; import * as protosTypes from '../protos/protos'; -const assert = require('assert'); +import * as assert from 'assert'; const translationserviceModule = require('../src'); const FAKE_STATUS_CODE = 1; class FakeError{ + name: string; + message: string; code: number; constructor(n: number){ + this.name = 'fakeName'; + this.message = 'fake message'; this.code = n; } } const error = new FakeError(FAKE_STATUS_CODE); export interface Callback { - (err: FakeError|null, response?: {} | null): {}; + (err: FakeError|null, response?: {} | null): void; } export class Operation{