From 7d6d33fa09a6decd63dc81b2fbea93433f1d0c7f Mon Sep 17 00:00:00 2001 From: Joe Li Date: Thu, 7 May 2026 11:35:49 -0700 Subject: [PATCH] fix(subdirectory): use explicit __esModule mock shape for getBootstrapData MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit requireActual spread didn't fix the Layer 5 crash — consumers still hit "_getBootstrapData.default is not a function". Most plausibly the SWC transform produces a default-export shape that requireActual doesn't faithfully round-trip when spread into a fresh object literal. Mirror the established pattern from CrudThemeProvider.test.tsx and Register.test.tsx: explicit { __esModule: true, default, applicationRoot, staticAssetsPrefix }. Default returns a BootstrapData-shaped object that reads from mockApplicationRoot so any consumer that pulls common.application_root through the default path also sees the mocked value. staticAssetsPrefix mocked as a no-op since none of the touched code paths exercise it. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../SliceHeaderControls.subdirectory.test.tsx | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/superset-frontend/src/dashboard/components/SliceHeaderControls/SliceHeaderControls.subdirectory.test.tsx b/superset-frontend/src/dashboard/components/SliceHeaderControls/SliceHeaderControls.subdirectory.test.tsx index a6fd922be8b..24eac27d756 100644 --- a/superset-frontend/src/dashboard/components/SliceHeaderControls/SliceHeaderControls.subdirectory.test.tsx +++ b/superset-frontend/src/dashboard/components/SliceHeaderControls/SliceHeaderControls.subdirectory.test.tsx @@ -49,15 +49,23 @@ import SliceHeaderControls, { SliceHeaderControlsProps } from '.'; // "module factory is not allowed to reference any out-of-scope variables". const mockApplicationRoot = jest.fn(() => ''); -// `getBootstrapData` exposes both a default export (the bootstrap getter -// itself) and named exports like `applicationRoot`. Consumers in the -// component tree transitively import the default — replacing the module -// with just `{ applicationRoot }` left default undefined and crashed at -// require-time. Spread `requireActual` to preserve everything else and -// override only `applicationRoot`. +// Mirror the actual module shape: __esModule + default getBootstrapData +// + named applicationRoot/staticAssetsPrefix. Consumers in the +// SliceHeaderControls import chain transitively call the default export, +// so a mock that omits it crashes at require-time. (Spreading +// jest.requireActual was tried first — it executes the real module body, +// which reads applicationRoot from cached module state and produces the +// wrong default-export shape under SWC/Babel ESM interop.) jest.mock('src/utils/getBootstrapData', () => ({ - ...jest.requireActual('src/utils/getBootstrapData'), + __esModule: true, + default: () => ({ + common: { + application_root: mockApplicationRoot(), + static_assets_prefix: '', + }, + }), applicationRoot: () => mockApplicationRoot(), + staticAssetsPrefix: () => '', })); const SLICE_ID = 371;