Skip to content

Commit c65d86b

Browse files
Adding tests for loadCJSON (#9556)
* Adding tests for loadCJSON * Update src/loadCJSON.spec.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Format --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent c6fc7d8 commit c65d86b

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/loadCJSON.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect } from "chai";
2+
import * as path from "path";
3+
import { loadCJSON } from "./loadCJSON";
4+
import { FirebaseError } from "./error";
5+
6+
describe("loadCJSON", () => {
7+
const fixturesDir = path.join(__dirname, "test", "fixtures", "loadCJSON");
8+
9+
it("should return parsed JSON on success", () => {
10+
const filePath = path.join(fixturesDir, "valid.cjson");
11+
const result = loadCJSON(filePath);
12+
expect(result).to.deep.equal({ key: "value" });
13+
});
14+
15+
it("should throw FirebaseError on ENOENT", () => {
16+
const filePath = path.join(fixturesDir, "nonexistent.cjson");
17+
expect(() => loadCJSON(filePath)).to.throw(
18+
FirebaseError,
19+
"File " + filePath + " does not exist",
20+
);
21+
});
22+
23+
it("should throw FirebaseError on parse error", () => {
24+
const filePath = path.join(fixturesDir, "invalid.cjson");
25+
expect(() => loadCJSON(filePath)).to.throw(
26+
FirebaseError,
27+
new RegExp(`Parse Error in ${filePath}`),
28+
);
29+
});
30+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
"key": "value" // Missing closing brace
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
// This is a comment
3+
"key": "value"
4+
}

0 commit comments

Comments
 (0)