Skip to content

Commit

Permalink
fix: import concurrency functions from xml-disassembler
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarvin8 committed Jan 21, 2025
1 parent 908af62 commit 5348ef9
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 74 deletions.
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",
"yaml": "^2.7.0"
},
"repository": {
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 {
withConcurrencyLimit,
getConcurrencyThreshold,
} 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.

8 changes: 5 additions & 3 deletions src/service/transform2YAML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import { readdir, rm, writeFile } from "node:fs/promises";
import { join } from "node:path/posix";
import { stringify } from "yaml";
import { parseXML } from "xml-disassembler";
import {
parseXML,
withConcurrencyLimit,
getConcurrencyThreshold,
} from "xml-disassembler";

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

export async function transform2YAML(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/xml2yamlDisassembler.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 {
withConcurrencyLimit,
getConcurrencyThreshold,
} from "xml-disassembler";

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

export class XmlToYamlDisassembler {
async disassemble(xmlAttributes: {
Expand Down
6 changes: 4 additions & 2 deletions src/service/yaml2xmlReassembler.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 {
withConcurrencyLimit,
getConcurrencyThreshold,
} 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 YamlToXmlReassembler {
async reassemble(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 @@ -120,33 +119,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

0 comments on commit 5348ef9

Please sign in to comment.