diff --git a/src/main/libs/ParseFlows.ts b/src/main/libs/ParseFlows.ts index 21c5b78..c59c829 100644 --- a/src/main/libs/ParseFlows.ts +++ b/src/main/libs/ParseFlows.ts @@ -1,16 +1,17 @@ -import p from "path-browserify"; +// import p from "path-browserify"; import { Flow } from "../models/Flow"; -import fs from "fs"; +import { readFile } from "fs/promises"; +import { fileURLToPath } from "url"; import { convert } from "xmlbuilder2"; +import { realpath } from "fs/promises"; import { ParsedFlow } from "../models/ParsedFlow"; export async function ParseFlows(selectedUris: string[]): Promise { const parseResults: ParsedFlow[] = []; for (const uri of selectedUris) { try { - console.log(`normalize uri ${uri}`); - const normalizedURI = p.normalize(uri); - const content = await fs.readFileSync(normalizedURI); + const resolvePath = await realpath(uri); + const content = await readFile(fileURLToPath(`file:${resolvePath}`)); const xmlString = content.toString(); const flowObj = convert(xmlString, { format: "object" }); console.log(`flowObj ${JSON.stringify(flowObj, null, 2)}`); diff --git a/tests/models/Flow.test.ts b/tests/models/Flow.test.ts index da0a74a..6e8ad73 100644 --- a/tests/models/Flow.test.ts +++ b/tests/models/Flow.test.ts @@ -4,6 +4,10 @@ import { XMLBuilder } from "xmlbuilder2/lib/interfaces"; import { Flow } from "../../src/main/models/Flow"; +// import { readFileSync } from "node:fs"; + +import { parse, ParsedFlow } from "../../src"; + describe("Flow Model", () => { beforeAll(() => { jest.spyOn(console, "warn").mockImplementation(() => jest.fn()); @@ -67,4 +71,12 @@ describe("Flow Model", () => { expect(errors).toBeTruthy(); expect(errors).not.toBeInstanceOf(NoErrorThrownError); }); + + it("should read a file from base and convert to flow e2e", async () => { + const filePath: string = "./tests/xmlfiles/Unused_Variable.flow-meta.xml"; + const parsedFiles: ParsedFlow[] = await parse([filePath]); + expect(parsedFiles).toHaveLength(1); + expect(parsedFiles[0].flow).toBeTruthy(); + expect(parsedFiles[0].errorMessage).toBeFalsy(); + }); });