| gio | c31bf14 | 2025-06-16 07:48:20 +0000 | [diff] [blame] | 1 | import { NodeJSAnalyzer } from "./nodejs.js"; |
| gio | 9b7421a | 2025-06-18 12:31:13 +0000 | [diff] [blame^] | 2 | import { FileSystem } from "./fs.js"; |
| gio | a71316d | 2025-05-24 09:41:36 +0400 | [diff] [blame] | 3 | import { Volume, IFs, createFsFromVolume } from "memfs"; |
| 4 | import { test, expect } from "@jest/globals"; |
| gio | a71316d | 2025-05-24 09:41:36 +0400 | [diff] [blame] | 5 | |
| 6 | class 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 | |
| gio | a71316d | 2025-05-24 09:41:36 +0400 | [diff] [blame] | 20 | test("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 | }); |