Skip to content

Commit 3fd78b8

Browse files
committed
test: fix webpack config and tests
1 parent 195561c commit 3fd78b8

File tree

4 files changed

+56
-36
lines changed

4 files changed

+56
-36
lines changed

gax/test/browser-test/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
"@types/node": "^20.5.0",
2929
"@types/sinon": "^10.0.13",
3030
"assert": "^2.1.0",
31+
"browserify-zlib": "^0.2.0",
3132
"core-js": "^3.40.0",
33+
"crypto-browserify": "^3.12.1",
3234
"google-gax": "./google-gax.tgz",
3335
"https-browserify": "^1.0.0",
3436
"is-docker": "^2.2.1",
@@ -39,6 +41,8 @@
3941
"karma-sourcemap-loader": "^0.4.0",
4042
"karma-webpack": "^5.0.1",
4143
"mocha": "^10.0.0",
44+
"os-browserify": "^0.3.0",
45+
"path-browserify": "^1.0.1",
4246
"process": "^0.11.10",
4347
"puppeteer": "^16.0.0",
4448
"querystring-es3": "^0.2.1",

gax/test/browser-test/test/test.endtoend.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ function sleep(timeout: number) {
2828

2929
describe('Run tests against gRPC server', async function () {
3030
const authStub = {
31+
getRequestHeaders: async () => {
32+
return new Headers({
33+
Authorization: 'Bearer zzzz',
34+
});
35+
},
3136
getClient: async () => {
3237
return {
3338
getRequestHeaders: async () => {
34-
return {
39+
return new Headers({
3540
Authorization: 'Bearer zzzz',
36-
};
41+
});
3742
},
3843
};
3944
},
@@ -71,7 +76,7 @@ describe('Run tests against gRPC server', async function () {
7176
}
7277
if (retryCount === MAX_RETRIES) {
7378
throw new Error(
74-
`gapic-showcase server did not respond after ${MAX_RETRIES} attempts, aborting end-to-end browser tests`
79+
`gapic-showcase server did not respond after ${MAX_RETRIES} attempts, aborting end-to-end browser tests`,
7580
);
7681
}
7782
});

gax/test/browser-test/test/test.grpc-fallback.ts

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,13 @@ import {EchoClient} from 'showcase-echo-client';
2424
import 'core-js/stable';
2525

2626
import echoProtoJson = require('showcase-echo-client/build/protos/protos.json');
27+
import {PassThroughClient} from 'google-auth-library';
2728

28-
const authStub = {
29-
getClient: async () => {
30-
return {
31-
getRequestHeaders: async () => {
32-
return {
33-
Authorization: 'Bearer zzzz',
34-
};
35-
},
36-
};
37-
},
38-
};
29+
const authClient = new PassThroughClient();
30+
const auth = new GoogleAuth({authClient});
3931

4032
const opts = {
41-
auth: authStub as unknown as GoogleAuth,
33+
auth,
4234
};
4335

4436
describe('loadProto', () => {
@@ -128,20 +120,10 @@ describe('grpc-fallback', () => {
128120
// eslint-disable-next-line no-undef
129121
const savedAbortController = window.AbortController;
130122

131-
const authStub = {
132-
getClient: async () => {
133-
return {
134-
getRequestHeaders: async () => {
135-
return {
136-
Authorization: 'Bearer zzzz',
137-
};
138-
},
139-
};
140-
},
141-
};
142-
123+
const authClient = new PassThroughClient();
124+
const auth = new GoogleAuth({authClient});
143125
const opts = {
144-
auth: authStub as unknown as GoogleAuth,
126+
auth,
145127
protocol: 'http',
146128
port: 1337,
147129
};
@@ -198,7 +180,7 @@ describe('grpc-fallback', () => {
198180
ok: true,
199181
arrayBuffer: () => {
200182
return Promise.resolve(
201-
new TextEncoder().encode(JSON.stringify(response))
183+
new TextEncoder().encode(JSON.stringify(response)),
202184
);
203185
},
204186
});
@@ -238,12 +220,12 @@ describe('grpc-fallback', () => {
238220
// eslint-disable-next-line no-undef
239221
window.fetch = (url, options) => {
240222
// @ts-ignore
241-
assert.strictEqual(options.headers['x-test-header'], 'value');
223+
assert.strictEqual(options.headers.get('x-test-header'), 'value');
242224
return Promise.resolve({
243225
ok: true,
244226
arrayBuffer: () => {
245227
return Promise.resolve(
246-
new TextEncoder().encode(JSON.stringify(response))
228+
new TextEncoder().encode(JSON.stringify(response)),
247229
);
248230
},
249231
});
@@ -265,7 +247,7 @@ describe('grpc-fallback', () => {
265247
ok: false,
266248
arrayBuffer: () => {
267249
return Promise.resolve(
268-
new TextEncoder().encode(JSON.stringify(expectedError))
250+
new TextEncoder().encode(JSON.stringify(expectedError)),
269251
);
270252
},
271253
});

gax/test/browser-test/webpack.config.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,30 @@
1818
const webpack = require('webpack');
1919
module.exports = {
2020
entry: './build/src/index.js',
21+
externals: {
22+
crypto: '{}',
23+
'node:buffer': '{}',
24+
'node:fs': '{}',
25+
'node:http': '{}',
26+
'node:https': '{}',
27+
'node:net': '{}',
28+
'node:path': '{}',
29+
'node:process': '{}',
30+
'node:stream': '{}',
31+
'node:stream/web': '{}',
32+
'node:url': '{}',
33+
'node:util': '{}',
34+
'node:zlib': '{}',
35+
worker_threads: '{}',
36+
fs: '{}',
37+
child_process: '{}',
38+
tls: '{}',
39+
net: '{}',
40+
},
2141
resolve: {
42+
alias: {
43+
process: 'process/browser',
44+
},
2245
extensions: ['.ts', '.js', '.json'],
2346
fallback: {
2447
fs: 'empty',
@@ -31,9 +54,9 @@ module.exports = {
3154
https: require.resolve('https-browserify'),
3255
querystring: require.resolve('querystring-es3'),
3356
url: require.resolve('url/'),
34-
worker_threads: 'empty',
3557
crypto: require.resolve('crypto'),
36-
'process/browser': 'empty',
58+
os: require.resolve('os-browserify/browser'),
59+
path: require.resolve('path-browserify'),
3760
},
3861
},
3962
plugins: [
@@ -44,7 +67,7 @@ module.exports = {
4467
Buffer: ['buffer', 'Buffer'],
4568
}),
4669
new webpack.ProvidePlugin({
47-
'node:buffer': ['buffer', 'Buffer'],
70+
'node-fetch': ['fetch'],
4871
}),
4972
],
5073
module: {
@@ -59,7 +82,7 @@ module.exports = {
5982
use: 'null-loader',
6083
},
6184
{
62-
test: /node_modules[\\/]google-auth-library/,
85+
test: /node_modules[\\/]gcp-metadata/,
6386
use: 'null-loader',
6487
},
6588
{
@@ -70,6 +93,12 @@ module.exports = {
7093
test: /build[\\/]src[\\/]grpc\.js$/,
7194
use: 'null-loader',
7295
},
96+
{
97+
test: /\.m?js$/,
98+
resolve: {
99+
fullySpecified: false,
100+
},
101+
},
73102
],
74103
},
75104
cache: false,

0 commit comments

Comments
 (0)