aglinxinyuan commented on code in PR #4997:
URL: https://github.com/apache/texera/pull/4997#discussion_r3213013104


##########
frontend/src/app/workspace/component/code-editor-dialog/code-debugger.component.ts:
##########
@@ -20,9 +20,6 @@
 import { AfterViewInit, Component, Input, ViewChild } from "@angular/core";
 import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
 import { SafeStyle } from "@angular/platform-browser";
-import "@codingame/monaco-vscode-python-default-extension";
-import "@codingame/monaco-vscode-r-default-extension";
-import "@codingame/monaco-vscode-java-default-extension";
 import { isDefined } from "../../../common/util/predicate";
 import * as monaco from "monaco-editor";
 import { MonacoBreakpoint } from "monaco-breakpoints";

Review Comment:
   Already done — see e8e67b56c7. Both `import 
"@codingame/monaco-vscode-{python,java}-default-extension"` lines were dropped 
from `code-debugger.component.ts`, and the centralized 
`ensureVscodeApiStarted()` in `code-editor.component.ts` (where the editor 
stack is actually instantiated) is the only place loading them now. The static 
side-effect imports on the debugger were leftover duplicates and are gone.



##########
frontend/src/jsdom-svg-polyfill.ts:
##########
@@ -18,22 +18,49 @@
  */
 
 /**
- * jsdom doesn't implement the SVG geometry APIs 
(`SVGSVGElement#createSVGMatrix`,
- * `createSVGPoint`, `createSVGTransform`, `getScreenCTM`, `getCTM`,
- * `getBBox`). jointjs reaches into these during graph layout and crashes
- * the spec build with `TypeError: svgDocument.createSVGMatrix is not a
- * function` etc.
- *
- * The stubs below return identity-ish geometry: matrices/points behave like
- * the identity, bounding boxes report zero dimensions. That's enough for
- * jointjs construction code to not throw; specs that actually depend on
- * accurate geometry should run under Vitest browser mode rather than
- * jsdom (tracked in #4861), but the bulk of the texera specs only need
- * jointjs to instantiate cleanly.
+ * Test-environment polyfills + setup hooks for jsdom + the Angular
+ * `@angular/build:unit-test` builder. Pulled in via `setupFiles` in
+ * `angular.json`. Each block below targets a specific gap that surfaces
+ * when the codingame monaco-vscode-* v25 stack or jointjs runs under
+ * jsdom; comments next to each block say which one.
  */
 
+// ───────────────────────────────────────────────────────────────────────────
+// Node ESM loader hook so every transitive `.css` import resolves to an empty
+// module. The unit-test builder pre-bundles spec files with `externalPackages:
+// true`, so imports like `monaco-languageclient` reach Node's native ESM
+// loader instead of Vite's transform pipeline — without the hook, every spec
+// that transitively loads the codingame v25 stack crashes with
+// `Unknown file extension ".css"`. The hook source lives inline as a `data:`
+// URL so we don't carry a sidecar `.mjs`. Must run before any spec body
+// imports the affected packages; `module.register` needs Node 20.6+ (the
+// project pins Node ≥ 24).
+import { register as registerLoader } from "node:module";
+
+const cssLoaderHookSource = `
+export function resolve(specifier, context, nextResolve) {
+  if (specifier.endsWith(".css") || /\\.css(\\?|$)/.test(specifier)) {
+    return {
+      url: "data:text/javascript,export%20default%20%7B%7D%3B",
+      shortCircuit: true,
+      format: "module",
+    };
+  }
+  return nextResolve(specifier, context);
+}
+`;
+registerLoader(`data:text/javascript;charset=utf-8,${encodeURIComponent(cssLoaderHookSource)}`);
+
 type AnyFn = (...args: unknown[]) => unknown;
 
+// ───────────────────────────────────────────────────────────────────────────
+// SVG geometry APIs (`SVGSVGElement#createSVGMatrix`, `createSVGPoint`,
+// `createSVGTransform`, `getScreenCTM`, `getCTM`, `getBBox`). jsdom doesn't
+// implement these and jointjs reaches into them during graph layout, so the
+// spec build crashes with `TypeError: svgDocument.createSVGMatrix is not a
+// function`. Stubs below return identity-ish geometry — enough for jointjs
+// construction code not to throw. Specs needing accurate geometry should
+// run under Vitest browser mode rather than jsdom (tracked in #4861).
 function fakeMatrix() {

Review Comment:
   Good catch — fixed in 33eea83c83.
   
   Vitest re-evaluates `setupFiles` once per spec file, so the unconditional 
`module.register(...)` was chaining a fresh `.css` ESM hook for every spec. 
Guarded the registration behind a 
`Symbol.for("texera.cssLoaderHookRegistered")` flag on `globalThis` so the hook 
is installed exactly once per process; subsequent setup invocations 
short-circuit before calling `register`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to