diff --git a/src/config.spec.ts b/src/config.spec.ts index e381a3aff3f..b4ff64f751c 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"; @@ -78,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("firebase-test"); fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE)); const cfg = new Config({ functions: {} }, { cwd: tmpDir, projectDir: tmpDir }); @@ -87,8 +99,6 @@ describe("Config", () => { }); 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 }, @@ -97,7 +107,6 @@ describe("Config", () => { }); 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( @@ -113,7 +122,6 @@ describe("Config", () => { }); 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( @@ -136,7 +144,6 @@ describe("Config", () => { }); 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( @@ -152,7 +159,6 @@ describe("Config", () => { }); 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( @@ -173,8 +179,6 @@ describe("Config", () => { }); it("does not inject for arrays when default dir is missing", () => { - const tmpDir = fs.mkdtempSync("firebase-test"); - const cfg = new Config( { functions: [{}, { source: "something" }],