Skip to content
Merged
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
22 changes: 13 additions & 9 deletions src/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from "path";
import * as fs from "fs";
import * as os from "os";

import { expect } from "chai";

Expand Down Expand Up @@ -47,7 +48,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 51 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 @@ -68,7 +69,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 72 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 All @@ -78,17 +79,26 @@
});

describe("functions.source", () => {
let tmpDir: string;

beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test"));
});

afterEach(() => {
if (tmpDir) {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
});

it("injects default source when default dir exists but source is missing", () => {
const tmpDir = fs.mkdtempSync("firebase-test");
fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE));

const cfg = new Config({ functions: {} }, { cwd: tmpDir, projectDir: tmpDir });
expect(cfg.get("functions.source")).to.be.equal("functions");
});

it("does not injects default source when default dir is missing", () => {
const tmpDir = fs.mkdtempSync("firebase-test");

const cfg = new Config(
{ functions: { runtime: "nodejs20" } },
{ cwd: tmpDir, projectDir: tmpDir },
Expand All @@ -97,7 +107,6 @@
});

it("does not inject source for remoteSource", () => {
const tmpDir = fs.mkdtempSync("firebase-test");
fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE));

const cfg = new Config(
Expand All @@ -113,7 +122,6 @@
});

it("injects into the first empty entry only when default dir exists", () => {
const tmpDir = fs.mkdtempSync("firebase-test");
fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE));

const cfg = new Config(
Expand All @@ -136,7 +144,6 @@
});

it("injects only one entry when multiple are empty", () => {
const tmpDir = fs.mkdtempSync("firebase-test");
fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE));

const cfg = new Config(
Expand All @@ -152,7 +159,6 @@
});

it("does not inject when no entry is empty", () => {
const tmpDir = fs.mkdtempSync("firebase-test");
fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE));

const cfg = new Config(
Expand All @@ -173,8 +179,6 @@
});

it("does not inject for arrays when default dir is missing", () => {
const tmpDir = fs.mkdtempSync("firebase-test");

const cfg = new Config(
{
functions: [{}, { source: "something" }],
Expand Down
Loading