diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 39ac271dfc..f580540eaa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -643,8 +643,8 @@ importers: specifier: ^3.1.3 version: 3.1.3 fast-xml-parser: - specifier: ^4.5.1 - version: 4.5.3 + specifier: ^5.0.0 + version: 5.2.3 fastest-levenshtein: specifier: ^1.0.16 version: 1.0.16 @@ -6487,8 +6487,8 @@ packages: resolution: {integrity: sha512-xkjOecfnKGkSsOwtZ5Pz7Us/T6mrbPQrq0nh+aCO5V9nk5NLWmasAHumTKjiPJPWANe+kAZ84Jc8ooJkzZ88Sw==} hasBin: true - fast-xml-parser@4.5.3: - resolution: {integrity: sha512-RKihhV+SHsIUGXObeVy9AXiBbFwkVk7Syp8XgwN5U3JV416+Gwp/GO9i0JYKmikykgz/UHRrrV4ROuZEo/T0ig==} + fast-xml-parser@5.2.3: + resolution: {integrity: sha512-OdCYfRqfpuLUFonTNjvd30rCBZUneHpSQkCqfaeWQ9qrKcl6XlWeDBNVwGb+INAIxRshuN2jF+BE0L6gbBO2mw==} hasBin: true fastest-levenshtein@1.0.16: @@ -9748,6 +9748,9 @@ packages: strnum@1.1.2: resolution: {integrity: sha512-vrN+B7DBIoTTZjnPNewwhx6cBA/H+IS7rfW68n7XxC1y7uoiGQBxaKzqucGUgavX15dJgiGztLJ8vxuEzwqBdA==} + strnum@2.1.1: + resolution: {integrity: sha512-7ZvoFTiCnGxBtDqJ//Cu6fWtZtc7Y3x+QOirG15wztbdngGSkht27o2pyGWrVy0b4WAy3jbKmnoK6g5VlVNUUw==} + strong-type@0.1.6: resolution: {integrity: sha512-eJe5caH6Pi5oMMeQtIoBPpvNu/s4jiyb63u5tkHNnQXomK+puyQ5i+Z5iTLBr/xUz/pIcps0NSfzzFI34+gAXg==} engines: {node: '>=12.0.0'} @@ -17010,9 +17013,9 @@ snapshots: dependencies: strnum: 1.1.2 - fast-xml-parser@4.5.3: + fast-xml-parser@5.2.3: dependencies: - strnum: 1.1.2 + strnum: 2.1.1 fastest-levenshtein@1.0.16: {} @@ -21092,6 +21095,8 @@ snapshots: strnum@1.1.2: {} + strnum@2.1.1: {} + strong-type@0.1.6: {} strong-type@1.1.0: {} diff --git a/src/package.json b/src/package.json index 2e006136f2..5c85483a9c 100644 --- a/src/package.json +++ b/src/package.json @@ -378,7 +378,7 @@ "diff": "^5.2.0", "diff-match-patch": "^1.0.5", "fast-deep-equal": "^3.1.3", - "fast-xml-parser": "^4.5.1", + "fast-xml-parser": "^5.0.0", "fastest-levenshtein": "^1.0.16", "fzf": "^0.5.2", "get-folder-size": "^5.0.0", diff --git a/src/utils/__tests__/xml.test.ts b/src/utils/__tests__/xml.test.ts index aa71fa0901..27e5353377 100644 --- a/src/utils/__tests__/xml.test.ts +++ b/src/utils/__tests__/xml.test.ts @@ -117,35 +117,47 @@ describe("parseXml", () => { describe("error handling", () => { it("wraps parser errors with a descriptive message", () => { - // Use jest.spyOn to mock the XMLParser implementation + // Create a mock implementation that throws an error const mockParseFn = jest.fn().mockImplementation(() => { throw new Error("Simulated parsing error") }) + // Create a mock parser instance const mockParserInstance = { parse: mockParseFn, } - // Spy on the XMLParser constructor to return our mock - const parserSpy = jest - .spyOn(require("fast-xml-parser"), "XMLParser") - .mockImplementation(() => mockParserInstance) - - // Test that our function wraps the error appropriately - expect(() => parseXml("")).toThrow("Failed to parse XML: Simulated parsing error") - - // Verify the parser was called with the expected options - expect(parserSpy).toHaveBeenCalledWith({ - ignoreAttributes: false, - attributeNamePrefix: "@_", - parseAttributeValue: false, - parseTagValue: false, - trimValues: true, - stopNodes: [], + // Create a mock constructor function + const MockXMLParser = jest.fn().mockImplementation(() => mockParserInstance) + + // Save the original XMLParser + const { XMLParser } = jest.requireActual("fast-xml-parser") + + // Replace the XMLParser with our mock + jest.doMock("fast-xml-parser", () => ({ + XMLParser: MockXMLParser, + })) + + // Import the module with our mocked dependency + jest.isolateModules(() => { + const { parseXml } = require("../xml") + + // Test that our function wraps the error appropriately + expect(() => parseXml("")).toThrow("Failed to parse XML: Simulated parsing error") + + // Verify the parser was called with the expected options + expect(MockXMLParser).toHaveBeenCalledWith({ + ignoreAttributes: false, + attributeNamePrefix: "@_", + parseAttributeValue: false, + parseTagValue: false, + trimValues: true, + stopNodes: [], + }) }) - // Cleanup - parserSpy.mockRestore() + // Restore the original module + jest.dontMock("fast-xml-parser") }) }) })