Skip to content

Commit d68aa33

Browse files
authored
refactor: create temporary directories in tests using os.tmpdir() for consistency. (#9473)
1 parent a8c5f58 commit d68aa33

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/config.spec.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from "path";
22
import * as fs from "fs";
3+
import * as os from "os";
34

45
import { expect } from "chai";
56

@@ -78,17 +79,26 @@ describe("Config", () => {
7879
});
7980

8081
describe("functions.source", () => {
82+
let tmpDir: string;
83+
84+
beforeEach(() => {
85+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "firebase-test"));
86+
});
87+
88+
afterEach(() => {
89+
if (tmpDir) {
90+
fs.rmSync(tmpDir, { recursive: true, force: true });
91+
}
92+
});
93+
8194
it("injects default source when default dir exists but source is missing", () => {
82-
const tmpDir = fs.mkdtempSync("firebase-test");
8395
fs.mkdirSync(path.join(tmpDir, Config.DEFAULT_FUNCTIONS_SOURCE));
8496

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

89101
it("does not injects default source when default dir is missing", () => {
90-
const tmpDir = fs.mkdtempSync("firebase-test");
91-
92102
const cfg = new Config(
93103
{ functions: { runtime: "nodejs20" } },
94104
{ cwd: tmpDir, projectDir: tmpDir },
@@ -97,7 +107,6 @@ describe("Config", () => {
97107
});
98108

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

103112
const cfg = new Config(
@@ -113,7 +122,6 @@ describe("Config", () => {
113122
});
114123

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

119127
const cfg = new Config(
@@ -136,7 +144,6 @@ describe("Config", () => {
136144
});
137145

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

142149
const cfg = new Config(
@@ -152,7 +159,6 @@ describe("Config", () => {
152159
});
153160

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

158164
const cfg = new Config(
@@ -173,8 +179,6 @@ describe("Config", () => {
173179
});
174180

175181
it("does not inject for arrays when default dir is missing", () => {
176-
const tmpDir = fs.mkdtempSync("firebase-test");
177-
178182
const cfg = new Config(
179183
{
180184
functions: [{}, { source: "something" }],

0 commit comments

Comments
 (0)