Skip to content

Fix Crashlytics unit tests#10172

Merged
andrewbrook merged 2 commits intocrashlyticsfrom
crash2
Mar 25, 2026
Merged

Fix Crashlytics unit tests#10172
andrewbrook merged 2 commits intocrashlyticsfrom
crash2

Conversation

@andrewbrook
Copy link
Copy Markdown
Contributor

Description

Fix unit tests for crashlytics:sourcemap:upload

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 addresses a specific issue within the Crashlytics sourcemap upload unit tests. The primary goal is to ensure the reliability of these tests by accurately simulating the execution environment, particularly concerning the current working directory, and updating the expected file path patterns to reflect these changes. This ensures the tests correctly validate the functionality of finding and uploading mapping files.

Highlights

  • Test Fix: Fixed a failing unit test for the crashlytics:sourcemap:upload command that was incorrectly identifying mapping files.
  • Current Working Directory Management: Introduced process.chdir() and process.cwd() calls within the test to correctly simulate the execution environment and ensure proper path resolution.
  • Regex Pattern Update: Adjusted the regular expressions used to match uploaded file names to align with the changes in the current working directory during the test.

🧠 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.

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
Copy Markdown
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 modifies a test for Crashlytics sourcemap upload, specifically for finding and uploading mapping files in the current directory. The change involves temporarily altering the current working directory (process.chdir) for the duration of the test. The reviewer identified a potential issue where the original working directory might not be restored if an error occurs during the test, which could lead to test flakiness. A try...finally block was suggested to ensure the current working directory is always reset.

Comment on lines +131 to +150
const originalCwd = process.cwd();
process.chdir("src/test");
await command.runner()(undefined, { app: "test-app" });
const uploadedFiles = gcsMock.uploadObject
.getCalls()
.map((call) => call.args[0].file)
.sort();
expect(uploadedFiles[0]).to.match(
/test-app-.*-src-test-fixtures-mapping-files-mock_mapping\.js\.map\.zip/,
/test-app-.*-fixtures-mapping-files-mock_mapping\.js\.map\.zip/,
);
expect(uploadedFiles[1]).to.match(
/test-app-.*-src-test-fixtures-mapping-files-subdir-subdir_mock_mapping\.js\.map\.zip/,
/test-app-.*-fixtures-mapping-files-subdir-subdir_mock_mapping\.js\.map\.zip/,
);
expect(uploadedFiles[2]).to.match(
/test-app-.*-src-test-fixtures-mapping-files-with-js-main\.js\.map\.zip/,
/test-app-.*-fixtures-mapping-files-with-js-main\.js\.map\.zip/,
);
expect(uploadedFiles[3]).to.match(
/test-app-.*-src-test-fixtures-mapping-files-with-js-other\.js\.map\.zip/,
/test-app-.*-fixtures-mapping-files-with-js-other\.js\.map\.zip/,
);
process.chdir(originalCwd);
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

While changing the current working directory fixes the test, it introduces a potential for test flakiness. If command.runner() or any of the assertions throw an error, process.chdir(originalCwd) will not be executed. This would leave the CWD changed, which could affect other tests in the suite.

To ensure the CWD is always restored, it's best practice to wrap the test logic in a try...finally block.

    const originalCwd = process.cwd();
    try {
      process.chdir("src/test");
      await command.runner()(undefined, { app: "test-app" });
      const uploadedFiles = gcsMock.uploadObject
        .getCalls()
        .map((call) => call.args[0].file)
        .sort();
      expect(uploadedFiles[0]).to.match(
        /test-app-.*-fixtures-mapping-files-mock_mapping\.js\.map\.zip/,
      );
      expect(uploadedFiles[1]).to.match(
        /test-app-.*-fixtures-mapping-files-subdir-subdir_mock_mapping\.js\.map\.zip/,
      );
      expect(uploadedFiles[2]).to.match(
        /test-app-.*-fixtures-mapping-files-with-js-main\.js\.map\.zip/,
      );
      expect(uploadedFiles[3]).to.match(
        /test-app-.*-fixtures-mapping-files-with-js-other\.js\.map\.zip/,
      );
    } finally {
      process.chdir(originalCwd);
    }

@andrewbrook andrewbrook merged commit 35d703d into crashlytics Mar 25, 2026
43 checks passed
@andrewbrook andrewbrook deleted the crash2 branch March 25, 2026 15:23
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.

3 participants