mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Update Dockerfile and LogManager
This commit is contained in:
parent
ae2173e8b1
commit
21711960df
5 changed files with 8 additions and 18 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { appendFile, writeFile, mkdir, exists } from "node:fs/promises";
|
||||
import { appendFile, mkdir, exists } from "node:fs/promises";
|
||||
import { dirname } from "node:path";
|
||||
import type { BunFile } from "bun";
|
||||
|
||||
|
|
@ -42,6 +42,7 @@ export class LogManager {
|
|||
}
|
||||
|
||||
private async write(text: string) {
|
||||
Bun.stdout.name;
|
||||
if (this.output === Bun.stdout) {
|
||||
await Bun.write(Bun.stdout, `${text}\n`);
|
||||
} else {
|
||||
|
|
@ -51,7 +52,6 @@ export class LogManager {
|
|||
await mkdir(dirname(this.output.name ?? ""), {
|
||||
recursive: true,
|
||||
});
|
||||
await writeFile(this.output.name ?? "", "");
|
||||
this.output = Bun.file(this.output.name ?? "");
|
||||
} catch {
|
||||
//
|
||||
|
|
|
|||
|
|
@ -21,13 +21,14 @@ describe("LogManager", () => {
|
|||
beforeEach(async () => {
|
||||
mockOutput = Bun.file("test.log");
|
||||
mockAppend = jest.fn();
|
||||
await mock.module("fs/promises", () => ({
|
||||
await mock.module("node:fs/promises", () => ({
|
||||
appendFile: mockAppend,
|
||||
}));
|
||||
logManager = new LogManager(mockOutput);
|
||||
});
|
||||
|
||||
it("should initialize and write init log", () => {
|
||||
new LogManager(mockOutput);
|
||||
expect(mockAppend).toHaveBeenCalledWith(
|
||||
mockOutput.name,
|
||||
expect.stringContaining("--- INIT LogManager at"),
|
||||
|
|
@ -72,17 +73,6 @@ describe("LogManager", () => {
|
|||
);
|
||||
});
|
||||
|
||||
it("should throw error if output file does not exist", () => {
|
||||
mockAppend.mockImplementationOnce(() => {
|
||||
return Promise.reject(
|
||||
new Error("Output file doesnt exist (and isnt stdout)"),
|
||||
);
|
||||
});
|
||||
expect(
|
||||
logManager.log(LogLevel.INFO, "TestEntity", "Test message"),
|
||||
).rejects.toThrow(Error);
|
||||
});
|
||||
|
||||
it("should log error message", async () => {
|
||||
const error = new Error("Test error");
|
||||
await logManager.logError(LogLevel.ERROR, "TestEntity", error);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue