Skip to content

Commit

Permalink
fix: unit tests and for file not being read but the file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
junners committed Jan 26, 2025
1 parent 30337e9 commit 4199034
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/libs/ParseFlows.ts
Original file line number Diff line number Diff line change
@@ -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<ParsedFlow[]> {
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)}`);
Expand Down
12 changes: 12 additions & 0 deletions tests/models/Flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
});
});

0 comments on commit 4199034

Please sign in to comment.