Skip to content

Commit

Permalink
test: add typescript test (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and ofrobots committed Jan 8, 2018
1 parent b3bda6b commit 7fb0bb3
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 52 deletions.
115 changes: 71 additions & 44 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
"@types/jws": "^3.1.0",
"@types/lodash.isstring": "^4.0.2",
"@types/mocha": "^2.2.41",
"@types/ncp": "^2.0.1",
"@types/nock": "^8.2.1",
"@types/node": "^8.0.49",
"@types/request": "^2.0.7",
"@types/pify": "^3.0.0",
"@types/tmp": "0.0.33",
"clang-format": "^1.0.50",
"coveralls": "^3.0.0",
"del": "^3.0.0",
Expand All @@ -44,20 +46,21 @@
"gulp-typescript": "^3.1.6",
"istanbul": "^0.4.5",
"keypair": "^1.0.0",
"merge2": "^1.0.3",
"mocha": "^4.0.1",
"ncp": "^2.0.0",
"nock": "^9.0.2",
"pify": "^3.0.0",
"source-map-support": "^0.5.0",
"tmp": "0.0.33",
"tslint": "^5.1.0",
"typedoc": "^0.9.0",
"typescript": "~2.6.0"
},
"files": [
"LICENSE",
"README.md",
"src/**/*.js",
"package.json",
"types/lib"
"build/src",
"package.json"
],
"scripts": {
"coverage": "istanbul cover -x 'apis/**' _mocha build/test -- --reporter spec --timeout 4000",
Expand Down
1 change: 0 additions & 1 deletion src/auth/computeclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export class Compute extends OAuth2Client {
e.message = 'Could not refresh access token.';
throw e;
}
console.log(res.data);
const tokens = res.data as Credentials;
if (res.data && res.data.expires_in) {
tokens.expiry_date =
Expand Down
1 change: 0 additions & 1 deletion src/auth/oauth2client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ export class OAuth2Client extends AuthClient {
const res = await this.transporter.request<CredentialRequest>(
{method: 'POST', url, data: values});

console.log(res.data);
const tokens = res.data as Credentials;
if (res.data && res.data.expires_in) {
tokens.expiry_date =
Expand Down
24 changes: 24 additions & 0 deletions test/fixtures/kitchen/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "google-auth-library-nodejs-fixture",
"version": "1.0.0",
"description": "An app we're using to test the 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": {
"google-auth-library": "file:./google-auth-library.tgz"
},
"devDependencies": {
"@types/node": "^8.0.53",
"typescript": "^2.6.1",
"gts": "^0.5.1"
}
}
12 changes: 12 additions & 0 deletions test/fixtures/kitchen/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {GoogleAuth} from 'google-auth-library';
// uncomment the line below during development
// import {GoogleAuth} from '../../../../build/src/index';
const auth = new GoogleAuth();
const jwt = new auth.JWT();
async function getToken() {
const token = await jwt.getToken('token');
const projectId = await auth.getDefaultProjectId();
const creds = await auth.getApplicationDefault();
return token;
}
getToken();
14 changes: 14 additions & 0 deletions test/fixtures/kitchen/tsconfig.json
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"
},
"include": [
"src/*.ts",
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}
72 changes: 72 additions & 0 deletions test/test.kitchen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright 2017 Google Inc. All Rights Reserved.
*
* 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 * as cp from 'child_process';
import * as fs from 'fs';
import {ncp} from 'ncp';
import * as pify from 'pify';
import * as tmp from 'tmp';

const rename = pify(fs.rename);
const ncpp = pify(ncp);
const keep = !!process.env.GALN_KEEP_TEMPDIRS;
const stagingDir = tmp.dirSync({keep, unsafeCleanup: true});
const stagingPath = stagingDir.name;
const pkg = require('../../package.json');

const spawnp = (command: string, args: string[], options: cp.SpawnOptions = {}):
Promise<void> => {
return new Promise((resolve, reject) => {
cp.spawn(command, args, Object.assign(options, {stdio: 'inherit'}))
.on('close',
(code, signal) => {
if (code === 0) {
resolve();
} else {
reject(
new Error(`Spawn failed with an exit code of ${code}`));
}
})
.on('error', err => {
reject(err);
});
});
};

/**
* Create a staging directory with temp fixtures used
* to test on a fresh application.
*/

describe('kitchen sink', async () => {
it('should be able to use the d.ts', async () => {
console.log(`${__filename} staging area: ${stagingPath}`);
await spawnp('npm', ['pack']);
const tarball = `${pkg.name}-${pkg.version}.tgz`;
await rename(tarball, `${stagingPath}/google-auth-library.tgz`);
await ncpp('test/fixtures/kitchen', `${stagingPath}/`);
await spawnp('npm', ['install'], {cwd: `${stagingPath}/`});
}).timeout(40000);
});

/**
* CLEAN UP - remove the staging directory when done.
*/
after('cleanup staging', async () => {
if (!keep) {
stagingDir.removeCallback();
}
});
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"test/**/*.ts"
],
"exclude": [
"node_modules"
"node_modules",
"test/fixtures"
]
}

0 comments on commit 7fb0bb3

Please sign in to comment.