Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 1d0ea7d

Browse files
fix: revert native typescript mocha tests (#1947)
* fix: revert native typescript mocha tests * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 7ea4ec6 commit 1d0ea7d

16 files changed

Lines changed: 41 additions & 64 deletions

File tree

conformance-test/libraryMethods.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ export async function bucketUploadResumable(bucket: Bucket) {
183183
bucket.instancePreconditionOpts.ifGenerationMatch = 0;
184184
}
185185
await bucket.upload(
186-
path.join(__dirname, 'test-data', 'retryStrategyTestData.json'),
186+
path.join(
187+
__dirname,
188+
'../../conformance-test/test-data/retryStrategyTestData.json'
189+
),
187190
{resumable: true}
188191
);
189192
}
@@ -194,7 +197,10 @@ export async function bucketUploadMultipart(bucket: Bucket) {
194197
bucket.instancePreconditionOpts.ifGenerationMatch = 0;
195198
}
196199
await bucket.upload(
197-
path.join(__dirname, 'test-data', 'retryStrategyTestData.json'),
200+
path.join(
201+
__dirname,
202+
'../../conformance-test/test-data/retryStrategyTestData.json'
203+
),
198204
{resumable: false}
199205
);
200206
}

conformance-test/v4SignedUrl.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ interface BucketAction {
8888
}
8989

9090
const testFile = fs.readFileSync(
91-
path.join(__dirname, 'test-data', 'v4SignedUrl.json'),
91+
path.join(__dirname, '../../conformance-test/test-data/v4SignedUrl.json'),
9292
'utf-8'
9393
);
9494

@@ -100,8 +100,7 @@ const v4SignedPolicyCases: V4SignedPolicyTestCase[] =
100100

101101
const SERVICE_ACCOUNT = path.join(
102102
__dirname,
103-
'fixtures',
104-
'signing-service-account.json'
103+
'../../conformance-test/fixtures/signing-service-account.json'
105104
);
106105

