Skip to content

Conversation

@dlarocque
Copy link
Contributor

@dlarocque dlarocque commented Jan 14, 2026

When using run_tests.ts (e.g., when running Firestore Lite tests), a noisy stack trace is output when tests fail. A stack trace isn't necessary in this case.

This modifies the script to only output a stack trace for real crashes, not test failures.

Before:

$ RUN_ENTERPRISE_TESTS=true yarn test:lite:prod --databaseId=enterprise --grep "Regex"
yarn run v1.22.11
$ ts-node ./scripts/run-tests.ts --platform node_lite --main=lite/index.ts 'test/lite/**/*.test.ts' --databaseId=enterprise --grep Regex

  Firestore Pipelines
    function expressions
      ✔ testRegexContains (55ms)
      1) testRegexFind
      ✔ testRegexMatches (65ms)

  2 passing (6s)
  1 failing

  1) Firestore Pipelines
       function expressions
         testRegexFind:
     Function field() called with invalid data. Invalid field path (.oo.). Paths must not be empty, begin with '.', end with '.', or contain '..'

ChildProcessError: `/Users/dlarocque/workspace/firebase-js-sdk/node_modules/.bin/nyc --reporter lcovonly /Users/dlarocque/workspace/firebase-js-sdk/node_modules/.bin/mocha --require /Users/dlarocque/workspace/firebase-js-sdk/packages/firestore/babel-register.js --require lite/index.ts --config ../../config/mocharc.node.js --grep Regex test/lite/**/*.test.ts` failed with code 1
    at ChildProcess.<anonymous> (/Users/dlarocque/workspace/firebase-js-sdk/node_modules/child-process-promise/lib/index.js:132:23)
    at ChildProcess.emit (node:events:518:28)
    at ChildProcess.emit (node:domain:489:12)
    at maybeClose (node:internal/child_process:1104:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5) {
  code: 1,
  childProcess: ChildProcess {
    _events: [Object: null prototype] {
      error: [Function (anonymous)],
      close: [Function (anonymous)]
    },
    _eventsCount: 2,
    _maxListeners: undefined,
    _closesNeeded: 1,
    _closesGot: 1,
    connected: false,
    signalCode: null,
    exitCode: 1,
    killed: false,
    spawnfile: '/Users/dlarocque/workspace/firebase-js-sdk/node_modules/.bin/nyc',
    _handle: null,
    spawnargs: [
      '/Users/dlarocque/workspace/firebase-js-sdk/node_modules/.bin/nyc',
      '--reporter',
      'lcovonly',
      '/Users/dlarocque/workspace/firebase-js-sdk/node_modules/.bin/mocha',
      '--require',
      '/Users/dlarocque/workspace/firebase-js-sdk/packages/firestore/babel-register.js',
      '--require',
      'lite/index.ts',
      '--config',
      '../../config/mocharc.node.js',
      '--grep',
      'Regex',
      'test/lite/**/*.test.ts'
    ],
    pid: 14458,
    stdin: null,
    stdout: null,
    stderr: null,
    stdio: [ null, null, null ],
    [Symbol(shapeMode)]: false,
    [Symbol(kCapture)]: false
  },
  stdout: undefined,
  stderr: undefined
}
error Command failed with exit code 1

After:

$ RUN_ENTERPRISE_TESTS=true yarn test:lite:prod --databaseId=enterprise --grep "Regex"
yarn run v1.22.11
$ ts-node ./scripts/run-tests.ts --platform node_lite --main=lite/index.ts 'test/lite/**/*.test.ts' --databaseId=enterprise --grep Regex

  Firestore Pipelines
    function expressions
      ✔ testRegexContains (73ms)
      1) testRegexFind
      ✔ testRegexMatches (54ms)

  2 passing (5s)
  1 failing

  1) Firestore Pipelines
       function expressions
         testRegexFind:
     Function field() called with invalid data. Invalid field path (.oo.). Paths must not be empty, begin with '.', end with '.', or contain '..'

error Command failed with exit code 1.

When using `run_tests.ts` (e.g., when running Firestore Lite tests), a
noisy stack trace is output when tests fail. This is unecessarily noisy.

This modifies the script to only output a stack trace for real crashes,
not test failures.
@dlarocque dlarocque requested review from a team as code owners January 14, 2026 16:18
@changeset-bot
Copy link

changeset-bot bot commented Jan 14, 2026

⚠️ No Changeset found

Latest commit: 87cab2a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dlarocque, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the output behavior of the run_tests.ts script, specifically for Firestore Lite tests. It addresses the issue of excessive stack trace logging during routine test failures, distinguishing these from critical process crashes. This change improves the readability of test results by reducing noise, making it easier to identify and debug actual system issues rather than just test assertion failures.

Highlights

  • Test Runner Output: Modified run_tests.ts to suppress full stack traces for test failures, ensuring they are only displayed for genuine process crashes.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to improve the test running script by silencing stack traces for test failures, while still showing them for actual crashes. The approach of catching the promise rejection from spawn is correct. However, I've found a potential issue in how different error types are distinguished, which could lead to an unhandled exception in some crash scenarios. I've provided a suggestion to make the error handling more robust.

Comment on lines +90 to +97
if (error.code) {
process.exit(error.code);
} else {
// The error code will be undefined if it was a real crash (e.g., spawn failed to start),
// so print the entire stack trace for debugging.
console.error(error);
process.exit(1);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current check if (error.code) is not robust enough to distinguish between a test failure (which results in a numeric exit code) and a spawn failure. If spawn fails (e.g., because the command is not found), the error object will have a code property that is a string (e.g., 'ENOENT'). Calling process.exit() with a string argument will throw a TypeError, which would then be an unhandled exception inside the catch block, defeating the purpose of this error handling.

To make this more robust, you should check if error.code is a number. This will correctly differentiate between test failures and other crashes.

I've also updated the comments to be more accurate.

Suggested change
if (error.code) {
process.exit(error.code);
} else {
// The error code will be undefined if it was a real crash (e.g., spawn failed to start),
// so print the entire stack trace for debugging.
console.error(error);
process.exit(1);
}
if (typeof error.code === 'number') {
process.exit(error.code);
} else {
// The error code will not be a number for a real crash (e.g., spawn
// failed to start), so print the entire stack trace for debugging.
console.error(error);
process.exit(1);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant