rusackas commented on code in PR #44042:
URL: https://github.com/apache/superset/pull/44042#discussion_r3964729578


##########
superset-frontend/plugins/plugin-chart-point-cluster-map/test/MapLibre.test.tsx:
##########
@@ -70,6 +70,23 @@ jest.mock('@apache-superset/core/theme', () => ({
 jest.mock('maplibre-gl/dist/maplibre-gl.css', () => ({}));
 jest.mock('../src/MapLibre.css', () => ({}));
 
+// maplibre-gl 6 is an ESM-only package with no "require"/"default" export
+// condition, so jest's (CJS-based) resolver can't locate the real module to
+// mock over it by name; { virtual: true } skips that resolution step.
+//
+// The mock jest.fn() is created inline (not hoisted out to a `const`)
+// because MapLibre.tsx calls maplibregl.setWorkerUrl() synchronously at
+// import time, and `import`/jest.mock() calls are themselves hoisted above
+// this file's plain `const` declarations — a `const` referenced here would
+// still be in its temporal dead zone when that import-time call fires.
+jest.mock(
+  'maplibre-gl',
+  () => ({ __esModule: true, setWorkerUrl: jest.fn() }),
+  { virtual: true },
+);

Review Comment:
   The mock's narrow on purpose, it's checking that `setWorkerUrl` gets called 
with the right path before any map can mount, which is the actual bug here 
(silently empty `WORKER_URL`). Whether `CopyPlugin` really emits the worker + 
shared files and serves them correctly is a build-output concern that a jest 
unit test can't meaningfully cover without mocking half of webpack. I checked 
that separately with a full build plus a headless-Chromium test constructing a 
real `Worker` from the copied files (see the testing instructions in the PR 
description), just didn't want to fold an e2e-shaped check into the unit suite.



-- 
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]


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

Reply via email to