From cb2226c491f337dee7ecabd5795109b0fc6550ec Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Mon, 17 Nov 2025 10:23:00 -0800 Subject: [PATCH 1/2] refactor: create temporary directories in tests using `os.tmpdir()` for consistency. --- src/config.spec.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/config.spec.ts b/src/config.spec.ts index e381a3aff3f..3bda3d1915d 100644 --- a/src/config.spec.ts +++ b/src/config.spec.ts @@ -1,5 +1,6 @@ import * as path from "path"; import * as fs from "fs"; +import * as os from "os"; import { expect } from "chai"; @@ -79,7 +80,7 @@ describe("Config", () => { describe("functions.source", () => { it("injects default source when default dir exists but source is missing", () => { - const tmpDir = fs.mkdtempSync("firebase-test"); + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test")); fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE)); const cfg = new Config({ functions: {} }, { cwd: tmpDir, projectDir: tmpDir }); @@ -87,7 +88,7 @@ describe("Config", () => { }); it("does not injects default source when default dir is missing", () => { - const tmpDir = fs.mkdtempSync("firebase-test"); + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test")); const cfg = new Config( { functions: { runtime: "nodejs20" } }, @@ -97,7 +98,7 @@ describe("Config", () => { }); it("does not inject source for remoteSource", () => { - const tmpDir = fs.mkdtempSync("firebase-test"); + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test")); fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE)); const cfg = new Config( @@ -113,7 +114,7 @@ describe("Config", () => { }); it("injects into the first empty entry only when default dir exists", () => { - const tmpDir = fs.mkdtempSync("firebase-test"); + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test")); fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE)); const cfg = new Config( @@ -136,7 +137,7 @@ describe("Config", () => { }); it("injects only one entry when multiple are empty", () => { - const tmpDir = fs.mkdtempSync("firebase-test"); + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test")); fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE)); const cfg = new Config( @@ -152,7 +153,7 @@ describe("Config", () => { }); it("does not inject when no entry is empty", () => { - const tmpDir = fs.mkdtempSync("firebase-test"); + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test")); fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE)); const cfg = new Config( @@ -173,7 +174,7 @@ describe("Config", () => { }); it("does not inject for arrays when default dir is missing", () => { - const tmpDir = fs.mkdtempSync("firebase-test"); + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test")); const cfg = new Config( { From 05f34eb0e5b077a1d60fa72925877c01e862996e Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Mon, 17 Nov 2025 10:28:05 -0800 Subject: [PATCH 2/2] refactor: centralize temporary directory creation and cleanup for functions.source tests. --- src/config.spec.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/config.spec.ts b/src/config.spec.ts index 3bda3d1915d..b4ff64f751c 100644 --- a/src/config.spec.ts +++ b/src/config.spec.ts @@ -79,8 +79,19 @@ describe("Config", () => { }); 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(path.join(os.tmpdir(), "firebase-test")); fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE)); const cfg = new Config({ functions: {} }, { cwd: tmpDir, projectDir: tmpDir }); @@ -88,8 +99,6 @@ describe("Config", () => { }); it("does not injects default source when default dir is missing", () => { - const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test")); - const cfg = new Config( { functions: { runtime: "nodejs20" } }, { cwd: tmpDir, projectDir: tmpDir }, @@ -98,7 +107,6 @@ describe("Config", () => { }); it("does not inject source for remoteSource", () => { - const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test")); fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE)); const cfg = new Config( @@ -114,7 +122,6 @@ describe("Config", () => { }); it("injects into the first empty entry only when default dir exists", () => { - const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test")); fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE)); const cfg = new Config( @@ -137,7 +144,6 @@ describe("Config", () => { }); it("injects only one entry when multiple are empty", () => { - const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test")); fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE)); const cfg = new Config( @@ -153,7 +159,6 @@ describe("Config", () => { }); it("does not inject when no entry is empty", () => { - const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test")); fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE)); const cfg = new Config( @@ -174,8 +179,6 @@ describe("Config", () => { }); it("does not inject for arrays when default dir is missing", () => { - const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test")); - const cfg = new Config( { functions: [{}, { source: "something" }],