Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert native typescript mocha tests #1947

Merged
merged 2 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions conformance-test/libraryMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
);
}
Expand All @@ -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}
);
}
Expand Down
5 changes: 2 additions & 3 deletions conformance-test/v4SignedUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);

Expand All @@ -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});
Expand Down
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions src/gcs-resumable-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*):\/\//;

Expand Down
3 changes: 1 addition & 2 deletions src/nodejs-common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 2 additions & 4 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -614,8 +614,6 @@ export class Storage extends Service {
maxRetryValue = options.retryOptions.maxRetries;
}

const packageJson = getPackageJSON();

const config = {
apiEndpoint: options.apiEndpoint!,
retryOptions: {
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 0 additions & 24 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JSON['parse']> {
let packageJson: ReturnType<JSON['parse']> = 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');
}
10 changes: 6 additions & 4 deletions system-test/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ describe('storage', () => {
const USER_ACCOUNT = '[email protected]';
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},
Expand All @@ -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'),
},
};

Expand Down
2 changes: 1 addition & 1 deletion test/acl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('storage/acl', () => {
const ENTITY = '[email protected]';

before(() => {
const aclModule = proxyquire('../src/acl.ts', {
const aclModule = proxyquire('../src/acl.js', {
'@google-cloud/promisify': fakePromisify,
});
Acl = aclModule.Acl;
Expand Down
14 changes: 7 additions & 7 deletions test/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
});

Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion test/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/gcs-resumable-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
2 changes: 1 addition & 1 deletion test/iam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('storage/iam', () => {
};

before(() => {
Iam = proxyquire('../src/iam.ts', {
Iam = proxyquire('../src/iam.js', {
'@google-cloud/promisify': fakePromisify,
}).Iam;
});
Expand Down
4 changes: 2 additions & 2 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('Storage', () => {
'./nodejs-common': {
Service: FakeService,
},
'./channel.ts': {Channel: FakeChannel},
'./channel.js': {Channel: FakeChannel},
'./hmacKey': hmacKeyModule,
}).Storage;
Bucket = Storage.Bucket;
Expand Down Expand Up @@ -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')
);
});

Expand Down
2 changes: 1 addition & 1 deletion test/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down