From faf5df18c340d08aaa53645e68b53bd0be60d619 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 6 Dec 2026 05:39:07 +0800 Subject: [PATCH] test(js-app): share unavailable renderer mapping assertions (#17247) --- .../javascriptArtifactReconstruction.test.ts | 94 ++++++------------- 1 file changed, 28 insertions(+), 66 deletions(-) diff --git a/tests/boundary/filesystem/javascript-applications/javascriptArtifactReconstruction.test.ts b/tests/boundary/filesystem/javascript-applications/javascriptArtifactReconstruction.test.ts index 18aedbd2865..a6ec60077a0 100644 --- a/tests/boundary/filesystem/javascript-applications/javascriptArtifactReconstruction.test.ts +++ b/tests/boundary/filesystem/javascript-applications/javascriptArtifactReconstruction.test.ts @@ -94,6 +94,31 @@ it("does not let a known-absent optional import erase another application's page ).toHaveLength(1); }); +const expectUnavailableRendererMapping = ( + graph: JavaScriptApplicationGraph, +): void => { + const roles = graph.nodes.filter(({ kind }) => kind === "electron-renderer"); + expect(roles).toHaveLength(1); + const role = roles[0]; + if (role === undefined) throw new Error("Missing renderer"); + expect(role.observations).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + properties: expect.objectContaining({ + resolved_path: null, + resolution_status: "unavailable", + }), + }), + ]), + ); + expect( + graph.edges.filter( + ({ source_node_id, relation }) => + source_node_id === role.node_id && relation === "maps_to", + ), + ).toEqual([]); +}; + const moduleFactRoles = (graph: JavaScriptApplicationGraph): string[] => graph.nodes.flatMap(({ observations }) => observations.flatMap(({ properties }) => { @@ -418,28 +443,7 @@ it.each(["unselected", "unavailable"] as const)( partial, (await analyzeArtifactFiles(partial)).analysis, ); - const roles = graph.nodes.filter( - ({ kind }) => kind === "electron-renderer", - ); - expect(roles).toHaveLength(1); - const role = roles[0]; - if (role === undefined) throw new Error("Missing renderer"); - expect(role.observations).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - properties: expect.objectContaining({ - resolved_path: null, - resolution_status: "unavailable", - }), - }), - ]), - ); - expect( - graph.edges.filter( - ({ source_node_id, relation }) => - source_node_id === role.node_id && relation === "maps_to", - ), - ).toEqual([]); + expectUnavailableRendererMapping(graph); } finally { await reader.close(); } @@ -485,28 +489,7 @@ it("keeps imported loadFile ownership unknown across an application projection o : file, ), }); - const roles = graph.nodes.filter( - ({ kind }) => kind === "electron-renderer", - ); - expect(roles).toHaveLength(1); - const role = roles[0]; - if (role === undefined) throw new Error("Missing renderer"); - expect(role.observations).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - properties: expect.objectContaining({ - resolved_path: null, - resolution_status: "unavailable", - }), - }), - ]), - ); - expect( - graph.edges.filter( - ({ source_node_id, relation }) => - source_node_id === role.node_id && relation === "maps_to", - ), - ).toEqual([]); + expectUnavailableRendererMapping(graph); } finally { await reader.close(); } @@ -964,28 +947,7 @@ it("keeps a loadFile owner unknown when a sibling manifest is unavailable in the partial, (await analyzeArtifactFiles(partial)).analysis, ); - const roles = graph.nodes.filter( - ({ kind }) => kind === "electron-renderer", - ); - expect(roles).toHaveLength(1); - const role = roles[0]; - if (role === undefined) throw new Error("Missing renderer"); - expect(role.observations).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - properties: expect.objectContaining({ - resolved_path: null, - resolution_status: "unavailable", - }), - }), - ]), - ); - expect( - graph.edges.filter( - ({ source_node_id, relation }) => - source_node_id === role.node_id && relation === "maps_to", - ), - ).toEqual([]); + expectUnavailableRendererMapping(graph); } finally { await reader.close(); }