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: small esm fixes and add esm-system tests #1475

Merged
merged 20 commits into from
Oct 20, 2023
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
35 changes: 35 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,41 @@ jobs:
npm run compile
npm run system-test
npm run docs
lib-tests-esm:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
lib-name: [showcase, kms, translate, monitoring, dlp, texttospeech, showcase-legacy, compute, logging]
steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
path: ~/artifacts

- name: Prepare ${{ matrix.lib-name }}-esm library to test
run: |
unzip ~/artifacts/outputs.zip '.test-out-${{ matrix.lib-name }}-esm/*' -d library
mv library/.test-out-${{ matrix.lib-name }}-esm library/${{ matrix.lib-name }}-esm

- name: Test ${{ matrix.lib-name }} library
run: |
cd library/${{ matrix.lib-name }}-esm
pwd
npm install
npm test
npm run fix
# Second compile to make sure "gts fix" did not break the code, it happens!
rm -rf build
npm run compile
npm run system-test
lint:
runs-on: ubuntu-latest
steps:
Expand Down
19 changes: 19 additions & 0 deletions baselines/asset-esm/.babelrc.json.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"presets": [
"@babel/preset-typescript",
"@babel/env"
],
"plugins": [
[
"replace-import-extension",
{
"extMapping": {
".js": ".cjs"
}
}
],
"./node_modules/gapic-tools/build/src/replaceESMMockingLib.js",
"./node_modules/gapic-tools/build/src/replaceImportMetaUrl.js",
"./node_modules/gapic-tools/build/src/toggleESMFlagVariable.js"
]
}
6 changes: 5 additions & 1 deletion baselines/asset-esm/.eslintignore.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ build/
docs/
protos/
system-test/
samples/generated/
samples/
esm/src/**/*.d.ts
esm/test/**/*.d.ts
esm/system-test/**/*.d.ts
esm/system-test/fixtures/sample/src/*.ts
4 changes: 2 additions & 2 deletions baselines/asset-esm/esm/system-test/install.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('📦 pack-n-play test', () => {
packageDir: process.cwd(),
sample: {
description: 'TypeScript user can use the type definitions',
ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString()
ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString()
}
};
await packNTest(options);
Expand All @@ -40,7 +40,7 @@ describe('📦 pack-n-play test', () => {
packageDir: process.cwd(),
sample: {
description: 'JavaScript user can use the library',
ts: readFileSync('./system-test/fixtures/sample/src/index.js').toString()
ts: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString()
}
};
await packNTest(options);
Expand Down
48 changes: 24 additions & 24 deletions baselines/asset-esm/esm/test/gapic_asset_service_v1.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const root = protobuf.Root.fromJSON(
function getTypeDefaultValue(typeName: string, fields: string[]) {
let type = root.lookupType(typeName) as protobuf.Type;
for (const field of fields.slice(0, -1)) {
type = type.fields[field]?.resolvedType as protobuf.Type;
type = type?.fields[field]?.resolvedType as protobuf.Type;
}
return type.fields[fields[fields.length - 1]]?.defaultValue;
return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null;
}

function generateSampleMessage<T extends object>(instance: T) {
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.BatchGetAssetsHistoryRequest', ['parent']);
request.parent = defaultValue1;
const expectedHeaderRequestParams = `parent=${defaultValue1}`;
const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.asset.v1.BatchGetAssetsHistoryResponse()
);
Expand All @@ -213,7 +213,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.BatchGetAssetsHistoryRequest', ['parent']);
request.parent = defaultValue1;
const expectedHeaderRequestParams = `parent=${defaultValue1}`;
const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.asset.v1.BatchGetAssetsHistoryResponse()
);
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.BatchGetAssetsHistoryRequest', ['parent']);
request.parent = defaultValue1;
const expectedHeaderRequestParams = `parent=${defaultValue1}`;
const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;
const expectedError = new Error('expected');
client.innerApiCalls.batchGetAssetsHistory = stubSimpleCall(undefined, expectedError);
await assert.rejects(client.batchGetAssetsHistory(request), expectedError);
Expand Down Expand Up @@ -294,7 +294,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.CreateFeedRequest', ['parent']);
request.parent = defaultValue1;
const expectedHeaderRequestParams = `parent=${defaultValue1}`;
const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.asset.v1.Feed()
);
Expand All @@ -321,7 +321,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.CreateFeedRequest', ['parent']);
request.parent = defaultValue1;
const expectedHeaderRequestParams = `parent=${defaultValue1}`;
const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.asset.v1.Feed()
);
Expand Down Expand Up @@ -359,7 +359,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.CreateFeedRequest', ['parent']);
request.parent = defaultValue1;
const expectedHeaderRequestParams = `parent=${defaultValue1}`;
const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;
const expectedError = new Error('expected');
client.innerApiCalls.createFeed = stubSimpleCall(undefined, expectedError);
await assert.rejects(client.createFeed(request), expectedError);
Expand Down Expand Up @@ -402,7 +402,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.GetFeedRequest', ['name']);
request.name = defaultValue1;
const expectedHeaderRequestParams = `name=${defaultValue1}`;
const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.asset.v1.Feed()
);
Expand All @@ -429,7 +429,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.GetFeedRequest', ['name']);
request.name = defaultValue1;
const expectedHeaderRequestParams = `name=${defaultValue1}`;
const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.asset.v1.Feed()
);
Expand Down Expand Up @@ -467,7 +467,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.GetFeedRequest', ['name']);
request.name = defaultValue1;
const expectedHeaderRequestParams = `name=${defaultValue1}`;
const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;
const expectedError = new Error('expected');
client.innerApiCalls.getFeed = stubSimpleCall(undefined, expectedError);
await assert.rejects(client.getFeed(request), expectedError);
Expand Down Expand Up @@ -510,7 +510,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.ListFeedsRequest', ['parent']);
request.parent = defaultValue1;
const expectedHeaderRequestParams = `parent=${defaultValue1}`;
const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.asset.v1.ListFeedsResponse()
);
Expand All @@ -537,7 +537,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.ListFeedsRequest', ['parent']);
request.parent = defaultValue1;
const expectedHeaderRequestParams = `parent=${defaultValue1}`;
const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.asset.v1.ListFeedsResponse()
);
Expand Down Expand Up @@ -575,7 +575,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.ListFeedsRequest', ['parent']);
request.parent = defaultValue1;
const expectedHeaderRequestParams = `parent=${defaultValue1}`;
const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;
const expectedError = new Error('expected');
client.innerApiCalls.listFeeds = stubSimpleCall(undefined, expectedError);
await assert.rejects(client.listFeeds(request), expectedError);
Expand Down Expand Up @@ -619,7 +619,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.UpdateFeedRequest', ['feed', 'name']);
request.feed.name = defaultValue1;
const expectedHeaderRequestParams = `feed.name=${defaultValue1}`;
const expectedHeaderRequestParams = `feed.name=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.asset.v1.Feed()
);
Expand Down Expand Up @@ -647,7 +647,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.UpdateFeedRequest', ['feed', 'name']);
request.feed.name = defaultValue1;
const expectedHeaderRequestParams = `feed.name=${defaultValue1}`;
const expectedHeaderRequestParams = `feed.name=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.asset.v1.Feed()
);
Expand Down Expand Up @@ -686,7 +686,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.UpdateFeedRequest', ['feed', 'name']);
request.feed.name = defaultValue1;
const expectedHeaderRequestParams = `feed.name=${defaultValue1}`;
const expectedHeaderRequestParams = `feed.name=${defaultValue1 ?? '' }`;
const expectedError = new Error('expected');
client.innerApiCalls.updateFeed = stubSimpleCall(undefined, expectedError);
await assert.rejects(client.updateFeed(request), expectedError);
Expand Down Expand Up @@ -730,7 +730,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.DeleteFeedRequest', ['name']);
request.name = defaultValue1;
const expectedHeaderRequestParams = `name=${defaultValue1}`;
const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.protobuf.Empty()
);
Expand All @@ -757,7 +757,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.DeleteFeedRequest', ['name']);
request.name = defaultValue1;
const expectedHeaderRequestParams = `name=${defaultValue1}`;
const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.protobuf.Empty()
);
Expand Down Expand Up @@ -795,7 +795,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.DeleteFeedRequest', ['name']);
request.name = defaultValue1;
const expectedHeaderRequestParams = `name=${defaultValue1}`;
const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;
const expectedError = new Error('expected');
client.innerApiCalls.deleteFeed = stubSimpleCall(undefined, expectedError);
await assert.rejects(client.deleteFeed(request), expectedError);
Expand Down Expand Up @@ -838,7 +838,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.ExportAssetsRequest', ['parent']);
request.parent = defaultValue1;
const expectedHeaderRequestParams = `parent=${defaultValue1}`;
const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.longrunning.Operation()
);
Expand Down Expand Up @@ -866,7 +866,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.ExportAssetsRequest', ['parent']);
request.parent = defaultValue1;
const expectedHeaderRequestParams = `parent=${defaultValue1}`;
const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.longrunning.Operation()
);
Expand Down Expand Up @@ -907,7 +907,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.ExportAssetsRequest', ['parent']);
request.parent = defaultValue1;
const expectedHeaderRequestParams = `parent=${defaultValue1}`;
const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;
const expectedError = new Error('expected');
client.innerApiCalls.exportAssets = stubLongRunningCall(undefined, expectedError);
await assert.rejects(client.exportAssets(request), expectedError);
Expand All @@ -931,7 +931,7 @@ describe('v1.AssetServiceClient', () => {
const defaultValue1 =
getTypeDefaultValue('.google.cloud.asset.v1.ExportAssetsRequest', ['parent']);
request.parent = defaultValue1;
const expectedHeaderRequestParams = `parent=${defaultValue1}`;
const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;
const expectedError = new Error('expected');
client.innerApiCalls.exportAssets = stubLongRunningCall(undefined, undefined, expectedError);
const [operation] = await client.exportAssets(request);
Expand Down
11 changes: 7 additions & 4 deletions baselines/asset-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"scripts": {
"clean": "gts clean",
"compile-protos": "compileProtos esm/src --esm ",
"docs": "jsdoc -c .jsdoc.js",
"docs": "jsdoc -c .jsdoc.cjs",
"postpack": "minifyProtoJson build/cjs && minifyProtoJson build/esm",
"predocs-test": "npm run docs",
"docs-test": "linkinator docs",
Expand All @@ -55,9 +55,10 @@
"test:esm": "c8 mocha build/esm/test",
"test": "npm run test:cjs && npm run test:esm",
"compile:esm": "tsc -p ./tsconfig.esm.json",
"babel": "babel esm --out-dir build/cjs --extensions \".ts\" --out-file-extension .cjs --copy-files",
"babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files",
"compile:cjs": "tsc -p ./tsconfig.json && npm run babel",
"compile": "npm run compile:esm && npm run compile:cjs && cp -r protos build/protos"
"compile": "npm run compile:esm && npm run compile:cjs && cp -r protos build/protos",
"samples-test": "cd samples/ && npm link ../ && npm i && npm test"
},
"dependencies": {
"google-gax": "^4.0.4"
Expand All @@ -70,12 +71,14 @@
"@types/mocha": "^10.0.2",
"@types/node": "^18.11.18",
"@types/sinon": "^10.0.19",
"babel-plugin-replace-import-extension": "^1.1.3",
"c8": "^8.0.1",
"gapic-tools": "^0.2.0",
"gts": "5.2.0",
"gts": "^5.2.0",
"jsdoc": "^4.0.2",
"jsdoc-region-tag": "^3.0.0",
"jsdoc-fresh": "^3.0.0",
"long": "^5.2.3",
"mocha": "^10.2.0",
"pack-n-play": "^1.0.0-2",
"sinon": "^15.2.0",
Expand Down
19 changes: 19 additions & 0 deletions baselines/bigquery-storage-esm/.babelrc.json.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"presets": [
"@babel/preset-typescript",
"@babel/env"
],
"plugins": [
[
"replace-import-extension",
{
"extMapping": {
".js": ".cjs"
}
}
],
"./node_modules/gapic-tools/build/src/replaceESMMockingLib.js",
"./node_modules/gapic-tools/build/src/replaceImportMetaUrl.js",
"./node_modules/gapic-tools/build/src/toggleESMFlagVariable.js"
]
}
6 changes: 5 additions & 1 deletion baselines/bigquery-storage-esm/.eslintignore.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ build/
docs/
protos/
system-test/
samples/generated/
samples/
esm/src/**/*.d.ts
esm/test/**/*.d.ts
esm/system-test/**/*.d.ts
esm/system-test/fixtures/sample/src/*.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('📦 pack-n-play test', () => {
packageDir: process.cwd(),
sample: {
description: 'TypeScript user can use the type definitions',
ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString()
ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString()
}
};
await packNTest(options);
Expand All @@ -40,7 +40,7 @@ describe('📦 pack-n-play test', () => {
packageDir: process.cwd(),
sample: {
description: 'JavaScript user can use the library',
ts: readFileSync('./system-test/fixtures/sample/src/index.js').toString()
ts: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString()
}
};
await packNTest(options);
Expand Down
Loading
Loading