Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: import concurrency functions from xml-disassembler #22

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"dependencies": {
"tslib": "^2.6.2",
"xml-disassembler": "^1.3.9"
"xml-disassembler": "^1.3.10"
},
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/service/deleteReassembledXML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import { readdir, rm } from "node:fs/promises";
import { join } from "node:path/posix";
import { getConcurrencyThreshold } from "./getConcurrencyThreshold";
import { withConcurrencyLimit } from "./withConcurrencyLimit";
import {
getConcurrencyThreshold,
withConcurrencyLimit,
} from "xml-disassembler";

export async function deleteReassembledXML(
disassembledPath: string,
Expand Down
10 changes: 0 additions & 10 deletions src/service/getConcurrencyThreshold.ts

This file was deleted.

6 changes: 4 additions & 2 deletions src/service/json2xmlReassembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import { stat, readdir } from "node:fs/promises";
import { join } from "node:path/posix";
import {
getConcurrencyThreshold,
withConcurrencyLimit,
} from "xml-disassembler";

import { logger } from "@src/index";
import { reassembleHandler } from "@src/service/reassembleHandler";
import { transform2XML } from "@src/service/transform2XML";
import { deleteReassembledXML } from "@src/service/deleteReassembledXML";
import { withConcurrencyLimit } from "./withConcurrencyLimit";
import { getConcurrencyThreshold } from "./getConcurrencyThreshold";

export class JsonToXmlReassembler {
async reassemble(xmlAttributes: {
Expand Down
8 changes: 5 additions & 3 deletions src/service/transform2JSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import { readdir, rm, writeFile } from "node:fs/promises";
import { join } from "node:path/posix";
import { parseXML } from "xml-disassembler";
import {
parseXML,
getConcurrencyThreshold,
withConcurrencyLimit,
} from "xml-disassembler";

import { logger } from "@src/index";
import { withConcurrencyLimit } from "./withConcurrencyLimit";
import { getConcurrencyThreshold } from "./getConcurrencyThreshold";

export async function transform2JSON(xmlPath: string): Promise<void> {
const tasks: (() => Promise<void>)[] = [];
Expand Down
22 changes: 0 additions & 22 deletions src/service/withConcurrencyLimit.ts

This file was deleted.

6 changes: 4 additions & 2 deletions src/service/xml2jsonDisassembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import { existsSync } from "node:fs";
import { stat, readdir } from "node:fs/promises";
import { resolve, join, basename, dirname, extname } from "node:path/posix";
import {
getConcurrencyThreshold,
withConcurrencyLimit,
} from "xml-disassembler";

import { logger } from "@src/index";
import { disassembleHandler } from "@src/service/disassembleHandler";
import { transform2JSON } from "@src/service/transform2JSON";
import { withConcurrencyLimit } from "./withConcurrencyLimit";
import { getConcurrencyThreshold } from "./getConcurrencyThreshold";

export class XmlToJsonDisassembler {
async disassemble(xmlAttributes: {
Expand Down
28 changes: 0 additions & 28 deletions test/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ describe("main function", () => {

afterEach(async () => {
jest.restoreAllMocks();
jest.resetModules();
});

afterAll(async () => {
Expand Down Expand Up @@ -121,33 +120,6 @@ describe("main function", () => {
await rm(fakeFile);
expect(logger.error).toHaveBeenCalled();
});
it("should return the minimum of available parallelism and 6", () => {
jest.mock("node:os", () => ({
availableParallelism: jest.fn(() => 4), // Mock availableParallelism to return 4
}));
const {
getConcurrencyThreshold,
} = require("../src/service/getConcurrencyThreshold");
expect(getConcurrencyThreshold()).toBe(4);
});
it("should return 6 if availableParallelism returns a higher value", () => {
jest.mock("node:os", () => ({
availableParallelism: jest.fn(() => 10), // Mock availableParallelism to return 10
}));
const {
getConcurrencyThreshold,
} = require("../src/service/getConcurrencyThreshold");
expect(getConcurrencyThreshold()).toBe(6);
});
it("should return 6 if availableParallelism is undefined", () => {
jest.mock("node:os", () => ({
availableParallelism: undefined, // Simulate unavailable function
}));
const {
getConcurrencyThreshold,
} = require("../src/service/getConcurrencyThreshold");
expect(getConcurrencyThreshold()).toBe(6);
});
// This should always be the final test
it("should compare the files created in the mock directory against the baselines to confirm no changes.", async () => {
await compareDirectories(baselineDir, mockDir);
Expand Down
Loading