Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pack and install test #121

Merged
merged 8 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,40 +63,44 @@ jobs:
npm run browser-test
trap stop_showcase EXIT
- run:
name: Run unit tests and gts fix of the generated Showcase library
name: Run unit tests, system tests, and gts fix of the generated Showcase library
command: |
cd .test-out-showcase
npm install
npm test
npm run fix
npm run compile
npm run system-test
- run:
name: Run unit tests and gts fix of the generated KMS library
name: Run unit tests, system 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
npm run compile
npm run system-test
- run:
name: Run unit tests and gts fix of the generated Translate library
name: Run unit tests, system 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
npm run compile
npm run system-test
- run:
name: Run unit tests and gts fix of the generated Text-to-Speech library
name: Run unit tests, system 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
npm run compile
npm run system-test
- run:
name: Run linting
command: |
Expand Down
16 changes: 12 additions & 4 deletions templates/typescript_gapic/package.json.njk
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ limitations under the License.
"build/protos"
],
"dependencies": {
"google-gax": "^1.8.0"
"google-gax": "^1.9.0"
},
"devDependencies": {
"@types/node": "^12.0.0",
"@types/mocha": "^5.2.5",
"@types/mv": "^2.1.0",
"@types/ncp": "^2.0.3",
"@types/node": "^12.0.0",
"@types/tmp": "^0.1.0",
"execa": "^3.2.0",
"gts": "^1.0.0",
"mocha": "^6.0.0",
"typescript": "~3.6.0"
"mv": "^2.1.1",
"ncp": "^2.0.0",
"tmp": "^0.1.0",
"typescript": "^3.7.0"
},
"scripts": {
"lint": "gts check",
Expand All @@ -43,7 +50,8 @@ limitations under the License.
"compile-protos": "compileProtos src",
"fix": "gts fix",
"prepare": "npm run compile-protos && npm run compile",
"test": "mocha build/test"
"test": "mocha build/test",
"system-test": "mocha build/system-test"
},
"license": "Apache-2.0",
"engines": {
Expand Down
22 changes: 22 additions & 0 deletions templates/typescript_gapic/system-test/.eslintrc.yml.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{#-

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.

-#}
---
env:
mocha: true
rules:
no-console: off
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{#-

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"
}
}
Original file line number Diff line number Diff line change
@@ -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 -%}

{%- 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();
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{#-

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"
]
}
56 changes: 56 additions & 0 deletions templates/typescript_gapic/system-test/install.ts.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{#-

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 -%}

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() {
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',
});
});

after('cleanup staging', () => {
if (!keep) {
stagingDir.removeCallback();
}
});
});
3 changes: 2 additions & 1 deletion templates/typescript_gapic/tsconfig.json.njk
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ limitations under the License.
"src/*.ts",
"src/**/*.ts",
"test/*.ts",
"test/**/*.ts"
"test/**/*.ts",
"system-test/*.ts"
]
}
16 changes: 12 additions & 4 deletions typescript/test/testdata/keymanager/package.json.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@
"build/protos"
],
"dependencies": {
"google-gax": "^1.8.0"
"google-gax": "^1.9.0"
},
"devDependencies": {
"@types/node": "^12.0.0",
"@types/mocha": "^5.2.5",
"@types/mv": "^2.1.0",
"@types/ncp": "^2.0.3",
"@types/node": "^12.0.0",
"@types/tmp": "^0.1.0",
"execa": "^3.2.0",
"gts": "^1.0.0",
"mocha": "^6.0.0",
"typescript": "~3.6.0"
"mv": "^2.1.1",
"ncp": "^2.0.0",
"tmp": "^0.1.0",
"typescript": "^3.7.0"
},
"scripts": {
"lint": "gts check",
Expand All @@ -26,7 +33,8 @@
"compile-protos": "compileProtos src",
"fix": "gts fix",
"prepare": "npm run compile-protos && npm run compile",
"test": "mocha build/test"
"test": "mocha build/test",
"system-test": "mocha build/system-test"
},
"license": "Apache-2.0",
"engines": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
env:
mocha: true
rules:
no-console: off
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import {KeyManagementServiceClient} from 'kms';

function main() {
const keyManagementServiceClient = new KeyManagementServiceClient();
console.log("keyManagementServiceClient was created!");
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "build",
"types": [
"node"
],
"skipLibCheck": false
},
"include": [
"src/*.ts"
]
}
Loading