diff --git a/conformance-test/libraryMethods.ts b/conformance-test/libraryMethods.ts index 99d201042..6dfa7e284 100644 --- a/conformance-test/libraryMethods.ts +++ b/conformance-test/libraryMethods.ts @@ -183,7 +183,10 @@ export async function bucketUploadResumable(bucket: Bucket) { bucket.instancePreconditionOpts.ifGenerationMatch = 0; } await bucket.upload( - path.join(__dirname, 'test-data', 'retryStrategyTestData.json'), + path.join( + __dirname, + '../../conformance-test/test-data/retryStrategyTestData.json' + ), {resumable: true} ); } @@ -194,7 +197,10 @@ export async function bucketUploadMultipart(bucket: Bucket) { bucket.instancePreconditionOpts.ifGenerationMatch = 0; } await bucket.upload( - path.join(__dirname, 'test-data', 'retryStrategyTestData.json'), + path.join( + __dirname, + '../../conformance-test/test-data/retryStrategyTestData.json' + ), {resumable: false} ); } diff --git a/conformance-test/v4SignedUrl.ts b/conformance-test/v4SignedUrl.ts index fc9384985..2bc20d1c8 100644 --- a/conformance-test/v4SignedUrl.ts +++ b/conformance-test/v4SignedUrl.ts @@ -88,7 +88,7 @@ interface BucketAction { } const testFile = fs.readFileSync( - path.join(__dirname, 'test-data', 'v4SignedUrl.json'), + path.join(__dirname, '../../conformance-test/test-data/v4SignedUrl.json'), 'utf-8' ); @@ -100,8 +100,7 @@ const v4SignedPolicyCases: V4SignedPolicyTestCase[] = const SERVICE_ACCOUNT = path.join( __dirname, - 'fixtures', - 'signing-service-account.json' + '../../conformance-test/fixtures/signing-service-account.json' ); const storage = new Storage({keyFilename: SERVICE_ACCOUNT}); diff --git a/package.json b/package.json index 0855e7b70..d92ec6773 100644 --- a/package.json +++ b/package.json @@ -26,16 +26,15 @@ "google storage", "storage" ], - "mocha": { - "require": "ts-node/register", - "extension": "ts" - }, "scripts": { "predocs": "npm run compile", "docs": "jsdoc -c .jsdoc.js", - "system-test": "mocha system-test --timeout 600000 --exit", - "conformance-test": "mocha --parallel --require ts-node/register --require conformance-test/globalHooks.ts conformance-test/", - "test": "c8 mocha test", + "system-test": "mocha build/system-test --timeout 600000 --exit", + "conformance-test": "mocha --parallel build/conformance-test/ --require build/conformance-test/globalHooks.js", + "preconformance-test": "npm run compile", + "presystem-test": "npm run compile", + "test": "c8 mocha build/test", + "pretest": "npm run compile", "lint": "gts check", "samples-test": "npm link && cd samples/ && npm link ../ && npm test && cd ../", "all-test": "npm test && npm run system-test && npm run samples-test", @@ -111,7 +110,6 @@ "proxyquire": "^2.1.3", "sinon": "^14.0.0", "tmp": "^0.2.0", - "ts-node": "^10.7.0", "typescript": "~3.9.10", "uuid": "^8.0.0", "yargs": "^16.0.0" diff --git a/src/gcs-resumable-upload.ts b/src/gcs-resumable-upload.ts index d64d6f522..8d5bd18bb 100644 --- a/src/gcs-resumable-upload.ts +++ b/src/gcs-resumable-upload.ts @@ -28,13 +28,12 @@ import {Readable, Writable} from 'stream'; import retry = require('async-retry'); import {RetryOptions, PreconditionOptions} from './storage'; import * as uuid from 'uuid'; -import {getPackageJSON} from './util'; const NOT_FOUND_STATUS_CODE = 404; const TERMINATED_UPLOAD_STATUS_CODE = 410; const RESUMABLE_INCOMPLETE_STATUS_CODE = 308; const DEFAULT_API_ENDPOINT_REGEX = /.*\.googleapis\.com/; -const packageJson = getPackageJSON(); +const packageJson = require('../../package.json'); export const PROTOCOL_REGEX = /^(\w*):\/\//; diff --git a/src/nodejs-common/util.ts b/src/nodejs-common/util.ts index b1fd1e206..3008f187b 100644 --- a/src/nodejs-common/util.ts +++ b/src/nodejs-common/util.ts @@ -29,8 +29,7 @@ import {Duplex, DuplexOptions, Readable, Transform, Writable} from 'stream'; import {teenyRequest} from 'teeny-request'; import {Interceptor} from './service-object'; import * as uuid from 'uuid'; -import {getPackageJSON} from '../util'; -const packageJson = getPackageJSON(); +const packageJson = require('../../../package.json'); // eslint-disable-next-line @typescript-eslint/no-var-requires const duplexify: DuplexifyConstructor = require('duplexify'); diff --git a/src/storage.ts b/src/storage.ts index 3d815bf0f..2298544b6 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -21,7 +21,7 @@ import {Readable} from 'stream'; import {Bucket} from './bucket'; import {Channel} from './channel'; import {File} from './file'; -import {getPackageJSON, normalize} from './util'; +import {normalize} from './util'; import {HmacKey, HmacKeyMetadata, HmacKeyOptions} from './hmacKey'; export interface GetServiceAccountOptions { @@ -614,8 +614,6 @@ export class Storage extends Service { maxRetryValue = options.retryOptions.maxRetries; } - const packageJson = getPackageJSON(); - const config = { apiEndpoint: options.apiEndpoint!, retryOptions: { @@ -647,7 +645,7 @@ export class Storage extends Service { 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/devstorage.full_control', ], - packageJson, + packageJson: require('../../package.json'), }; super(config, options); diff --git a/src/util.ts b/src/util.ts index ffe9a4323..89ba6a2d5 100644 --- a/src/util.ts +++ b/src/util.ts @@ -166,27 +166,3 @@ export function formatAsUTCISO( return resultString; } - -/** - * Attempts to retrieve package.json from either the typescript or build context. - * @returns {object} object representation of package.json - */ -export function getPackageJSON(): ReturnType { - let packageJson: ReturnType = undefined; - const possiblePaths = ['../../package.json', '../package.json']; - - for (const path of possiblePaths) { - try { - packageJson = require(path); - break; - } catch { - packageJson = undefined; - } - } - - if (packageJson) { - return packageJson; - } - - throw new Error('Unable to find package.json'); -} diff --git a/system-test/storage.ts b/system-test/storage.ts index 6d64a78a5..19bb9a489 100644 --- a/system-test/storage.ts +++ b/system-test/storage.ts @@ -58,7 +58,6 @@ describe('storage', () => { const USER_ACCOUNT = 'user-spsawchuk@gmail.com'; const TESTS_PREFIX = `storage-tests-${shortUUID()}-`; const RETENTION_DURATION_SECONDS = 10; - const DATA_ROOT = path.join(__dirname, 'data'); const storage = new Storage({ retryOptions: {idempotencyStrategy: IdempotencyStrategy.RetryAlways}, @@ -73,14 +72,17 @@ describe('storage', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const FILES: {[index: string]: any} = { logo: { - path: path.join(DATA_ROOT, 'CloudPlatform_128px_Retina.png'), + path: path.join( + __dirname, + '../../system-test/data/CloudPlatform_128px_Retina.png' + ), }, big: { - path: path.join(DATA_ROOT, 'three-mb-file.tif'), + path: path.join(__dirname, '../../system-test/data/three-mb-file.tif'), hash: undefined, }, html: { - path: path.join(DATA_ROOT, 'long-html-file.html'), + path: path.join(__dirname, '../../system-test/data/long-html-file.html'), }, }; diff --git a/test/acl.ts b/test/acl.ts index 5cdb79234..9339b6377 100644 --- a/test/acl.ts +++ b/test/acl.ts @@ -43,7 +43,7 @@ describe('storage/acl', () => { const ENTITY = 'user-user@example.com'; before(() => { - const aclModule = proxyquire('../src/acl.ts', { + const aclModule = proxyquire('../src/acl.js', { '@google-cloud/promisify': fakePromisify, }); Acl = aclModule.Acl; diff --git a/test/bucket.ts b/test/bucket.ts index eae482be6..1129b2d33 100644 --- a/test/bucket.ts +++ b/test/bucket.ts @@ -201,7 +201,7 @@ describe('Bucket', () => { const BUCKET_NAME = 'test-bucket'; before(() => { - Bucket = proxyquire('../src/bucket.ts', { + Bucket = proxyquire('../src/bucket.js', { fs: fakeFs, 'p-limit': fakePLimit, '@google-cloud/promisify': fakePromisify, @@ -210,11 +210,11 @@ describe('Bucket', () => { ServiceObject: FakeServiceObject, util: fakeUtil, }, - './acl.ts': {Acl: FakeAcl}, - './file.ts': {File: FakeFile}, - './iam.ts': {Iam: FakeIam}, - './notification.ts': {Notification: FakeNotification}, - './signer.ts': fakeSigner, + './acl.js': {Acl: FakeAcl}, + './file.js': {File: FakeFile}, + './iam.js': {Iam: FakeIam}, + './notification.js': {Notification: FakeNotification}, + './signer.js': fakeSigner, }).Bucket; }); @@ -2607,7 +2607,7 @@ describe('Bucket', () => { describe('upload', () => { const basename = 'testfile.json'; - const filepath = path.join(__dirname, 'testdata', basename); + const filepath = path.join(__dirname, '../../test/testdata/' + basename); const metadata = { metadata: { a: 'b', diff --git a/test/channel.ts b/test/channel.ts index 701187fdb..e14d4ed1f 100644 --- a/test/channel.ts +++ b/test/channel.ts @@ -54,7 +54,7 @@ describe('Channel', () => { let channel: any; before(() => { - Channel = proxyquire('../src/channel.ts', { + Channel = proxyquire('../src/channel.js', { '@google-cloud/promisify': fakePromisify, './nodejs-common': { ServiceObject: FakeServiceObject, diff --git a/test/file.ts b/test/file.ts index 2e8ddda63..01e935604 100644 --- a/test/file.ts +++ b/test/file.ts @@ -205,7 +205,7 @@ describe('File', () => { let BUCKET: any; before(() => { - File = proxyquire('../src/file.ts', { + File = proxyquire('../src/file.js', { './nodejs-common': { ServiceObject: FakeServiceObject, util: fakeUtil, diff --git a/test/gcs-resumable-upload.ts b/test/gcs-resumable-upload.ts index f28222d77..6369d30ea 100644 --- a/test/gcs-resumable-upload.ts +++ b/test/gcs-resumable-upload.ts @@ -107,7 +107,7 @@ describe('gcs-resumable-upload', () => { retryableErrorFn: RETRYABLE_ERR_FN_DEFAULT, }; let REQ_OPTS: GaxiosOptions; - const keyFile = path.join(__dirname, 'fixtures', 'keys.json'); + const keyFile = path.join(__dirname, '../../test/fixtures/keys.json'); before(() => { mockery.registerMock('abort-controller', {default: AbortController}); diff --git a/test/iam.ts b/test/iam.ts index 2e3cd11c4..6d4c693be 100644 --- a/test/iam.ts +++ b/test/iam.ts @@ -37,7 +37,7 @@ describe('storage/iam', () => { }; before(() => { - Iam = proxyquire('../src/iam.ts', { + Iam = proxyquire('../src/iam.js', { '@google-cloud/promisify': fakePromisify, }).Iam; }); diff --git a/test/index.ts b/test/index.ts index 3ae0a6d08..782fb9e61 100644 --- a/test/index.ts +++ b/test/index.ts @@ -103,7 +103,7 @@ describe('Storage', () => { './nodejs-common': { Service: FakeService, }, - './channel.ts': {Channel: FakeChannel}, + './channel.js': {Channel: FakeChannel}, './hmacKey': hmacKeyModule, }).Storage; Bucket = Storage.Bucket; @@ -145,7 +145,7 @@ describe('Storage', () => { assert.deepStrictEqual( calledWith.packageJson, // eslint-disable-next-line @typescript-eslint/no-var-requires - require('../package.json') + require('../../package.json') ); }); diff --git a/test/notification.ts b/test/notification.ts index b9812a969..e986f69db 100644 --- a/test/notification.ts +++ b/test/notification.ts @@ -56,7 +56,7 @@ describe('Notification', () => { const ID = '123'; before(() => { - Notification = proxyquire('../src/notification.ts', { + Notification = proxyquire('../src/notification.js', { '@google-cloud/promisify': fakePromisify, './nodejs-common': { ServiceObject: FakeServiceObject,