Skip to content

Commit

Permalink
feat: replace system test with pack-n-play (#132)
Browse files Browse the repository at this point in the history
* pack-n-play setup

* feedback

* system-test for js users

* js test application
  • Loading branch information
xiaozhenliu-gg5 authored Nov 13, 2019
1 parent 2171b6f commit 2e4bcb5
Show file tree
Hide file tree
Showing 24 changed files with 239 additions and 351 deletions.
1 change: 1 addition & 0 deletions templates/typescript_gapic/package.json.njk
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"null-loader": "^3.0.0",
"tmp": "^0.1.0",
"ts-loader": "^6.2.1",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ 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"
]
{% import "../../../../_license.njk" as license -%}
{{license.license()}}
{%- for service in api.services %}
const {{ api.naming.productName.toKebabCase()}} = require('{{ api.naming.productName.toKebabCase() }}');
{%- endfor %}

function main() {
{%- for service in api.services %}
const {{ service.name.toCamelCase() -}}Client = new {{ api.naming.productName.toKebabCase() }}.{{ service.name.toPascalCase() + 'Client' }}();
console.log("{{- service.name.toCamelCase() -}}Client was created!");
{%- endfor %}
}

main();
57 changes: 25 additions & 32 deletions templates/typescript_gapic/system-test/install.ts.njk
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,33 @@ 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 typescript users', 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 user can use the 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();
}
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.
});

});
1 change: 1 addition & 0 deletions typescript/test/testdata/keymanager/package.json.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"mocha": "^6.0.0",
"mv": "^2.1.1",
"ncp": "^2.0.0",
"pack-n-play": "^1.0.0-2",
"null-loader": "^3.0.0",
"tmp": "^0.1.0",
"ts-loader": "^6.2.1",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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. **

const kms = require('kms');

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

main();

This file was deleted.

53 changes: 23 additions & 30 deletions typescript/test/testdata/keymanager/system-test/install.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,33 @@
// ** 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 typescript users', 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 user can use the 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();
}
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.
});

});
1 change: 1 addition & 0 deletions typescript/test/testdata/showcase/package.json.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"mocha": "^6.0.0",
"mv": "^2.1.1",
"ncp": "^2.0.0",
"pack-n-play": "^1.0.0-2",
"null-loader": "^3.0.0",
"tmp": "^0.1.0",
"ts-loader": "^6.2.1",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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. **

const showcase = require('showcase');

function main() {
const echoClient = new showcase.EchoClient();
console.log("echoClient was created!");
}

main();

This file was deleted.

Loading

0 comments on commit 2e4bcb5

Please sign in to comment.