This is an automated email from the ASF dual-hosted git repository.

tiagobento pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git


The following commit(s) were added to refs/heads/main by this push:
     new 470af4797b3 [NO-ISSUE] Fix CI pipeline failure: normalize XML 
attribute order in getContent round-trip test (#4020)
470af4797b3 is described below

commit 470af4797b3a2696e792aa0de23a3f3911cae07e
Author: Nithin R Krishnan <[email protected]>
AuthorDate: Fri Sep 25 07:57:39 2026 +0530

    [NO-ISSUE] Fix CI pipeline failure: normalize XML attribute order in 
getContent round-trip test (#4020)
---
 .../tests-e2e/__fixtures__/prettier.ts             | 28 ++++++++++++++++++++++
 .../tests-e2e/api/getContent.spec.ts               |  9 +++++--
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/packages/dmn-editor-standalone/tests-e2e/__fixtures__/prettier.ts 
b/packages/dmn-editor-standalone/tests-e2e/__fixtures__/prettier.ts
index 9c6d2c82a7e..7fc71279db5 100644
--- a/packages/dmn-editor-standalone/tests-e2e/__fixtures__/prettier.ts
+++ b/packages/dmn-editor-standalone/tests-e2e/__fixtures__/prettier.ts
@@ -37,3 +37,31 @@ export async function prettierFormat(content: string) {
     parser: "xml",
   });
 }
+
+/**
+ * Returns `xml` with the attributes of every start tag sorted by name.
+ *
+ * Attribute order carries no meaning in XML, and the marshaller does not 
preserve it: it builds its JSON by iterating
+ * `Element.attributes`, and `build()` then serializes them in that same 
order. Engines disagree on what that order is.
+ * Parsing `<e id="1" xmlns:zz="urn:zz" name="n" xmlns:aa="urn:aa"/>` gives:
+ *
+ *   - Firefox and jsdom      -> `id xmlns:zz name xmlns:aa`  (the source 
order)
+ *   - WebKit and Chromium    -> `xmlns:zz xmlns:aa id name`  (namespace 
declarations hoisted to the front)
+ *   - Chrome 153+            -> `xmlns:aa xmlns:zz id name`  (hoisted AND 
sorted alphabetically)
+ *
+ * Chrome 153 changed the last of these, which is what made this test start 
failing. Normalizing both sides keeps the
+ * comparison on what the test is actually about — that every element, 
attribute, value and text node survives the
+ * round-trip — while ignoring an ordering the library never promised to 
preserve. A missing or altered attribute
+ * still fails, because sorting changes the order of the attributes and 
nothing else.
+ */
+export function withSortedAttributes(xml: string) {
+  return xml.replace(
+    
/<([A-Za-z_][\w.:-]*)((?:\s+[A-Za-z_][\w.:-]*\s*=\s*"[^"]*")+)(\s*\/)?\s*>/g,
+    (_match, tagName: string, rawAttributes: string, selfClosing: string | 
undefined) => {
+      const attributes = 
[...rawAttributes.matchAll(/([A-Za-z_][\w.:-]*)\s*=\s*"([^"]*)"/g)]
+        .map(([, name, value]) => `${name}="${value}"`)
+        .sort();
+      return `<${tagName} ${attributes.join(" ")}${selfClosing ? " /" : ""}>`;
+    }
+  );
+}
diff --git a/packages/dmn-editor-standalone/tests-e2e/api/getContent.spec.ts 
b/packages/dmn-editor-standalone/tests-e2e/api/getContent.spec.ts
index 6817c803c9f..eca67ee08ba 100644
--- a/packages/dmn-editor-standalone/tests-e2e/api/getContent.spec.ts
+++ b/packages/dmn-editor-standalone/tests-e2e/api/getContent.spec.ts
@@ -20,6 +20,7 @@
 import { test, expect } from "../__fixtures__/base";
 import { ExternalFile } from "../__fixtures__/files";
 import { NodeType } from "../__fixtures__/nodes";
+import { withSortedAttributes } from "../__fixtures__/prettier";
 
 test.describe("DMN Editor - Standalone - API", () => {
   test.describe("getContent", () => {
@@ -31,8 +32,12 @@ test.describe("DMN Editor - Standalone - API", () => {
     test("should get DMN contents of input DMN file", async ({ editor, files 
}) => {
       await editor.setContent("loanPreQualification.dmn", await 
files.getFile(ExternalFile.LOAN_PRE_QUALIFICATION_DMN));
       await expect(editor.get().getByText("Loan Pre-Qualification", { exact: 
true })).toBeAttached();
-      expect(await editor.getFormattedContent()).toEqual(
-        await files.getFormattedFile(ExternalFile.LOAN_PRE_QUALIFICATION_DMN)
+      // Attribute order is normalized on both sides. `DOMParser` 
implementations report an element's attributes in
+      // different orders, and the marshaller serializes them in whatever 
order it received, so the exact bytes depend
+      // on the browser. Chrome 153 started sorting namespace declarations, 
which is what made this assertion fail.
+      // Everything else is still compared exactly. See `withSortedAttributes`.
+      expect(withSortedAttributes(await editor.getFormattedContent())).toEqual(
+        withSortedAttributes(await 
files.getFormattedFile(ExternalFile.LOAN_PRE_QUALIFICATION_DMN))
       );
     });
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to