Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- Added Enterprise Edition support to the Firestore emulator. Configure it by setting `firebase.json#firestore.edition` or `firebase.json#emulators.firestore.edition`.
- Fixed an issue where functions deployments would silently fail (#6989)
- Fixed issue where the CLI isn't able to correctly parse command arguments on PowerShell (#7506)
- Add support for Next.js 16 middleware (`proxy.ts`/`proxy.js`) (#9631)
- Updates the default region for new App Hosting backends to us-east4 (#10271)
- Fix Next.js image optimization detection in client components (#10228)
Expand Down
54 changes: 54 additions & 0 deletions src/command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
it("should work when no arguments are passed and options", async () => {
const run = command
.action((options) => {
options.foo = "bar";

Check warning on line 56 in src/command.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .foo on an `any` value
return options;

Check warning on line 57 in src/command.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe return of an `any` typed value
})
.runner();

Expand All @@ -65,13 +65,13 @@
it("should execute befores before the action", async () => {
const run = command
.before((options) => {
options.foo = true;

Check warning on line 68 in src/command.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .foo on an `any` value
})
.action((options) => {
if (options.foo) {

Check warning on line 71 in src/command.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .foo on an `any` value
options.bar = "baz";

Check warning on line 72 in src/command.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .bar on an `any` value
}
return options;

Check warning on line 74 in src/command.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe return of an `any` typed value
})
.runner();

Expand Down Expand Up @@ -117,8 +117,8 @@
const run = command
.action((options) => {
return {
project: options.project,

Check warning on line 120 in src/command.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .project on an `any` value

Check warning on line 120 in src/command.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
projectNumber: options.projectNumber,

Check warning on line 121 in src/command.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .projectNumber on an `any` value

Check warning on line 121 in src/command.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
projectId: options.projectId,
};
})
Expand Down Expand Up @@ -170,6 +170,60 @@
});
});
});

it("should handle comma separated values in 'only' options", async () => {
const run = command
.action((options) => {
return {
only: options.only,
};
})
.runner();

const result = await run({
only: "firestore,hosting,auth",
});

expect(result).to.deep.eq({
only: "firestore,hosting,auth",
});
});

it("should normalize space separated values in 'only' options", async () => {
const run = command
.action((options) => {
return {
only: options.only,
};
})
.runner();

const result = await run({
only: "firestore hosting auth",
});

expect(result).to.deep.eq({
only: "firestore,hosting,auth",
});
});

it("should normalize space and commas separated values in 'only' options", async () => {
const run = command
.action((options) => {
return {
only: options.only,
};
})
.runner();

const result = await run({
only: "firestore, hosting, auth",
});

expect(result).to.deep.eq({
only: "firestore,hosting,auth",
});
});
Comment on lines +174 to +226

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

These tests are great for covering different scenarios for the --only option. However, there's a lot of repeated code. To improve maintainability and make it easier to add new test cases in the future, you could refactor these tests into a data-driven format. This would reduce duplication and make the intent clearer, which aligns with the style guide's emphasis on code quality.

  const testCases = [
    {
      description: "should handle comma separated values in 'only' options",
      input: "firestore,hosting,auth",
    },
    {
      description: "should normalize space separated values in 'only' options",
      input: "firestore hosting auth",
    },
    {
      description: "should normalize space and commas separated values in 'only' options",
      input: "firestore, hosting,  auth",
    },
  ];

  for (const tc of testCases) {
    it(tc.description, async () => {
      const run = command
        .action((options) => {
          return {
            only: options.only,
          };
        })
        .runner();

      const result = await run({
        only: tc.input,
      });

      expect(result).to.deep.eq({
        only: "firestore,hosting,auth",
      });
    });
  }
References
  1. Code should avoid unnecessarily deep nesting or long periods of nesting. Handle edge cases early and exit or fold them into the general case. Consider helper functions that can completely encapsulate branching, e.g. multiple ways a variable can be populated. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the current tests are a bit more readable compared to this? But, I'm open to changing it if this is better

});

describe("validateProjectId", () => {
Expand Down
10 changes: 10 additions & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@ export class Command {
options.configPath = getInheritedOption(options, "config");
}

const onlyOption = getInheritedOption(options, "only");
if (onlyOption) {
// Handle cases where PowerShell replaces commas with spaces.
// see https://github.com/firebase/firebase-tools/issues/7506
options.only = onlyOption
.split(/[\s,]+/)
.filter(Boolean)
.join(",");
}

try {
options.config = Config.load(options);
} catch (e: any) {
Expand Down
Loading