From 36d3fef63bd27b20c6270aed5ae7fed3bcedaa54 Mon Sep 17 00:00:00 2001 From: xiaozhenliugg Date: Tue, 12 Nov 2019 16:57:03 -0800 Subject: [PATCH 1/4] pack-n-play setup --- templates/typescript_gapic/package.json.njk | 1 + .../fixtures/sample/package.json.njk | 40 --------------- .../fixtures/sample/tsconfig.json.njk | 29 ----------- .../system-test/install.ts.njk | 49 ++++++------------- .../testdata/keymanager/package.json.baseline | 1 + .../fixtures/sample/package.json.baseline | 23 --------- .../fixtures/sample/tsconfig.json.baseline | 14 ------ .../system-test/install.ts.baseline | 45 +++++------------ .../testdata/showcase/package.json.baseline | 1 + .../fixtures/sample/package.json.baseline | 23 --------- .../fixtures/sample/tsconfig.json.baseline | 14 ------ .../showcase/system-test/install.ts.baseline | 45 +++++------------ .../texttospeech/package.json.baseline | 1 + .../fixtures/sample/package.json.baseline | 23 --------- .../fixtures/sample/tsconfig.json.baseline | 14 ------ .../system-test/install.ts.baseline | 45 +++++------------ .../testdata/translate/package.json.baseline | 1 + .../fixtures/sample/package.json.baseline | 23 --------- .../fixtures/sample/tsconfig.json.baseline | 14 ------ .../translate/system-test/install.ts.baseline | 45 +++++------------ 20 files changed, 72 insertions(+), 379 deletions(-) delete mode 100644 templates/typescript_gapic/system-test/fixtures/sample/package.json.njk delete mode 100644 templates/typescript_gapic/system-test/fixtures/sample/tsconfig.json.njk delete mode 100644 typescript/test/testdata/keymanager/system-test/fixtures/sample/package.json.baseline delete mode 100644 typescript/test/testdata/keymanager/system-test/fixtures/sample/tsconfig.json.baseline delete mode 100644 typescript/test/testdata/showcase/system-test/fixtures/sample/package.json.baseline delete mode 100644 typescript/test/testdata/showcase/system-test/fixtures/sample/tsconfig.json.baseline delete mode 100644 typescript/test/testdata/texttospeech/system-test/fixtures/sample/package.json.baseline delete mode 100644 typescript/test/testdata/texttospeech/system-test/fixtures/sample/tsconfig.json.baseline delete mode 100644 typescript/test/testdata/translate/system-test/fixtures/sample/package.json.baseline delete mode 100644 typescript/test/testdata/translate/system-test/fixtures/sample/tsconfig.json.baseline diff --git a/templates/typescript_gapic/package.json.njk b/templates/typescript_gapic/package.json.njk index b9d87bfbe..6031e5970 100644 --- a/templates/typescript_gapic/package.json.njk +++ b/templates/typescript_gapic/package.json.njk @@ -57,6 +57,7 @@ limitations under the License. "mocha": "^6.0.0", "mv": "^2.1.1", "ncp": "^2.0.0", + "pack-n-play": "^1.0.0-2", "tmp": "^0.1.0", "typescript": "^3.7.0" }, diff --git a/templates/typescript_gapic/system-test/fixtures/sample/package.json.njk b/templates/typescript_gapic/system-test/fixtures/sample/package.json.njk deleted file mode 100644 index 255a2320c..000000000 --- a/templates/typescript_gapic/system-test/fixtures/sample/package.json.njk +++ /dev/null @@ -1,40 +0,0 @@ -{#- - -Copyright 2019 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. - --#} -{ - "name": "{{ api.naming.productName.toKebabCase() }}-sample-fixture", - "description": "An app we're using to test the {{ api.naming.productName }} library.", - "scripts": { - "check": "gts check", - "clean": "gts clean", - "compile": "tsc -p .", - "fix": "gts fix", - "prepare": "npm run compile", - "pretest": "npm run compile", - "posttest": "npm run check", - "start": "node build/src/index.js" - }, - "license": "Apache-2.0", - "dependencies": { - "{{ api.naming.productName.toKebabCase() }}": "file:./{{ api.naming.productName.toKebabCase() }}.tgz" - }, - "devDependencies": { - "@types/node": "^12.0.0", - "typescript": "^3.0.0", - "gts": "^1.0.0" - } -} diff --git a/templates/typescript_gapic/system-test/fixtures/sample/tsconfig.json.njk b/templates/typescript_gapic/system-test/fixtures/sample/tsconfig.json.njk deleted file mode 100644 index 7c8bc7157..000000000 --- a/templates/typescript_gapic/system-test/fixtures/sample/tsconfig.json.njk +++ /dev/null @@ -1,29 +0,0 @@ -{#- - -Copyright 2019 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. - --#} -{ - "extends": "./node_modules/gts/tsconfig-google.json", - "compilerOptions": { - "rootDir": ".", - "outDir": "build", - "types": ["node"], - "skipLibCheck": false - }, - "include": [ - "src/*.ts" - ] -} diff --git a/templates/typescript_gapic/system-test/install.ts.njk b/templates/typescript_gapic/system-test/install.ts.njk index 0e7aec78b..20cc42c90 100644 --- a/templates/typescript_gapic/system-test/install.ts.njk +++ b/templates/typescript_gapic/system-test/install.ts.njk @@ -17,40 +17,21 @@ limitations under the License. -#} {% import "../_license.njk" as license -%} {{license.license()}} -import * as execa from 'execa'; -import * as mv from 'mv'; -import {ncp} from 'ncp'; -import * as tmp from 'tmp'; -import {promisify} from 'util'; - -const keep = false; -const mvp = promisify(mv); -const ncpp = promisify(ncp); -const stagingDir = tmp.dirSync({keep, unsafeCleanup: true}); -const stagingPath = stagingDir.name; -const pkg = require('../../package.json'); - -describe('📦 pack and install', () => { - it('should be able use the library from a TypeScript application', async function() { +import {packNTest} from 'pack-n-play'; +import { readFileSync } from 'fs'; + +describe('typescript consumer tests', () => { + + it('should have correct type signature for {{ api.naming.name }} client library', async function() { this.timeout(300000); - await execa('npm', ['pack', '--unsafe-perm']); - const packageName = pkg.name.replace('@', '').replace('/', '-'); - const tarball = `${packageName}-${pkg.version}.tgz`; - await mvp(tarball, `${stagingPath}/{{ api.naming.productName.toKebabCase() }}.tgz`); - await ncpp('system-test/fixtures/sample', `${stagingPath}/`); - await execa('npm', ['install', '--unsafe-perm'], { - cwd: `${stagingPath}/`, - stdio: 'inherit', - }); - await execa('node', ['--throw-deprecation', 'build/src/index.js'], { - cwd: `${stagingPath}/`, - stdio: 'inherit', - }); + const options = { + packageDir: process.cwd(), // path to your module. + sample: { + description: 'typescript based used can use my type definitions', + ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() + } + }; + await packNTest(options); // will throw upon error. }); - after('cleanup staging', () => { - if (!keep) { - stagingDir.removeCallback(); - } - }); -}); +}); \ No newline at end of file diff --git a/typescript/test/testdata/keymanager/package.json.baseline b/typescript/test/testdata/keymanager/package.json.baseline index c1853e9df..38c71a561 100644 --- a/typescript/test/testdata/keymanager/package.json.baseline +++ b/typescript/test/testdata/keymanager/package.json.baseline @@ -40,6 +40,7 @@ "mocha": "^6.0.0", "mv": "^2.1.1", "ncp": "^2.0.0", + "pack-n-play": "^1.0.0-2", "tmp": "^0.1.0", "typescript": "^3.7.0" }, diff --git a/typescript/test/testdata/keymanager/system-test/fixtures/sample/package.json.baseline b/typescript/test/testdata/keymanager/system-test/fixtures/sample/package.json.baseline deleted file mode 100644 index 4a4e1febb..000000000 --- a/typescript/test/testdata/keymanager/system-test/fixtures/sample/package.json.baseline +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "kms-sample-fixture", - "description": "An app we're using to test the Kms library.", - "scripts": { - "check": "gts check", - "clean": "gts clean", - "compile": "tsc -p .", - "fix": "gts fix", - "prepare": "npm run compile", - "pretest": "npm run compile", - "posttest": "npm run check", - "start": "node build/src/index.js" - }, - "license": "Apache-2.0", - "dependencies": { - "kms": "file:./kms.tgz" - }, - "devDependencies": { - "@types/node": "^12.0.0", - "typescript": "^3.0.0", - "gts": "^1.0.0" - } -} diff --git a/typescript/test/testdata/keymanager/system-test/fixtures/sample/tsconfig.json.baseline b/typescript/test/testdata/keymanager/system-test/fixtures/sample/tsconfig.json.baseline deleted file mode 100644 index e5f760d87..000000000 --- a/typescript/test/testdata/keymanager/system-test/fixtures/sample/tsconfig.json.baseline +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "./node_modules/gts/tsconfig-google.json", - "compilerOptions": { - "rootDir": ".", - "outDir": "build", - "types": [ - "node" - ], - "skipLibCheck": false - }, - "include": [ - "src/*.ts" - ] -} diff --git a/typescript/test/testdata/keymanager/system-test/install.ts.baseline b/typescript/test/testdata/keymanager/system-test/install.ts.baseline index 2aabe52d9..1380a84b7 100644 --- a/typescript/test/testdata/keymanager/system-test/install.ts.baseline +++ b/typescript/test/testdata/keymanager/system-test/install.ts.baseline @@ -16,40 +16,21 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -import * as execa from 'execa'; -import * as mv from 'mv'; -import {ncp} from 'ncp'; -import * as tmp from 'tmp'; -import {promisify} from 'util'; +import {packNTest} from 'pack-n-play'; +import { readFileSync } from 'fs'; -const keep = false; -const mvp = promisify(mv); -const ncpp = promisify(ncp); -const stagingDir = tmp.dirSync({keep, unsafeCleanup: true}); -const stagingPath = stagingDir.name; -const pkg = require('../../package.json'); +describe('typescript consumer tests', () => { -describe('📦 pack and install', () => { - it('should be able use the library from a TypeScript application', async function() { + it('should have correct type signature for Kms client library', async function() { this.timeout(300000); - await execa('npm', ['pack', '--unsafe-perm']); - const packageName = pkg.name.replace('@', '').replace('/', '-'); - const tarball = `${packageName}-${pkg.version}.tgz`; - await mvp(tarball, `${stagingPath}/kms.tgz`); - await ncpp('system-test/fixtures/sample', `${stagingPath}/`); - await execa('npm', ['install', '--unsafe-perm'], { - cwd: `${stagingPath}/`, - stdio: 'inherit', - }); - await execa('node', ['--throw-deprecation', 'build/src/index.js'], { - cwd: `${stagingPath}/`, - stdio: 'inherit', - }); + const options = { + packageDir: process.cwd(), // path to your module. + sample: { + description: 'typescript based used can use my type definitions', + ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() + } + }; + await packNTest(options); // will throw upon error. }); - after('cleanup staging', () => { - if (!keep) { - stagingDir.removeCallback(); - } - }); -}); +}); \ No newline at end of file diff --git a/typescript/test/testdata/showcase/package.json.baseline b/typescript/test/testdata/showcase/package.json.baseline index 83ccb08c0..db7c6d677 100644 --- a/typescript/test/testdata/showcase/package.json.baseline +++ b/typescript/test/testdata/showcase/package.json.baseline @@ -40,6 +40,7 @@ "mocha": "^6.0.0", "mv": "^2.1.1", "ncp": "^2.0.0", + "pack-n-play": "^1.0.0-2", "tmp": "^0.1.0", "typescript": "^3.7.0" }, diff --git a/typescript/test/testdata/showcase/system-test/fixtures/sample/package.json.baseline b/typescript/test/testdata/showcase/system-test/fixtures/sample/package.json.baseline deleted file mode 100644 index e4325fb93..000000000 --- a/typescript/test/testdata/showcase/system-test/fixtures/sample/package.json.baseline +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "showcase-sample-fixture", - "description": "An app we're using to test the Showcase library.", - "scripts": { - "check": "gts check", - "clean": "gts clean", - "compile": "tsc -p .", - "fix": "gts fix", - "prepare": "npm run compile", - "pretest": "npm run compile", - "posttest": "npm run check", - "start": "node build/src/index.js" - }, - "license": "Apache-2.0", - "dependencies": { - "showcase": "file:./showcase.tgz" - }, - "devDependencies": { - "@types/node": "^12.0.0", - "typescript": "^3.0.0", - "gts": "^1.0.0" - } -} diff --git a/typescript/test/testdata/showcase/system-test/fixtures/sample/tsconfig.json.baseline b/typescript/test/testdata/showcase/system-test/fixtures/sample/tsconfig.json.baseline deleted file mode 100644 index e5f760d87..000000000 --- a/typescript/test/testdata/showcase/system-test/fixtures/sample/tsconfig.json.baseline +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "./node_modules/gts/tsconfig-google.json", - "compilerOptions": { - "rootDir": ".", - "outDir": "build", - "types": [ - "node" - ], - "skipLibCheck": false - }, - "include": [ - "src/*.ts" - ] -} diff --git a/typescript/test/testdata/showcase/system-test/install.ts.baseline b/typescript/test/testdata/showcase/system-test/install.ts.baseline index d063d561b..74c0db99b 100644 --- a/typescript/test/testdata/showcase/system-test/install.ts.baseline +++ b/typescript/test/testdata/showcase/system-test/install.ts.baseline @@ -16,40 +16,21 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -import * as execa from 'execa'; -import * as mv from 'mv'; -import {ncp} from 'ncp'; -import * as tmp from 'tmp'; -import {promisify} from 'util'; +import {packNTest} from 'pack-n-play'; +import { readFileSync } from 'fs'; -const keep = false; -const mvp = promisify(mv); -const ncpp = promisify(ncp); -const stagingDir = tmp.dirSync({keep, unsafeCleanup: true}); -const stagingPath = stagingDir.name; -const pkg = require('../../package.json'); +describe('typescript consumer tests', () => { -describe('📦 pack and install', () => { - it('should be able use the library from a TypeScript application', async function() { + it('should have correct type signature for Showcase client library', async function() { this.timeout(300000); - await execa('npm', ['pack', '--unsafe-perm']); - const packageName = pkg.name.replace('@', '').replace('/', '-'); - const tarball = `${packageName}-${pkg.version}.tgz`; - await mvp(tarball, `${stagingPath}/showcase.tgz`); - await ncpp('system-test/fixtures/sample', `${stagingPath}/`); - await execa('npm', ['install', '--unsafe-perm'], { - cwd: `${stagingPath}/`, - stdio: 'inherit', - }); - await execa('node', ['--throw-deprecation', 'build/src/index.js'], { - cwd: `${stagingPath}/`, - stdio: 'inherit', - }); + const options = { + packageDir: process.cwd(), // path to your module. + sample: { + description: 'typescript based used can use my type definitions', + ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() + } + }; + await packNTest(options); // will throw upon error. }); - after('cleanup staging', () => { - if (!keep) { - stagingDir.removeCallback(); - } - }); -}); +}); \ No newline at end of file diff --git a/typescript/test/testdata/texttospeech/package.json.baseline b/typescript/test/testdata/texttospeech/package.json.baseline index 9ab588f6c..5838b55a1 100644 --- a/typescript/test/testdata/texttospeech/package.json.baseline +++ b/typescript/test/testdata/texttospeech/package.json.baseline @@ -40,6 +40,7 @@ "mocha": "^6.0.0", "mv": "^2.1.1", "ncp": "^2.0.0", + "pack-n-play": "^1.0.0-2", "tmp": "^0.1.0", "typescript": "^3.7.0" }, diff --git a/typescript/test/testdata/texttospeech/system-test/fixtures/sample/package.json.baseline b/typescript/test/testdata/texttospeech/system-test/fixtures/sample/package.json.baseline deleted file mode 100644 index 71b238658..000000000 --- a/typescript/test/testdata/texttospeech/system-test/fixtures/sample/package.json.baseline +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "texttospeech-sample-fixture", - "description": "An app we're using to test the Texttospeech library.", - "scripts": { - "check": "gts check", - "clean": "gts clean", - "compile": "tsc -p .", - "fix": "gts fix", - "prepare": "npm run compile", - "pretest": "npm run compile", - "posttest": "npm run check", - "start": "node build/src/index.js" - }, - "license": "Apache-2.0", - "dependencies": { - "texttospeech": "file:./texttospeech.tgz" - }, - "devDependencies": { - "@types/node": "^12.0.0", - "typescript": "^3.0.0", - "gts": "^1.0.0" - } -} diff --git a/typescript/test/testdata/texttospeech/system-test/fixtures/sample/tsconfig.json.baseline b/typescript/test/testdata/texttospeech/system-test/fixtures/sample/tsconfig.json.baseline deleted file mode 100644 index e5f760d87..000000000 --- a/typescript/test/testdata/texttospeech/system-test/fixtures/sample/tsconfig.json.baseline +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "./node_modules/gts/tsconfig-google.json", - "compilerOptions": { - "rootDir": ".", - "outDir": "build", - "types": [ - "node" - ], - "skipLibCheck": false - }, - "include": [ - "src/*.ts" - ] -} diff --git a/typescript/test/testdata/texttospeech/system-test/install.ts.baseline b/typescript/test/testdata/texttospeech/system-test/install.ts.baseline index d826a9473..18fc05b94 100644 --- a/typescript/test/testdata/texttospeech/system-test/install.ts.baseline +++ b/typescript/test/testdata/texttospeech/system-test/install.ts.baseline @@ -16,40 +16,21 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -import * as execa from 'execa'; -import * as mv from 'mv'; -import {ncp} from 'ncp'; -import * as tmp from 'tmp'; -import {promisify} from 'util'; +import {packNTest} from 'pack-n-play'; +import { readFileSync } from 'fs'; -const keep = false; -const mvp = promisify(mv); -const ncpp = promisify(ncp); -const stagingDir = tmp.dirSync({keep, unsafeCleanup: true}); -const stagingPath = stagingDir.name; -const pkg = require('../../package.json'); +describe('typescript consumer tests', () => { -describe('📦 pack and install', () => { - it('should be able use the library from a TypeScript application', async function() { + it('should have correct type signature for Texttospeech client library', async function() { this.timeout(300000); - await execa('npm', ['pack', '--unsafe-perm']); - const packageName = pkg.name.replace('@', '').replace('/', '-'); - const tarball = `${packageName}-${pkg.version}.tgz`; - await mvp(tarball, `${stagingPath}/texttospeech.tgz`); - await ncpp('system-test/fixtures/sample', `${stagingPath}/`); - await execa('npm', ['install', '--unsafe-perm'], { - cwd: `${stagingPath}/`, - stdio: 'inherit', - }); - await execa('node', ['--throw-deprecation', 'build/src/index.js'], { - cwd: `${stagingPath}/`, - stdio: 'inherit', - }); + const options = { + packageDir: process.cwd(), // path to your module. + sample: { + description: 'typescript based used can use my type definitions', + ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() + } + }; + await packNTest(options); // will throw upon error. }); - after('cleanup staging', () => { - if (!keep) { - stagingDir.removeCallback(); - } - }); -}); +}); \ No newline at end of file diff --git a/typescript/test/testdata/translate/package.json.baseline b/typescript/test/testdata/translate/package.json.baseline index 0340609d2..2691d9b8a 100644 --- a/typescript/test/testdata/translate/package.json.baseline +++ b/typescript/test/testdata/translate/package.json.baseline @@ -40,6 +40,7 @@ "mocha": "^6.0.0", "mv": "^2.1.1", "ncp": "^2.0.0", + "pack-n-play": "^1.0.0-2", "tmp": "^0.1.0", "typescript": "^3.7.0" }, diff --git a/typescript/test/testdata/translate/system-test/fixtures/sample/package.json.baseline b/typescript/test/testdata/translate/system-test/fixtures/sample/package.json.baseline deleted file mode 100644 index f4c9f96d7..000000000 --- a/typescript/test/testdata/translate/system-test/fixtures/sample/package.json.baseline +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "translation-sample-fixture", - "description": "An app we're using to test the Translation library.", - "scripts": { - "check": "gts check", - "clean": "gts clean", - "compile": "tsc -p .", - "fix": "gts fix", - "prepare": "npm run compile", - "pretest": "npm run compile", - "posttest": "npm run check", - "start": "node build/src/index.js" - }, - "license": "Apache-2.0", - "dependencies": { - "translation": "file:./translation.tgz" - }, - "devDependencies": { - "@types/node": "^12.0.0", - "typescript": "^3.0.0", - "gts": "^1.0.0" - } -} diff --git a/typescript/test/testdata/translate/system-test/fixtures/sample/tsconfig.json.baseline b/typescript/test/testdata/translate/system-test/fixtures/sample/tsconfig.json.baseline deleted file mode 100644 index e5f760d87..000000000 --- a/typescript/test/testdata/translate/system-test/fixtures/sample/tsconfig.json.baseline +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "./node_modules/gts/tsconfig-google.json", - "compilerOptions": { - "rootDir": ".", - "outDir": "build", - "types": [ - "node" - ], - "skipLibCheck": false - }, - "include": [ - "src/*.ts" - ] -} diff --git a/typescript/test/testdata/translate/system-test/install.ts.baseline b/typescript/test/testdata/translate/system-test/install.ts.baseline index bb31db672..a631f0e3a 100644 --- a/typescript/test/testdata/translate/system-test/install.ts.baseline +++ b/typescript/test/testdata/translate/system-test/install.ts.baseline @@ -16,40 +16,21 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -import * as execa from 'execa'; -import * as mv from 'mv'; -import {ncp} from 'ncp'; -import * as tmp from 'tmp'; -import {promisify} from 'util'; +import {packNTest} from 'pack-n-play'; +import { readFileSync } from 'fs'; -const keep = false; -const mvp = promisify(mv); -const ncpp = promisify(ncp); -const stagingDir = tmp.dirSync({keep, unsafeCleanup: true}); -const stagingPath = stagingDir.name; -const pkg = require('../../package.json'); +describe('typescript consumer tests', () => { -describe('📦 pack and install', () => { - it('should be able use the library from a TypeScript application', async function() { + it('should have correct type signature for Translation client library', async function() { this.timeout(300000); - await execa('npm', ['pack', '--unsafe-perm']); - const packageName = pkg.name.replace('@', '').replace('/', '-'); - const tarball = `${packageName}-${pkg.version}.tgz`; - await mvp(tarball, `${stagingPath}/translation.tgz`); - await ncpp('system-test/fixtures/sample', `${stagingPath}/`); - await execa('npm', ['install', '--unsafe-perm'], { - cwd: `${stagingPath}/`, - stdio: 'inherit', - }); - await execa('node', ['--throw-deprecation', 'build/src/index.js'], { - cwd: `${stagingPath}/`, - stdio: 'inherit', - }); + const options = { + packageDir: process.cwd(), // path to your module. + sample: { + description: 'typescript based used can use my type definitions', + ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() + } + }; + await packNTest(options); // will throw upon error. }); - after('cleanup staging', () => { - if (!keep) { - stagingDir.removeCallback(); - } - }); -}); +}); \ No newline at end of file From e47c9b981cc59f57f978462a709d625e8afd850f Mon Sep 17 00:00:00 2001 From: xiaozhenliugg Date: Wed, 13 Nov 2019 09:47:43 -0800 Subject: [PATCH 2/4] feedback --- templates/typescript_gapic/system-test/install.ts.njk | 4 ++-- .../test/testdata/keymanager/system-test/install.ts.baseline | 4 ++-- .../test/testdata/showcase/system-test/install.ts.baseline | 4 ++-- .../testdata/texttospeech/system-test/install.ts.baseline | 4 ++-- .../test/testdata/translate/system-test/install.ts.baseline | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/templates/typescript_gapic/system-test/install.ts.njk b/templates/typescript_gapic/system-test/install.ts.njk index 20cc42c90..ceb6788c1 100644 --- a/templates/typescript_gapic/system-test/install.ts.njk +++ b/templates/typescript_gapic/system-test/install.ts.njk @@ -27,11 +27,11 @@ describe('typescript consumer tests', () => { const options = { packageDir: process.cwd(), // path to your module. sample: { - description: 'typescript based used can use my type definitions', + description: 'typescript based user can use the type definitions', ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() } }; await packNTest(options); // will throw upon error. }); -}); \ No newline at end of file +}); diff --git a/typescript/test/testdata/keymanager/system-test/install.ts.baseline b/typescript/test/testdata/keymanager/system-test/install.ts.baseline index 1380a84b7..bde8125a9 100644 --- a/typescript/test/testdata/keymanager/system-test/install.ts.baseline +++ b/typescript/test/testdata/keymanager/system-test/install.ts.baseline @@ -26,11 +26,11 @@ describe('typescript consumer tests', () => { const options = { packageDir: process.cwd(), // path to your module. sample: { - description: 'typescript based used can use my type definitions', + description: 'typescript based user can use the type definitions', ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() } }; await packNTest(options); // will throw upon error. }); -}); \ No newline at end of file +}); diff --git a/typescript/test/testdata/showcase/system-test/install.ts.baseline b/typescript/test/testdata/showcase/system-test/install.ts.baseline index 74c0db99b..7a6cfe78d 100644 --- a/typescript/test/testdata/showcase/system-test/install.ts.baseline +++ b/typescript/test/testdata/showcase/system-test/install.ts.baseline @@ -26,11 +26,11 @@ describe('typescript consumer tests', () => { const options = { packageDir: process.cwd(), // path to your module. sample: { - description: 'typescript based used can use my type definitions', + description: 'typescript based user can use the type definitions', ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() } }; await packNTest(options); // will throw upon error. }); -}); \ No newline at end of file +}); diff --git a/typescript/test/testdata/texttospeech/system-test/install.ts.baseline b/typescript/test/testdata/texttospeech/system-test/install.ts.baseline index 18fc05b94..a7fd2fc3e 100644 --- a/typescript/test/testdata/texttospeech/system-test/install.ts.baseline +++ b/typescript/test/testdata/texttospeech/system-test/install.ts.baseline @@ -26,11 +26,11 @@ describe('typescript consumer tests', () => { const options = { packageDir: process.cwd(), // path to your module. sample: { - description: 'typescript based used can use my type definitions', + description: 'typescript based user can use the type definitions', ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() } }; await packNTest(options); // will throw upon error. }); -}); \ No newline at end of file +}); diff --git a/typescript/test/testdata/translate/system-test/install.ts.baseline b/typescript/test/testdata/translate/system-test/install.ts.baseline index a631f0e3a..78708aaec 100644 --- a/typescript/test/testdata/translate/system-test/install.ts.baseline +++ b/typescript/test/testdata/translate/system-test/install.ts.baseline @@ -26,11 +26,11 @@ describe('typescript consumer tests', () => { const options = { packageDir: process.cwd(), // path to your module. sample: { - description: 'typescript based used can use my type definitions', + description: 'typescript based user can use the type definitions', ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() } }; await packNTest(options); // will throw upon error. }); -}); \ No newline at end of file +}); From adb78eb3472174c6e77f0e2e5507f3ba0cc9407d Mon Sep 17 00:00:00 2001 From: xiaozhenliugg Date: Wed, 13 Nov 2019 10:01:54 -0800 Subject: [PATCH 3/4] system-test for js users --- .../fixtures/sample/src/index.js.njk | 31 +++++++++++++++++++ .../system-test/install.ts.njk | 14 ++++++++- .../fixtures/sample/src/index.js.baseline | 26 ++++++++++++++++ .../system-test/install.ts.baseline | 14 ++++++++- .../fixtures/sample/src/index.js.baseline | 26 ++++++++++++++++ .../showcase/system-test/install.ts.baseline | 14 ++++++++- .../fixtures/sample/src/index.js.baseline | 26 ++++++++++++++++ .../system-test/install.ts.baseline | 14 ++++++++- .../fixtures/sample/src/index.js.baseline | 26 ++++++++++++++++ .../translate/system-test/install.ts.baseline | 14 ++++++++- 10 files changed, 200 insertions(+), 5 deletions(-) create mode 100644 templates/typescript_gapic/system-test/fixtures/sample/src/index.js.njk create mode 100644 typescript/test/testdata/keymanager/system-test/fixtures/sample/src/index.js.baseline create mode 100644 typescript/test/testdata/showcase/system-test/fixtures/sample/src/index.js.baseline create mode 100644 typescript/test/testdata/texttospeech/system-test/fixtures/sample/src/index.js.baseline create mode 100644 typescript/test/testdata/translate/system-test/fixtures/sample/src/index.js.baseline diff --git a/templates/typescript_gapic/system-test/fixtures/sample/src/index.js.njk b/templates/typescript_gapic/system-test/fixtures/sample/src/index.js.njk new file mode 100644 index 000000000..4a2a26cfa --- /dev/null +++ b/templates/typescript_gapic/system-test/fixtures/sample/src/index.js.njk @@ -0,0 +1,31 @@ +{#- + +Copyright 2019 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. + +-#} +{% import "../../../../_license.njk" as license -%} +{{license.license()}} +{%- for service in api.services %} +import { {{- service.name.toPascalCase() + 'Client' -}} } from '{{ api.naming.productName.toKebabCase() }}'; +{%- endfor %} + +function main() { +{%- for service in api.services %} + const {{ service.name.toCamelCase() -}}Client = new {{ service.name.toPascalCase() + 'Client' -}}(); + console.log("{{- service.name.toCamelCase() -}}Client was created!"); +{%- endfor %} +} + +main(); diff --git a/templates/typescript_gapic/system-test/install.ts.njk b/templates/typescript_gapic/system-test/install.ts.njk index ceb6788c1..d474741ba 100644 --- a/templates/typescript_gapic/system-test/install.ts.njk +++ b/templates/typescript_gapic/system-test/install.ts.njk @@ -22,7 +22,7 @@ import { readFileSync } from 'fs'; describe('typescript consumer tests', () => { - it('should have correct type signature for {{ api.naming.name }} client library', async function() { + it('should have correct type signature for typescript users', async function() { this.timeout(300000); const options = { packageDir: process.cwd(), // path to your module. @@ -34,4 +34,16 @@ describe('typescript consumer tests', () => { await packNTest(options); // will throw upon error. }); + it('should have correct type signature for javascript users', async function() { + this.timeout(300000); + const options = { + packageDir: process.cwd(), // path to your module. + sample: { + description: 'typescript based user can use the type definitions', + ts: readFileSync('./system-test/fixtures/sample/src/index.js').toString() + } + }; + await packNTest(options); // will throw upon error. + }); + }); diff --git a/typescript/test/testdata/keymanager/system-test/fixtures/sample/src/index.js.baseline b/typescript/test/testdata/keymanager/system-test/fixtures/sample/src/index.js.baseline new file mode 100644 index 000000000..310e4c51e --- /dev/null +++ b/typescript/test/testdata/keymanager/system-test/fixtures/sample/src/index.js.baseline @@ -0,0 +1,26 @@ +// Copyright 2019 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 +// +// https://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. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import {KeyManagementServiceClient} from 'kms'; + +function main() { + const keyManagementServiceClient = new KeyManagementServiceClient(); + console.log("keyManagementServiceClient was created!"); +} + +main(); diff --git a/typescript/test/testdata/keymanager/system-test/install.ts.baseline b/typescript/test/testdata/keymanager/system-test/install.ts.baseline index bde8125a9..faa7e02aa 100644 --- a/typescript/test/testdata/keymanager/system-test/install.ts.baseline +++ b/typescript/test/testdata/keymanager/system-test/install.ts.baseline @@ -21,7 +21,7 @@ import { readFileSync } from 'fs'; describe('typescript consumer tests', () => { - it('should have correct type signature for Kms client library', async function() { + it('should have correct type signature for typescript users', async function() { this.timeout(300000); const options = { packageDir: process.cwd(), // path to your module. @@ -33,4 +33,16 @@ describe('typescript consumer tests', () => { await packNTest(options); // will throw upon error. }); + it('should have correct type signature for javascript users', async function() { + this.timeout(300000); + const options = { + packageDir: process.cwd(), // path to your module. + sample: { + description: 'typescript based user can use the type definitions', + ts: readFileSync('./system-test/fixtures/sample/src/index.js').toString() + } + }; + await packNTest(options); // will throw upon error. + }); + }); diff --git a/typescript/test/testdata/showcase/system-test/fixtures/sample/src/index.js.baseline b/typescript/test/testdata/showcase/system-test/fixtures/sample/src/index.js.baseline new file mode 100644 index 000000000..dca99e9fb --- /dev/null +++ b/typescript/test/testdata/showcase/system-test/fixtures/sample/src/index.js.baseline @@ -0,0 +1,26 @@ +// Copyright 2019 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 +// +// https://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. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import {EchoClient} from 'showcase'; + +function main() { + const echoClient = new EchoClient(); + console.log("echoClient was created!"); +} + +main(); diff --git a/typescript/test/testdata/showcase/system-test/install.ts.baseline b/typescript/test/testdata/showcase/system-test/install.ts.baseline index 7a6cfe78d..faa7e02aa 100644 --- a/typescript/test/testdata/showcase/system-test/install.ts.baseline +++ b/typescript/test/testdata/showcase/system-test/install.ts.baseline @@ -21,7 +21,7 @@ import { readFileSync } from 'fs'; describe('typescript consumer tests', () => { - it('should have correct type signature for Showcase client library', async function() { + it('should have correct type signature for typescript users', async function() { this.timeout(300000); const options = { packageDir: process.cwd(), // path to your module. @@ -33,4 +33,16 @@ describe('typescript consumer tests', () => { await packNTest(options); // will throw upon error. }); + it('should have correct type signature for javascript users', async function() { + this.timeout(300000); + const options = { + packageDir: process.cwd(), // path to your module. + sample: { + description: 'typescript based user can use the type definitions', + ts: readFileSync('./system-test/fixtures/sample/src/index.js').toString() + } + }; + await packNTest(options); // will throw upon error. + }); + }); diff --git a/typescript/test/testdata/texttospeech/system-test/fixtures/sample/src/index.js.baseline b/typescript/test/testdata/texttospeech/system-test/fixtures/sample/src/index.js.baseline new file mode 100644 index 000000000..2e64b80ef --- /dev/null +++ b/typescript/test/testdata/texttospeech/system-test/fixtures/sample/src/index.js.baseline @@ -0,0 +1,26 @@ +// Copyright 2019 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 +// +// https://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. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import {TextToSpeechClient} from 'texttospeech'; + +function main() { + const textToSpeechClient = new TextToSpeechClient(); + console.log("textToSpeechClient was created!"); +} + +main(); diff --git a/typescript/test/testdata/texttospeech/system-test/install.ts.baseline b/typescript/test/testdata/texttospeech/system-test/install.ts.baseline index a7fd2fc3e..faa7e02aa 100644 --- a/typescript/test/testdata/texttospeech/system-test/install.ts.baseline +++ b/typescript/test/testdata/texttospeech/system-test/install.ts.baseline @@ -21,7 +21,7 @@ import { readFileSync } from 'fs'; describe('typescript consumer tests', () => { - it('should have correct type signature for Texttospeech client library', async function() { + it('should have correct type signature for typescript users', async function() { this.timeout(300000); const options = { packageDir: process.cwd(), // path to your module. @@ -33,4 +33,16 @@ describe('typescript consumer tests', () => { await packNTest(options); // will throw upon error. }); + it('should have correct type signature for javascript users', async function() { + this.timeout(300000); + const options = { + packageDir: process.cwd(), // path to your module. + sample: { + description: 'typescript based user can use the type definitions', + ts: readFileSync('./system-test/fixtures/sample/src/index.js').toString() + } + }; + await packNTest(options); // will throw upon error. + }); + }); diff --git a/typescript/test/testdata/translate/system-test/fixtures/sample/src/index.js.baseline b/typescript/test/testdata/translate/system-test/fixtures/sample/src/index.js.baseline new file mode 100644 index 000000000..d2ec87f5e --- /dev/null +++ b/typescript/test/testdata/translate/system-test/fixtures/sample/src/index.js.baseline @@ -0,0 +1,26 @@ +// Copyright 2019 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 +// +// https://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. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import {TranslationServiceClient} from 'translation'; + +function main() { + const translationServiceClient = new TranslationServiceClient(); + console.log("translationServiceClient was created!"); +} + +main(); diff --git a/typescript/test/testdata/translate/system-test/install.ts.baseline b/typescript/test/testdata/translate/system-test/install.ts.baseline index 78708aaec..faa7e02aa 100644 --- a/typescript/test/testdata/translate/system-test/install.ts.baseline +++ b/typescript/test/testdata/translate/system-test/install.ts.baseline @@ -21,7 +21,7 @@ import { readFileSync } from 'fs'; describe('typescript consumer tests', () => { - it('should have correct type signature for Translation client library', async function() { + it('should have correct type signature for typescript users', async function() { this.timeout(300000); const options = { packageDir: process.cwd(), // path to your module. @@ -33,4 +33,16 @@ describe('typescript consumer tests', () => { await packNTest(options); // will throw upon error. }); + it('should have correct type signature for javascript users', async function() { + this.timeout(300000); + const options = { + packageDir: process.cwd(), // path to your module. + sample: { + description: 'typescript based user can use the type definitions', + ts: readFileSync('./system-test/fixtures/sample/src/index.js').toString() + } + }; + await packNTest(options); // will throw upon error. + }); + }); From c5557d8ff61cdb18a3cccbca3821f33cf8fe84e1 Mon Sep 17 00:00:00 2001 From: xiaozhenliugg Date: Wed, 13 Nov 2019 11:49:24 -0800 Subject: [PATCH 4/4] js test application --- .../system-test/fixtures/sample/src/index.js.njk | 4 ++-- .../system-test/fixtures/sample/src/index.js.baseline | 4 ++-- .../system-test/fixtures/sample/src/index.js.baseline | 4 ++-- .../system-test/fixtures/sample/src/index.js.baseline | 4 ++-- .../system-test/fixtures/sample/src/index.js.baseline | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/templates/typescript_gapic/system-test/fixtures/sample/src/index.js.njk b/templates/typescript_gapic/system-test/fixtures/sample/src/index.js.njk index 4a2a26cfa..d0c928885 100644 --- a/templates/typescript_gapic/system-test/fixtures/sample/src/index.js.njk +++ b/templates/typescript_gapic/system-test/fixtures/sample/src/index.js.njk @@ -18,12 +18,12 @@ limitations under the License. {% import "../../../../_license.njk" as license -%} {{license.license()}} {%- for service in api.services %} -import { {{- service.name.toPascalCase() + 'Client' -}} } from '{{ api.naming.productName.toKebabCase() }}'; +const {{ api.naming.productName.toKebabCase()}} = require('{{ api.naming.productName.toKebabCase() }}'); {%- endfor %} function main() { {%- for service in api.services %} - const {{ service.name.toCamelCase() -}}Client = new {{ service.name.toPascalCase() + 'Client' -}}(); + const {{ service.name.toCamelCase() -}}Client = new {{ api.naming.productName.toKebabCase() }}.{{ service.name.toPascalCase() + 'Client' }}(); console.log("{{- service.name.toCamelCase() -}}Client was created!"); {%- endfor %} } diff --git a/typescript/test/testdata/keymanager/system-test/fixtures/sample/src/index.js.baseline b/typescript/test/testdata/keymanager/system-test/fixtures/sample/src/index.js.baseline index 310e4c51e..532f7ddd0 100644 --- a/typescript/test/testdata/keymanager/system-test/fixtures/sample/src/index.js.baseline +++ b/typescript/test/testdata/keymanager/system-test/fixtures/sample/src/index.js.baseline @@ -16,10 +16,10 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -import {KeyManagementServiceClient} from 'kms'; +const kms = require('kms'); function main() { - const keyManagementServiceClient = new KeyManagementServiceClient(); + const keyManagementServiceClient = new kms.KeyManagementServiceClient(); console.log("keyManagementServiceClient was created!"); } diff --git a/typescript/test/testdata/showcase/system-test/fixtures/sample/src/index.js.baseline b/typescript/test/testdata/showcase/system-test/fixtures/sample/src/index.js.baseline index dca99e9fb..3c71a80e0 100644 --- a/typescript/test/testdata/showcase/system-test/fixtures/sample/src/index.js.baseline +++ b/typescript/test/testdata/showcase/system-test/fixtures/sample/src/index.js.baseline @@ -16,10 +16,10 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -import {EchoClient} from 'showcase'; +const showcase = require('showcase'); function main() { - const echoClient = new EchoClient(); + const echoClient = new showcase.EchoClient(); console.log("echoClient was created!"); } diff --git a/typescript/test/testdata/texttospeech/system-test/fixtures/sample/src/index.js.baseline b/typescript/test/testdata/texttospeech/system-test/fixtures/sample/src/index.js.baseline index 2e64b80ef..443142bb6 100644 --- a/typescript/test/testdata/texttospeech/system-test/fixtures/sample/src/index.js.baseline +++ b/typescript/test/testdata/texttospeech/system-test/fixtures/sample/src/index.js.baseline @@ -16,10 +16,10 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -import {TextToSpeechClient} from 'texttospeech'; +const texttospeech = require('texttospeech'); function main() { - const textToSpeechClient = new TextToSpeechClient(); + const textToSpeechClient = new texttospeech.TextToSpeechClient(); console.log("textToSpeechClient was created!"); } diff --git a/typescript/test/testdata/translate/system-test/fixtures/sample/src/index.js.baseline b/typescript/test/testdata/translate/system-test/fixtures/sample/src/index.js.baseline index d2ec87f5e..87f33996e 100644 --- a/typescript/test/testdata/translate/system-test/fixtures/sample/src/index.js.baseline +++ b/typescript/test/testdata/translate/system-test/fixtures/sample/src/index.js.baseline @@ -16,10 +16,10 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -import {TranslationServiceClient} from 'translation'; +const translation = require('translation'); function main() { - const translationServiceClient = new TranslationServiceClient(); + const translationServiceClient = new translation.TranslationServiceClient(); console.log("translationServiceClient was created!"); }