forked from googleapis/google-auth-library-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add typescript test (googleapis#192)
- Loading branch information
1 parent
a4a85e9
commit 873c33d
Showing
9 changed files
with
159 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"test/**/*.ts" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
"node_modules", | ||
"test/fixtures" | ||
] | ||
} |