Skip to content

Commit

Permalink
test: use pack-n-play for install test (#1237)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarowolfx committed Jul 31, 2023
1 parent 73bf31f commit 37b3cf2
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 81 deletions.
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,27 @@
"devDependencies": {
"@google-cloud/storage": "^6.0.0",
"@types/big.js": "^6.0.0",
"@types/execa": "^0.9.0",
"@types/extend": "^3.0.1",
"@types/is": "0.0.22",
"@types/mocha": "^9.0.0",
"@types/mv": "^2.1.0",
"@types/ncp": "^2.0.1",
"@types/node": "^18.0.0",
"@types/proxyquire": "^1.3.28",
"@types/sinon": "^10.0.0",
"@types/tmp": "0.2.3",
"@types/uuid": "^9.0.0",
"c8": "^8.0.0",
"codecov": "^3.5.0",
"discovery-tsd": "^0.3.0",
"eslint-plugin-prettier": "^5.0.0",
"execa": "^5.0.0",
"gts": "^5.0.0",
"jsdoc": "^4.0.0",
"jsdoc-fresh": "^2.0.0",
"jsdoc-region-tag": "^2.0.0",
"linkinator": "^5.0.0",
"mocha": "^9.2.2",
"mv": "^2.1.1",
"ncp": "^2.0.0",
"pack-n-play": "^1.0.0-2",
"prettier": "^3.0.0",
"proxyquire": "^2.1.0",
"sinon": "^15.0.0",
"tmp": "0.2.1",
"typescript": "^5.1.6"
}
}
23 changes: 0 additions & 23 deletions system-test/fixtures/kitchen/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions system-test/fixtures/kitchen/src/index.ts

This file was deleted.

10 changes: 0 additions & 10 deletions system-test/fixtures/kitchen/tsconfig.json

This file was deleted.

22 changes: 22 additions & 0 deletions system-test/fixtures/sample/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2023 Google LLC
//
// 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
//
// https://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 {BigQuery} from '@google-cloud/bigquery';

function main() {
const bq = new BigQuery();
console.log(bq);
}

main();
58 changes: 24 additions & 34 deletions system-test/install.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,39 @@
// Copyright 2014 Google LLC
// Copyright 2023 Google LLC
//
// 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
// https://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';
import {describe, it, before, after} from 'mocha';
import {packNTest} from 'pack-n-play';
import {readFileSync} from 'fs';
import {describe, it} from 'mocha';

const RUNNING_IN_VPCSC = !!process.env['GOOGLE_CLOUD_TESTS_IN_VPCSC'];

const mvp = promisify(mv) as {} as (...args: string[]) => Promise<void>;
const ncpp = promisify(ncp);
const stagingDir = tmp.dirSync({unsafeCleanup: true});
const stagingPath = stagingDir.name;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../../package.json');

describe('Installation test', () => {
before(function () {
if (RUNNING_IN_VPCSC) this.skip();
describe('📦 pack-n-play test', () => {
it('TypeScript code', async function () {
this.timeout(300000);
const options = {
packageDir: process.cwd(),
sample: {
description: 'TypeScript user can use the type definitions',
ts: readFileSync(
'./system-test/fixtures/sample/src/index.ts'
).toString(),
dependencies: ['@types/node'],
},
};
try {
await packNTest(options);
} catch (err) {
console.error('TS install failed:\n', err);
throw err;
}
});

/**
* CLEAN UP - remove the staging directory when done.
*/
after('cleanup staging', () => stagingDir.removeCallback());

it('should be able to use the d.ts', async () => {
console.log(`${__filename} staging area: ${stagingPath}`);
await execa('npm', ['pack'], {stdio: 'inherit'});
const tarball = `google-cloud-bigquery-${pkg.version}.tgz`;
await mvp(tarball, `${stagingPath}/google-cloud-bigquery.tgz`);
await ncpp('system-test/fixtures/kitchen', `${stagingPath}/`);
await execa('npm', ['install'], {cwd: `${stagingPath}/`, stdio: 'inherit'});
}).timeout(40000);
});
12 changes: 9 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "build"
"outDir": "build",
"resolveJsonModule": true,
"lib": [
"es2018",
"dom"
]
},
"include": [
"src/*.ts",
"src/**/*.ts",
"test/*.ts",
"system-test/*.ts",
"benchmark/*.ts"
"test/**/*.ts",
"system-test/*.ts"
]
}

0 comments on commit 37b3cf2

Please sign in to comment.