From 63b89e9835bce5177c686bc3888b3b608d16ea37 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Tue, 5 Mar 2019 21:40:52 -0800 Subject: [PATCH] fix: add missing package, and add install test (#346) --- package.json | 13 +++++- system-test/fixtures/sample/package.json | 23 ++++++++++ system-test/fixtures/sample/src/index.ts | 6 +++ system-test/fixtures/sample/tsconfig.json | 10 ++++ system-test/install.ts | 56 +++++++++++++++++++++++ 5 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 system-test/fixtures/sample/package.json create mode 100644 system-test/fixtures/sample/src/index.ts create mode 100644 system-test/fixtures/sample/tsconfig.json create mode 100644 system-test/install.ts diff --git a/package.json b/package.json index e17b69b29..bd9a36925 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "dependencies": { "@google-cloud/projectify": "^0.3.2", "@google-cloud/promisify": "^0.4.0", + "@types/duplexify": "^3.6.0", "arrify": "^1.0.1", "concat-stream": "^2.0.0", "extend": "^3.0.1", @@ -62,30 +63,38 @@ "@google-cloud/nodejs-repo-tools": "^3.0.0", "@types/arrify": "^1.0.4", "@types/async": "^2.0.50", + "@types/execa": "^0.9.0", "@types/extend": "^3.0.0", "@types/is": "0.0.21", "@types/mocha": "^5.2.5", + "@types/mv": "^2.1.0", + "@types/ncp": "^2.0.1", "@types/proxyquire": "^1.3.28", "@types/sinon": "^7.0.2", "@types/through2": "^2.0.34", + "@types/tmp": "0.0.34", "assert-rejects": "^1.0.0", "codecov": "^3.0.2", "eslint": "^5.0.0", "eslint-config-prettier": "^4.0.0", "eslint-plugin-node": "^8.0.0", "eslint-plugin-prettier": "^3.0.0", + "execa": "^1.0.0", "google-proto-files": "^0.18.0", "gts": "^0.9.0", "intelli-espower-loader": "^1.0.1", "jsdoc": "^3.5.5", "jsdoc-baseline": "git+https://github.com/hegemonic/jsdoc-baseline.git", + "linkinator": "^1.1.2", "mocha": "^6.0.0", + "mv": "^2.1.1", + "npc": "0.0.1", "nyc": "^13.0.0", "power-assert": "^1.5.0", "prettier": "^1.13.5", "proxyquire": "^2.0.1", "sinon": "^7.0.0", - "typescript": "~3.3.0", - "linkinator": "^1.1.2" + "tmp": "0.0.33", + "typescript": "~3.3.0" } } diff --git a/system-test/fixtures/sample/package.json b/system-test/fixtures/sample/package.json new file mode 100644 index 000000000..8535d6bd8 --- /dev/null +++ b/system-test/fixtures/sample/package.json @@ -0,0 +1,23 @@ +{ + "name": "datastore-sample-fixture", + "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-cloud/datastore": "file:./datastore.tgz" + }, + "devDependencies": { + "@types/node": "^10.3.0", + "typescript": "^3.0.0", + "gts": "^0.9.0" + } +} diff --git a/system-test/fixtures/sample/src/index.ts b/system-test/fixtures/sample/src/index.ts new file mode 100644 index 000000000..f6bd17e90 --- /dev/null +++ b/system-test/fixtures/sample/src/index.ts @@ -0,0 +1,6 @@ +import {Datastore} from '@google-cloud/datastore'; +async function main() { + const datastore = new Datastore(); + console.log(datastore); +} +main(); diff --git a/system-test/fixtures/sample/tsconfig.json b/system-test/fixtures/sample/tsconfig.json new file mode 100644 index 000000000..f893d7afb --- /dev/null +++ b/system-test/fixtures/sample/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "./node_modules/gts/tsconfig-google.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "build" + }, + "include": [ + "src/*.ts" + ] +} diff --git a/system-test/install.ts b/system-test/install.ts new file mode 100644 index 000000000..6afae6c23 --- /dev/null +++ b/system-test/install.ts @@ -0,0 +1,56 @@ +/** + * Copyright 2019 Google LLC. 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 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) as {} as (...args: string[]) => Promise; +const ncpp = promisify(ncp); +const stagingDir = tmp.dirSync({keep, unsafeCleanup: true}); +const stagingPath = stagingDir.name; +const pkg = require('../../package.json'); + +describe('📦 pack and install', () => { + /** + * Create a staging directory with temp fixtures used to test on a fresh + * application. + */ + it('should be able to use the d.ts', async () => { + await execa('npm', ['pack', '--unsafe-perm']); + const tarball = `google-cloud-datastore-${pkg.version}.tgz`; + await mvp(tarball, `${stagingPath}/datastore.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'}); + }); + + /** + * CLEAN UP - remove the staging directory when done. + */ + after('cleanup staging', () => { + if (!keep) { + stagingDir.removeCallback(); + } + }); +});