107106
const storage = new Storage({keyFilename: SERVICE_ACCOUNT});

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@
2626
"google storage",
2727
"storage"
2828
],
29-
"mocha": {
30-
"require": "ts-node/register",
31-
"extension": "ts"
32-
},
3329
"scripts": {
3430
"predocs": "npm run compile",
3531
"docs": "jsdoc -c .jsdoc.js",
36-
"system-test": "mocha system-test --timeout 600000 --exit",
37-
"conformance-test": "mocha --parallel --require ts-node/register --require conformance-test/globalHooks.ts conformance-test/",
38-
"test": "c8 mocha test",
32+
"system-test": "mocha build/system-test --timeout 600000 --exit",
33+
"conformance-test": "mocha --parallel build/conformance-test/ --require build/conformance-test/globalHooks.js",
34+
"preconformance-test": "npm run compile",
35+
"presystem-test": "npm run compile",
36+
"test": "c8 mocha build/test",
37+
"pretest": "npm run compile",
3938
"lint": "gts check",
4039
"samples-test": "npm link && cd samples/ && npm link ../ && npm test && cd ../",
4140
"all-test": "npm test && npm run system-test && npm run samples-test",
@@ -111,7 +110,6 @@
111110
"proxyquire": "^2.1.3",
112111
"sinon": "^14.0.0",
113112
"tmp": "^0.2.0",
114-
"ts-node": "^10.7.0",
115113
"typescript": "~3.9.10",
116114
"uuid": "^8.0.0",
117115
"yargs": "^16.0.0"

src/gcs-resumable-upload.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ import {Readable, Writable} from 'stream';
2828
import retry = require('async-retry');
2929
import {RetryOptions, PreconditionOptions} from './storage';
3030
import * as uuid from 'uuid';
31-
import {getPackageJSON} from './util';
3231

3332
const NOT_FOUND_STATUS_CODE = 404;
3433
const TERMINATED_UPLOAD_STATUS_CODE = 410;
3534
const RESUMABLE_INCOMPLETE_STATUS_CODE = 308;
3635
const DEFAULT_API_ENDPOINT_REGEX = /.*\.googleapis\.com/;
37-
const packageJson = getPackageJSON();
36+
const packageJson = require('../../package.json');
3837

3938
export const PROTOCOL_REGEX = /^(\w*):\/\//;
4039

src/nodejs-common/util.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ import {Duplex, DuplexOptions, Readable, Transform, Writable} from 'stream';
2929
import {teenyRequest} from 'teeny-request';
3030
import {Interceptor} from './service-object';
3131
import * as uuid from 'uuid';
32-
import {getPackageJSON} from '../util';
33-
const packageJson = getPackageJSON();
32+
const packageJson = require('../../../package.json');
3433

3534
// eslint-disable-next-line @typescript-eslint/no-var-requires
3635
const duplexify: DuplexifyConstructor = require('duplexify');

src/storage.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {Readable} from 'stream';
2121
import {Bucket} from './bucket';
2222
import {Channel} from './channel';
2323
import {File} from './file';
24-
import {getPackageJSON, normalize} from './util';
24+
import {normalize} from './util';
2525
import {HmacKey, HmacKeyMetadata, HmacKeyOptions} from './hmacKey';
2626

2727
export interface GetServiceAccountOptions {
@@ -614,8 +614,6 @@ export class Storage extends Service {
614614
maxRetryValue = options.retryOptions.maxRetries;
615615
}
616616

617-
const packageJson = getPackageJSON();
618-
619617
const config = {
620618
apiEndpoint: options.apiEndpoint!,
621619
retryOptions: {
@@ -647,7 +645,7 @@ export class Storage extends Service {
647645
'https://www.googleapis.com/auth/cloud-platform',
648646
'https://www.googleapis.com/auth/devstorage.full_control',
649647
],
650-
packageJson,
648+
packageJson: require('../../package.json'),
651649
};
652650

653651
super(config, options);

src/util.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -166,27 +166,3 @@ export function formatAsUTCISO(
166166

167167
return resultString;
168168
}
169-
170-
/**
171-
* Attempts to retrieve package.json from either the typescript or build context.
172-
* @returns {object} object representation of package.json
173-
*/
174-
export function getPackageJSON(): ReturnType<JSON['parse']> {
175-
let packageJson: ReturnType<JSON['parse']> = undefined;
176-
const possiblePaths = ['../../package.json', '../package.json'];
177-
178-
for (const path of possiblePaths) {
179-
try {
180-
packageJson = require(path);
181-
break;
182-
} catch {
183-
packageJson = undefined;
184-
}
185-
}
186-
187-
if (packageJson) {
188-
return packageJson;
189-
}
190-
191-
throw new Error('Unable to find package.json');
192-
}

system-test/storage.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ describe('storage', () => {
5858
const USER_ACCOUNT = 'user-spsawchuk@gmail.com';
5959
const TESTS_PREFIX = `storage-tests-${shortUUID()}-`;
6060
const RETENTION_DURATION_SECONDS = 10;
61-
const DATA_ROOT = path.join(__dirname, 'data');
6261

6362
const storage = new Storage({
6463
retryOptions: {idempotencyStrategy: IdempotencyStrategy.RetryAlways},
@@ -73,14 +72,17 @@ describe('storage', () => {
7372
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7473
const FILES: {[index: string]: any} = {
7574
logo: {
76-
path: path.join(DATA_ROOT, 'CloudPlatform_128px_Retina.png'),
75+
path: path.join(
76+
__dirname,
77+
'../../system-test/data/CloudPlatform_128px_Retina.png'
78+
),
7779
},
7880
big: {
79-
path: path.join(DATA_ROOT, 'three-mb-file.tif'),
81+
path: path.join(__dirname, '../../system-test/data/three-mb-file.tif'),
8082
hash: undefined,
8183
},
8284
html: {
83-
path: path.join(DATA_ROOT, 'long-html-file.html'),
85+
path: path.join(__dirname, '../../system-test/data/long-html-file.html'),
8486
},
8587
};
8688

test/acl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('storage/acl', () => {
4343
const ENTITY = 'user-user@example.com';
4444

4545
before(() => {
46-
const aclModule = proxyquire('../src/acl.ts', {
46+
const aclModule = proxyquire('../src/acl.js', {
4747
'@google-cloud/promisify': fakePromisify,
4848
});
4949
Acl = aclModule.Acl;

test/bucket.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ describe('Bucket', () => {
201201
const BUCKET_NAME = 'test-bucket';
202202

203203
before(() => {
204-
Bucket = proxyquire('../src/bucket.ts', {
204+
Bucket = proxyquire('../src/bucket.js', {
205205
fs: fakeFs,
206206
'p-limit': fakePLimit,
207207
'@google-cloud/promisify': fakePromisify,
@@ -210,11 +210,11 @@ describe('Bucket', () => {
210210
ServiceObject: FakeServiceObject,
211211
util: fakeUtil,
212212
},
213-
'./acl.ts': {Acl: FakeAcl},
214-
'./file.ts': {File: FakeFile},
215-
'./iam.ts': {Iam: FakeIam},
216-
'./notification.ts': {Notification: FakeNotification},
217-
'./signer.ts': fakeSigner,
213+
'./acl.js': {Acl: FakeAcl},
214+
'./file.js': {File: FakeFile},
215+
'./iam.js': {Iam: FakeIam},
216+
'./notification.js': {Notification: FakeNotification},
217+
'./signer.js': fakeSigner,
218218
}).Bucket;
219219
});
220220

@@ -2607,7 +2607,7 @@ describe('Bucket', () => {
26072607

26082608
describe('upload', () => {
26092609
const basename = 'testfile.json';
2610-
const filepath = path.join(__dirname, 'testdata', basename);
2610+
const filepath = path.join(__dirname, '../../test/testdata/' + basename);
26112611
const metadata = {
26122612
metadata: {
26132613
a: 'b',

0 commit comments

Comments
 (0)