-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b47993
commit 3d51680
Showing
2 changed files
with
50 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,56 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { FileHandler } from "../../../src/file-handling/fileHandler.js"; | ||
import { LoadingException } from "../../../src/file-handling/exception.js"; | ||
|
||
describe("FileHandler", () => { | ||
it("correctly reports which file extensions it supports, if none are", () => { | ||
const handler = new FileHandler([]); | ||
expect(handler.getSupportedFileExtensions()).toEqual(new Set()); | ||
}); | ||
|
||
it("correctly reports which file extensions it supports, if one handler is registered", () => { | ||
const handler = new FileHandler([ | ||
{ | ||
fileExtensions: ["json"], | ||
load: async () => new Map(), | ||
}, | ||
]); | ||
expect(handler.getSupportedFileExtensions()).toEqual(new Set(["json"])); | ||
}); | ||
describe("handle", () => { | ||
it("throws LoadingException if no handler is found", async () => { | ||
const handler = new FileHandler([]); | ||
expect(async () => await handler.handle("foo.bar", "en")).toThrow(LoadingException); | ||
}); | ||
|
||
it("throws LoadingException if the file cannot be read", async () => { | ||
const handler = new FileHandler([ | ||
{ | ||
fileExtensions: ["json"], | ||
load: async () => new Map(), | ||
}, | ||
]); | ||
expect(async () => await handler.handle("nonexistent.json", "en")).toThrow(LoadingException); | ||
}); | ||
}); | ||
|
||
describe("getSupportedFileExtensions", () => { | ||
it("correctly reports which file extensions it supports, if none are", () => { | ||
const handler = new FileHandler([]); | ||
expect(handler.getSupportedFileExtensions()).toEqual(new Set()); | ||
}); | ||
|
||
it("correctly reports which file extensions it supports, if one handler is registered", () => { | ||
const handler = new FileHandler([ | ||
{ | ||
fileExtensions: ["json"], | ||
load: async () => new Map(), | ||
}, | ||
]); | ||
expect(handler.getSupportedFileExtensions()).toEqual(new Set(["json"])); | ||
}); | ||
|
||
it("correctly reports which file extensions it supports, if multiple handlers are registered", () => { | ||
const handler = new FileHandler([ | ||
{ | ||
fileExtensions: ["json"], | ||
load: async () => new Map(), | ||
}, | ||
{ | ||
fileExtensions: ["yaml", "yml"], | ||
load: async () => new Map(), | ||
}, | ||
]); | ||
expect(handler.getSupportedFileExtensions()).toEqual( | ||
new Set(["json", "yaml", "yml"]) | ||
); | ||
it("correctly reports which file extensions it supports, if multiple handlers are registered", () => { | ||
const handler = new FileHandler([ | ||
{ | ||
fileExtensions: ["json"], | ||
load: async () => new Map(), | ||
}, | ||
{ | ||
fileExtensions: ["yaml", "yml"], | ||
load: async () => new Map(), | ||
}, | ||
]); | ||
expect(handler.getSupportedFileExtensions()).toEqual( | ||
new Set(["json", "yaml", "yml"]) | ||
); | ||
}); | ||
}); | ||
}); |