maksym-work commited on
Commit
ef0f701
·
1 Parent(s): 0e13e28

Enhance vitest setup: improve .env file loading with ES modules path resolution

Browse files
scripts/populate.ts CHANGED
@@ -24,6 +24,7 @@ import { generateSearchTokens } from "../src/lib/utils/searchTokens.ts";
24
  import { ReviewStatus } from "../src/lib/types/Review.ts";
25
  import fs from "fs";
26
  import path from "path";
 
27
  import { MessageUpdateType } from "../src/lib/types/MessageUpdate.ts";
28
  import { MessageReasoningUpdateType } from "../src/lib/types/MessageUpdate.ts";
29
 
@@ -38,6 +39,8 @@ rl.on("close", function () {
38
  process.exit(0);
39
  });
40
 
 
 
41
  const samples = fs.readFileSync(path.join(__dirname, "samples.txt"), "utf8").split("\n---\n");
42
 
43
  const possibleFlags = ["reset", "all", "users", "settings", "assistants", "conversations", "tools"];
 
24
  import { ReviewStatus } from "../src/lib/types/Review.ts";
25
  import fs from "fs";
26
  import path from "path";
27
+ import { fileURLToPath } from "url";
28
  import { MessageUpdateType } from "../src/lib/types/MessageUpdate.ts";
29
  import { MessageReasoningUpdateType } from "../src/lib/types/MessageUpdate.ts";
30
 
 
39
  process.exit(0);
40
  });
41
 
42
+ // Fix __dirname usage for ES modules
43
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
44
  const samples = fs.readFileSync(path.join(__dirname, "samples.txt"), "utf8").split("\n---\n");
45
 
46
  const possibleFlags = ["reset", "all", "users", "settings", "assistants", "conversations", "tools"];
scripts/setups/vitest-setup-server.ts CHANGED
@@ -1,11 +1,13 @@
1
  import { vi, afterAll } from "vitest";
2
  import dotenv from "dotenv";
3
- import { resolve } from "path";
 
4
  import fs from "fs";
5
  import { MongoMemoryServer } from "mongodb-memory-server";
6
 
7
  let mongoServer: MongoMemoryServer;
8
- // Load the .env file
 
9
  const envPath = resolve(__dirname, "../../.env");
10
  dotenv.config({ path: envPath });
11
 
 
1
  import { vi, afterAll } from "vitest";
2
  import dotenv from "dotenv";
3
+ import { resolve, dirname } from "path";
4
+ import { fileURLToPath } from "url";
5
  import fs from "fs";
6
  import { MongoMemoryServer } from "mongodb-memory-server";
7
 
8
  let mongoServer: MongoMemoryServer;
9
+ // Load the .env file using ES modules path resolution
10
+ const __dirname = dirname(fileURLToPath(import.meta.url));
11
  const envPath = resolve(__dirname, "../../.env");
12
  dotenv.config({ path: envPath });
13