From 17e521f7e3ad8248e70add902e9a822f5597318a Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Tue, 12 Feb 2019 09:54:50 -0800 Subject: [PATCH] test: add an install test (#43) --- .cirrus.yml | 4 ++ package.json | 10 ++++ system-test/fixtures/sample/package.json | 23 ++++++++++ system-test/fixtures/sample/src/index.ts | 7 +++ system-test/fixtures/sample/tsconfig.json | 10 ++++ system-test/test.install.ts | 56 +++++++++++++++++++++++ 6 files changed, 110 insertions(+) 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/test.install.ts diff --git a/.cirrus.yml b/.cirrus.yml index 63cd7e59..1b9e38da 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -5,6 +5,10 @@ lint_task: install_script: npm install test_script: npm run lint +system_test_task: + install_script: npm install + test_script: npm run system-test + test_task: container: matrix: diff --git a/package.json b/package.json index c2c95456..ba82858f 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,8 @@ "lint": "semistandard && gts check", "test": "nyc mocha build/test", "samples-test": "cd samples/ && npm link ../ && npm test && cd ../", + "presystem-test": "npm run compile", + "system-test": "mocha build/system-test --timeout 40000", "clean": "gts clean", "compile": "tsc -p . && npm run fix", "fix": "gts fix && semistandard --fix", @@ -28,22 +30,30 @@ "devDependencies": { "@commitlint/cli": "^7.2.1", "@commitlint/config-conventional": "^7.1.2", + "@types/execa": "^0.9.0", "@types/extend": "^3.0.0", "@types/mocha": "^5.2.5", + "@types/mv": "^2.1.0", + "@types/ncp": "^2.0.1", "@types/nock": "^9.3.0", "@types/node": "^10.5.6", "@types/node-fetch": "^2.1.2", "@types/sinon": "^7.0.0", + "@types/tmp": "0.0.33", "assert-rejects": "^1.0.0", "codecov": "^3.0.4", + "execa": "^1.0.0", "gts": "^0.9.0", "mocha": "^5.2.0", + "mv": "^2.1.1", + "ncp": "^2.0.0", "nock": "^9.6.0", "nyc": "^12.0.2", "semantic-release": "^15.13.2", "semistandard": "^13.0.1", "sinon": "^7.1.1", "source-map-support": "^0.5.6", + "tmp": "0.0.33", "typescript": "~3.3.0" }, "dependencies": { diff --git a/system-test/fixtures/sample/package.json b/system-test/fixtures/sample/package.json new file mode 100644 index 00000000..e478263c --- /dev/null +++ b/system-test/fixtures/sample/package.json @@ -0,0 +1,23 @@ +{ + "name": "gaxios-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": { + "gaxios": "file:./gaxios.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 00000000..ffc92c41 --- /dev/null +++ b/system-test/fixtures/sample/src/index.ts @@ -0,0 +1,7 @@ +import {request} from 'gaxios'; +async function main() { + await request({ + url: 'https://www.googleapis.com/discovery/v1/apis/' + }); +} +main(); diff --git a/system-test/fixtures/sample/tsconfig.json b/system-test/fixtures/sample/tsconfig.json new file mode 100644 index 00000000..f893d7af --- /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/test.install.ts b/system-test/test.install.ts new file mode 100644 index 00000000..4f7fe3a1 --- /dev/null +++ b/system-test/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 = `${pkg.name}-${pkg.version}.tgz`; + await mvp(tarball, `${stagingPath}/gaxios.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(); + } + }); +});