Skip to content

Commit

Permalink
test: add an install test (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Feb 12, 2019
1 parent 6c66e43 commit 17e521f
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
23 changes: 23 additions & 0 deletions system-test/fixtures/sample/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
7 changes: 7 additions & 0 deletions system-test/fixtures/sample/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {request} from 'gaxios';
async function main() {
await request({
url: 'https://www.googleapis.com/discovery/v1/apis/'
});
}
main();
10 changes: 10 additions & 0 deletions system-test/fixtures/sample/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "build"
},
"include": [
"src/*.ts"
]
}
56 changes: 56 additions & 0 deletions system-test/test.install.ts
Original file line number Diff line number Diff line change
@@ -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<void>;
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();
}
});
});

0 comments on commit 17e521f

Please sign in to comment.