Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/presubmit-bun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
run: pnpm run compile
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.3.14
bun-version: latest
- run: bun --version
- run: bash ci/run_conditional_tests.sh --strict
name: Run unit tests with Bun
Expand Down
5 changes: 4 additions & 1 deletion ci/run_conditional_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,12 @@ for subdir in ${subdirs[@]}; do
echo "run samples tests for core/packages in ${d}"
should_test=true
fi
elif [[ "${TEST_TYPE}" == "lint" ]] || [[ "${TEST_TYPE}" == "units" ]]; then
echo "change detected in ${d} for ${TEST_TYPE} test"
should_test=true
elif [[ "${d}" == core/packages/* ]] || [[ "${d}" == core/dev-packages/* ]]; then
echo "skipping core package ${d} in non-core trigger"
elif [[ "${TEST_TYPE}" == "system" ]] || [[ "${TEST_TYPE}" == "lint" ]] || [[ "${TEST_TYPE}" == "units" ]]; then
elif [[ "${TEST_TYPE}" == "system" ]]; then
echo "change detected in ${d} for ${TEST_TYPE} test"
should_test=true
Comment on lines +223 to 230

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Placing the lint and units test checks above the core package skip check bypasses the skip logic for those test types in non-core triggers. This will cause core packages to run unit and lint tests unnecessarily during non-core trigger builds, wasting CI resources. Keep the core package skip check at the top of the conditional block.

Suggested change
elif [[ "${TEST_TYPE}" == "lint" ]] || [[ "${TEST_TYPE}" == "units" ]]; then
echo "change detected in ${d} for ${TEST_TYPE} test"
should_test=true
elif [[ "${d}" == core/packages/* ]] || [[ "${d}" == core/dev-packages/* ]]; then
echo "skipping core package ${d} in non-core trigger"
elif [[ "${TEST_TYPE}" == "system" ]] || [[ "${TEST_TYPE}" == "lint" ]] || [[ "${TEST_TYPE}" == "units" ]]; then
elif [[ "${TEST_TYPE}" == "system" ]]; then
echo "change detected in ${d} for ${TEST_TYPE} test"
should_test=true
elif [[ "${d}" == core/packages/* ]] || [[ "${d}" == core/dev-packages/* ]]; then
echo "skipping core package ${d} in non-core trigger"
elif [[ "${TEST_TYPE}" == "system" ]] || [[ "${TEST_TYPE}" == "lint" ]] || [[ "${TEST_TYPE}" == "units" ]]; then
echo "change detected in ${d} for ${TEST_TYPE} test"
should_test=true

elif [[ "${tests_with_credentials[*]}" =~ "${d}" ]] && [[ -n "${GOOGLE_APPLICATION_CREDENTIALS}" ]]; then
Expand Down
6 changes: 5 additions & 1 deletion ci/run_single_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ system)
retval=$?
;;
units)
${TEST_CMD} test
if [[ "${TEST_CMD}" == *"bun"* ]] && grep -q '"test:bun"' package.json; then
${TEST_CMD} test:bun
else
${TEST_CMD} test
fi
retval=$?
;;
*)
Expand Down
2 changes: 2 additions & 0 deletions core/paginator/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
root = "./test"
5 changes: 4 additions & 1 deletion core/paginator/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
// limitations under the License.

module.exports = {
testMatch: ['<rootDir>/test/**/*.ts'],
testMatch: ['<rootDir>/test/**/*.test.ts'],
transform: {
'^.+\\.tsx?$': ['ts-jest', {tsconfig: 'tsconfig.json'}],
},
moduleNameMapper: {
'^bun:test$': '<rootDir>/test/bun-test-shim.ts',
},
clearMocks: true,
};
1 change: 1 addition & 0 deletions core/paginator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"url": "https://github.com/googleapis/google-cloud-node.git"
},
"scripts": {
"test:bun": "bun test",
"test": "jest --coverage",
"compile": "tsc -p .",
"fix": "gts fix",
Expand Down
6 changes: 4 additions & 2 deletions core/paginator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
* @module common/paginator
*/

import * as extend from 'extend';
import * as extendMod from 'extend';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const extend: typeof extendMod = (extendMod as any).default || extendMod;
import {TransformOptions} from 'stream';
import {ResourceStream} from './resource-stream';

Expand Down Expand Up @@ -236,7 +238,7 @@ export class Paginator {
if (!callback) {
return promise.then(results => [results, query, ...otherArgs]);
}
promise.then(
return promise.then(
results => callback(null, results, query, ...otherArgs),
(err: Error) => callback(err),
);
Comment on lines +241 to 244

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Returning the promise when a callback is provided can lead to unhandled promise rejections if the callback throws an error. Since callers using callbacks do not typically catch returned promises, any synchronous error thrown inside the callback will reject the returned promise and go unhandled. Use the void operator to discard the promise instead of returning it. Additionally, avoid wrapping the callback in an arrow function for the error case to prevent unnecessary closure allocations.

Suggested change
return promise.then(
results => callback(null, results, query, ...otherArgs),
(err: Error) => callback(err),
);
void promise.then(
results => callback(null, results, query, ...otherArgs),
callback,
);
References
  1. Avoid wrapping methods in arrow functions for default cases to prevent unnecessary closure allocations and extra call stack frames.

Expand Down
39 changes: 39 additions & 0 deletions core/paginator/test/bun-test-shim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/* eslint-disable @typescript-eslint/no-explicit-any, import/no-extraneous-dependencies, n/no-extraneous-import */
import {jest} from '@jest/globals';

export const describe = (globalThis as any).describe;
export const it = (globalThis as any).it;
export const test = (globalThis as any).test;
export const expect = (globalThis as any).expect;
export const beforeEach = (globalThis as any).beforeEach;
export const afterEach = (globalThis as any).afterEach;
export const beforeAll = (globalThis as any).beforeAll;
export const afterAll = (globalThis as any).afterAll;

export const mock: any = Object.assign(
(...args: any[]) => (jest.fn as any)(...args),
{
module: (moduleName: string, factory: () => any) => {
jest.mock(moduleName, factory);
},
restore: () => jest.restoreAllMocks(),
},
);

export const spyOn: any = (obj: any, method: any) => jest.spyOn(obj, method);
export type Mock = any;
export {jest};
52 changes: 52 additions & 0 deletions core/paginator/test/bun-test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
declare module 'bun:test' {
export type DoneCallback = (err?: any) => void;
export function describe(name: string, fn: () => void): void;
export namespace describe {
export function only(name: string, fn: () => void): void;
export function skip(name: string, fn: () => void): void;
}
export function it(name: string, fn: (done: DoneCallback) => any): void;
export namespace it {
export function only(name: string, fn: (done: DoneCallback) => any): void;
export function skip(name: string, fn: (done: DoneCallback) => any): void;
}
export function test(name: string, fn: (done: DoneCallback) => any): void;
export namespace test {
export function only(name: string, fn: (done: DoneCallback) => any): void;
export function skip(name: string, fn: (done: DoneCallback) => any): void;
}
export function beforeEach(fn: (done: DoneCallback) => any): void;
export function afterEach(fn: (done: DoneCallback) => any): void;
export function beforeAll(fn: (done: DoneCallback) => any): void;
export function afterAll(fn: (done: DoneCallback) => any): void;
export const expect: any;
export function mock<T extends (...args: any[]) => any = (...args: any[]) => any>(
fn?: T
): Mock<T>;
export namespace mock {
export function module(moduleName: string, factory: () => any): void;
export function restore(): void;
}
export function spyOn(obj: any, method: any): Mock<any>;
export const jest: any;
export interface Mock<
T extends (...args: any[]) => any = (...args: any[]) => any,
> {
(...args: Parameters<T>): ReturnType<T>;
mock: {
calls: any[];
results: {type: string; value: any}[];
lastCall?: any;
};
mockImplementation(
fn?: (a?: any, b?: any, c?: any, d?: any, ...args: any[]) => any
): this;
mockReturnValue(val: any): this;
mockResolvedValue(val: any): this;
mockRejectedValue(val: any): this;
mockRestore(): void;
mockClear(): void;
mockReset(): void;
}
}
Loading
Loading