Skip to content

Commit

Permalink
Get rid of __dirname
Browse files Browse the repository at this point in the history
  • Loading branch information
kayahr committed Dec 31, 2023
1 parent acb1031 commit 9c476bf
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 39 deletions.
10 changes: 5 additions & 5 deletions src/test/Journal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { JournalError } from "../main/JournalError";
import type { JournalEvent } from "../main/JournalEvent";
import { sleep } from "../main/util/async";

const journalDir = join(__dirname, "../../src/test/data/journal");
const journalDir = "src/test/data/journal";

async function withTmpHome(action: (home: string) => Promise<void>): Promise<void> {
const origHome = process.env["HOME"];
Expand Down Expand Up @@ -243,7 +243,7 @@ describe("Journal", () => {
});

it("throws error when reading broken journal", async () => {
const journal = await Journal.open({ directory: join(__dirname, "../../src/test/data/broken") });
const journal = await Journal.open({ directory: "src/test/data/broken" });
try {
const promise = (async () => {
for await (const event of journal) {
Expand Down Expand Up @@ -307,9 +307,9 @@ describe("Journal", () => {
}
});
it("opens journal in given directory", async () => {
const journal = await Journal.open({ directory: __dirname });
const journal = await Journal.open({ directory: "src/test" });
try {
expect(journal.getDirectory()).toBe(__dirname);
expect(journal.getDirectory()).toBe("src/test");
} finally {
await journal.close();
}
Expand All @@ -322,7 +322,7 @@ describe("Journal", () => {
{ file: "Journal.2023-01-01T000000.01.log", offset: 222, line: 3 });
});
it("returns start position when no journal find found", async () => {
expect(await Journal.findEnd(__dirname)).toEqual({ file: "", offset: 0, line: 1 });
expect(await Journal.findEnd("src/test")).toEqual({ file: "", offset: 0, line: 1 });
});
});

Expand Down
4 changes: 1 addition & 3 deletions src/test/events/carrier/CarrierStats.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { join } from "path";

import { Journal } from "../../../main/Journal";

const directory = join(__dirname, "../../../../src/test/data/events/CarrierStats");
const directory = "src/test/data/events/CarrierStats";

describe("CarrierStats", () => {
it("updates old TaxRate to new TaxRate_rearm, TaxRate_refuel and TaxRate_repair", async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/test/events/exploration/Scan.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { join } from "path";

import { Journal } from "../../../main/Journal";

const directory = join(__dirname, "../../../../src/test/data/events/Scan");
const directory = "src/test/data/events/Scan";

describe("Scan", () => {
it("updates Materials object to array", async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/test/events/odyssey/Backpack.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { join } from "path";

import { Journal } from "../../../main/Journal";

const directory = join(__dirname, "../../../../src/test/data/events/Backpack");
const directory = "src/test/data/events/Backpack";

describe("Scan", () => {
it("rename BackPack and BackPackMaterials event to Backpack", async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/test/events/other/Synthesis.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { join } from "path";

import { Journal } from "../../../main/Journal";

const directory = join(__dirname, "../../../../src/test/data/events/Synthesis");
const directory = "src/test/data/events/Synthesis";

describe("Synthesis", () => {
it("updates Materials object to array", async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/test/events/startup/Statistics.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { join } from "path";

import { Journal } from "../../../main/Journal";

const directory = join(__dirname, "../../../../src/test/data/events/Statistics");
const directory = "src/test/data/events/Statistics";

describe("Statistics", () => {
it("updates fleet carrier distance travelled from LY string to number", async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/test/events/station/EngineerCraft.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { join } from "path";

import { Journal } from "../../../main/Journal";

const directory = join(__dirname, "../../../../src/test/data/events/EngineerCraft");
const directory = "src/test/data/events/EngineerCraft";

describe("EngineerCraft", () => {
it("updates Ingredients object to array", async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/test/events/travel/Docked.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { join } from "path";

import { Journal } from "../../../main/Journal";

const directory = join(__dirname, "../../../../src/test/data/events/Docked");
const directory = "src/test/data/events/Docked";

describe("Docked", () => {
it("updates old properties to new properties", async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/test/events/travel/FSDJump.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { join } from "path";

import { Journal } from "../../../main/Journal";

const directory = join(__dirname, "../../../../src/test/data/events/FSDJump");
const directory = "src/test/data/events/FSDJump";

describe("FSDJump", () => {
it("updates old properties to new properties", async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/test/events/travel/Location.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { join } from "path";

import { Journal } from "../../../main/Journal";

const directory = join(__dirname, "../../../../src/test/data/events/Location");
const directory = "src/test/data/events/Location";

describe("Location", () => {
it("updates old properties to new properties", async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { join } from "path";

import * as edj from "../main/index";

const journalDir = join(__dirname, "../../src/test/data/journal");
const journalDir = "src/test/data/journal";

describe("ed-journal", () => {
it("exports the Journal class", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/util/LineReader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from "path";

import { LineReader } from "../../main/util/LineReader";

const textsDir = join(__dirname, "../../../src/test/data/texts");
const textsDir = "src/test/data/texts";
const testTxt = join(textsDir, "test.txt");
const smallTxt = join(textsDir, "small.txt");

Expand Down
2 changes: 1 addition & 1 deletion src/tools/validate-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ValidationError extends Error {

(async () => {
const validator = new Validator();
const schema = JSON.parse((await readFile(join(__dirname, "..", schemaFile))).toString()) as Schema;
const schema = JSON.parse((await readFile(join("src", schemaFile))).toString()) as Schema;

const journal = await Journal.open();
process.on("SIGINT", () => {
Expand Down
3 changes: 1 addition & 2 deletions src/tools/validate-journal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class ValidationError extends Error {

(async () => {
const validator = new Validator();
const schema = JSON.parse((await readFile(join(__dirname, "..",
"journal-event.schema.json"))).toString()) as Schema;
const schema = JSON.parse((await readFile(join("src", "journal-event.schema.json"))).toString()) as Schema;
const narrowedSchemas = new Map<string, Schema>();

const journal = await Journal.open({ position, watch: true });
Expand Down

0 comments on commit 9c476bf

Please sign in to comment.