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
4 changes: 2 additions & 2 deletions src/commands/firestore-operations-describe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ describe("firestore:operations:describe", () => {

it("should throw a FirebaseError if operation name is invalid", async () => {
const options = { project: "test-project" };
await expect(command.runner()("", options)).to.be.rejectedWith(
await expect(command.runner()("/databases/blah", options)).to.be.rejectedWith(
FirebaseError,
'"" is not a valid operation name.',
'"/databases/blah" is not a valid operation name.',
);
await expect(command.runner()("projects/p/databases/d", options)).to.be.rejectedWith(
FirebaseError,
Expand Down
14 changes: 11 additions & 3 deletions src/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { FIREBASE_JSON_PATH as VALID_CONFIG_PATH } from "./test/fixtures/valid-config";
import { FIXTURE_DIR as SIMPLE_CONFIG_DIR } from "./test/fixtures/config-imports";
import { FIXTURE_DIR as DUP_TOP_LEVEL_CONFIG_DIR } from "./test/fixtures/dup-top-level";
import { FIREBASE_JSON_PATH as EMPTY_CONFIG_PATH } from "./test/fixtures/empty-config";

describe("Config", () => {
describe("#load", () => {
Expand All @@ -17,9 +18,16 @@
configPath: path.relative(cwd, VALID_CONFIG_PATH),
});
expect(config).to.not.be.null;
if (config) {
expect(config.get("database.rules")).to.eq("config/security-rules.json");
}
expect(config?.get("database.rules")).to.eq("config/security-rules.json");
});
it("should fall back to {} when the file is empty", () => {
const cwd = __dirname;
const config = Config.load({
cwd,
configPath: path.relative(cwd, EMPTY_CONFIG_PATH),
});
expect(config).to.not.be.null;
expect(config?.data).to.deep.eq({});
});
});

Expand All @@ -39,7 +47,7 @@
describe("#parseFile", () => {
it("should load a cjson file", () => {
const config = new Config({}, { cwd: SIMPLE_CONFIG_DIR });
expect(config.parseFile("hosting", "hosting.json").public).to.equal(".");

Check warning on line 50 in src/config.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .public on an `any` value
});

it("should error out for an unknown file", () => {
Expand All @@ -60,7 +68,7 @@
describe("#materialize", () => {
it("should assign unaltered if an object is found", () => {
const config = new Config({ example: { foo: "bar" } }, {});
expect(config.materialize("example").foo).to.equal("bar");

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

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .foo on an `any` value
});

it("should prevent top-level key duplication", () => {
Expand Down
6 changes: 4 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import * as clc from "colorette";
import * as fs from "fs-extra";
import * as path from "path";
const cjson = require("cjson");

import { detectProjectRoot } from "./detectProjectRoot";
import { FirebaseError } from "./error";
Expand All @@ -17,7 +16,7 @@
import { getValidator, getErrorMessage } from "./firebaseConfigValidate";
import { logger } from "./logger";
import { loadCJSON } from "./loadCJSON";
const parseBoltRules = require("./parseBoltRules");

Check warning on line 19 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement

Check warning on line 19 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

export class Config {
static DEFAULT_FUNCTIONS_SOURCE = "functions";
Expand All @@ -36,19 +35,19 @@
"apphosting",
];

public options: any;

Check warning on line 38 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
public projectDir: string;
public data: any = {};

Check warning on line 40 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
public defaults: any = {};

Check warning on line 41 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
public notes: any = {};

Check warning on line 42 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

private _src: any;

Check warning on line 44 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

/**
* @param src incoming firebase.json source, parsed by not validated.
* @param options command-line options.
*/
constructor(src: any, options: any = {}) {

Check warning on line 50 in src/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
this.options = options;
this.projectDir = this.options.projectDir || detectProjectRoot(this.options);
this._src = src;
Expand Down Expand Up @@ -303,7 +302,10 @@
if (pd) {
try {
const filePath = path.resolve(pd, path.basename(filename));
const data = cjson.load(filePath);
let data: unknown = {};
if (fs.statSync(filePath).size > 0) {
data = loadCJSON(filePath);
}

// Validate config against JSON Schema. For now we just print these to debug
// logs but in a future CLI version they could be warnings and/or errors.
Expand Down
Empty file.
8 changes: 8 additions & 0 deletions src/test/fixtures/empty-config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { resolve } from "path";

/**
* A directory containing an empty rebase.json.
*/
export const FIXTURE_DIR = __dirname;

export const FIREBASE_JSON_PATH = resolve(__dirname, "firebase.json");
Loading