blob: 579cad5f4f348593b05d7907636da6735150350c [file] [log] [blame]
gioc31bf142025-06-16 07:48:20 +00001import { NodeJSAnalyzer } from "./nodejs.js";
gio9b7421a2025-06-18 12:31:13 +00002import { FileSystem } from "./fs.js";
gioa71316d2025-05-24 09:41:36 +04003import { Volume, IFs, createFsFromVolume } from "memfs";
4import { test, expect } from "@jest/globals";
gioa71316d2025-05-24 09:41:36 +04005
6class InMemoryFileSystem implements FileSystem {
7 constructor(private readonly fs: IFs) {}
8
9 exists(path: string): boolean {
10 return this.fs.existsSync(path);
11 }
12
13 // TODO(gio): add encoding
14 async readFile(path: string, encoding?: BufferEncoding): Promise<string> {
15 const contents = await this.fs.promises.readFile(path);
16 return contents.toString(encoding);
17 }
18}
19
gioa71316d2025-05-24 09:41:36 +040020test("nodejs", async () => {
21 return;
22 const root = "/";
23 const vol = Volume.fromNestedJSON(
24 {
25 "package.json": JSON.stringify({
26 name: "test",
27 version: "1.0.0",
28 dependencies: {
29 prisma: "6.6.0",
30 },
31 }),
32 "package-lock.json": "fake",
33 "prisma/schema.prisma": `
34 datasource db {
35 provider = "sqlite"
36 url = env("DB_URL")
37 }
38 `,
39 },
40 root,
41 );
42 const fs: FileSystem = new InMemoryFileSystem(createFsFromVolume(vol));
43 const analyzer = new NodeJSAnalyzer();
44 expect(analyzer.detect(fs, root)).toBe(true);
45 const info = await analyzer.analyze(fs, root);
46 console.log(info);
47});